Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/scriptinterface/ScriptInterface.cpp
Show First 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | if (CProfileManager::IsInitialised() && ThreadUtil::IsMainThread()) | ||||
g_Profiler.StartScript(name); | g_Profiler.StartScript(name); | ||||
g_Profiler2.RecordRegionEnter(name); | g_Profiler2.RecordRegionEnter(name); | ||||
args.rval().setUndefined(); | args.rval().setUndefined(); | ||||
return true; | return true; | ||||
} | } | ||||
bool ProfileStop(JSContext* UNUSED(cx), uint UNUSED(argc), JS::Value* vp) | bool ProfileStop(JSContext* UNUSED(cx), uint argc, JS::Value* vp) | ||||
{ | { | ||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
if (CProfileManager::IsInitialised() && ThreadUtil::IsMainThread()) | if (CProfileManager::IsInitialised() && ThreadUtil::IsMainThread()) | ||||
g_Profiler.Stop(); | g_Profiler.Stop(); | ||||
g_Profiler2.RecordRegionLeave(); | g_Profiler2.RecordRegionLeave(); | ||||
rec.rval().setUndefined(); | args.rval().setUndefined(); | ||||
return true; | return true; | ||||
} | } | ||||
bool ProfileAttribute(JSContext* cx, uint argc, JS::Value* vp) | bool ProfileAttribute(JSContext* cx, uint argc, JS::Value* vp) | ||||
{ | { | ||||
const char* name = "(ProfileAttribute)"; | const char* name = "(ProfileAttribute)"; | ||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
Show All 31 Lines | while (true) | ||||
double d = (double)(rng.max() - rng.min()) + 1.0; | double d = (double)(rng.max() - rng.min()) + 1.0; | ||||
ENSURE(d > 0 && n >= 0 && n <= d); | ENSURE(d > 0 && n >= 0 && n <= d); | ||||
double r = n / d * (max - min) + min; | double r = n / d * (max - min) + min; | ||||
if (r < max) | if (r < max) | ||||
return r; | return r; | ||||
} | } | ||||
} | } | ||||
bool Math_random(JSContext* cx, uint UNUSED(argc), JS::Value* vp) | bool Math_random(JSContext* cx, uint argc, JS::Value* vp) | ||||
{ | { | ||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||||
double r; | double r; | ||||
if (!ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->MathRandom(r)) | if (!ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->MathRandom(r)) | ||||
return false; | return false; | ||||
rec.rval().setNumber(r); | args.rval().setNumber(r); | ||||
return true; | return true; | ||||
} | } | ||||
} // anonymous namespace | } // anonymous namespace | ||||
bool ScriptInterface::MathRandom(double& nbr) | bool ScriptInterface::MathRandom(double& nbr) | ||||
{ | { | ||||
if (m->m_rng == NULL) | if (m->m_rng == NULL) | ||||
▲ Show 20 Lines • Show All 772 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
bool ScriptInterface::IsExceptionPending(JSContext* cx) | bool ScriptInterface::IsExceptionPending(JSContext* cx) | ||||
{ | { | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
return JS_IsExceptionPending(cx) ? true : false; | return JS_IsExceptionPending(cx) ? true : false; | ||||
} | } | ||||
const JSClass* ScriptInterface::GetClass(JS::HandleObject obj) | |||||
{ | |||||
return JS_GetClass(obj); | |||||
} | |||||
void* ScriptInterface::GetPrivate(JS::HandleObject obj) | |||||
{ | |||||
// TODO: use JS_GetInstancePrivate | |||||
return JS_GetPrivate(obj); | |||||
} | |||||
JS::Value ScriptInterface::CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const | JS::Value ScriptInterface::CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const | ||||
{ | { | ||||
PROFILE("CloneValueFromOtherContext"); | PROFILE("CloneValueFromOtherContext"); | ||||
JSAutoRequest rq(m->m_cx); | JSAutoRequest rq(m->m_cx); | ||||
JS::RootedValue out(m->m_cx); | JS::RootedValue out(m->m_cx); | ||||
shared_ptr<StructuredClone> structuredClone = otherContext.WriteStructuredClone(val); | shared_ptr<StructuredClone> structuredClone = otherContext.WriteStructuredClone(val); | ||||
ReadStructuredClone(structuredClone, &out); | ReadStructuredClone(structuredClone, &out); | ||||
return out.get(); | return out.get(); | ||||
Show All 35 Lines |
Wildfire Games · Phabricator