Changeset View
Changeset View
Standalone View
Standalone View
source/scriptinterface/ScriptInterface.cpp
Show First 20 Lines • Show All 502 Lines • ▼ Show 20 Lines | bool ScriptInterface::SetGlobal_(const char* name, JS::HandleValue value, bool replace, bool constant, bool enumerate) | ||||
ScriptRequest rq(this); | ScriptRequest rq(this); | ||||
JS::RootedObject global(rq.cx, rq.glob); | JS::RootedObject global(rq.cx, rq.glob); | ||||
bool found; | bool found; | ||||
if (!JS_HasProperty(rq.cx, global, name, &found)) | if (!JS_HasProperty(rq.cx, global, name, &found)) | ||||
return false; | return false; | ||||
if (found) | if (found) | ||||
{ | { | ||||
JS::Rooted<JS::PropertyDescriptor> desc(rq.cx); | JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> desc(rq.cx); | ||||
if (!JS_GetOwnPropertyDescriptor(rq.cx, global, name, &desc)) | if (!JS_GetOwnPropertyDescriptor(rq.cx, global, name, &desc) || !desc.isSome()) | ||||
return false; | return false; | ||||
if (!desc.writable()) | if (!desc->writable()) | ||||
{ | { | ||||
if (!replace) | if (!replace) | ||||
{ | { | ||||
ScriptException::Raise(rq, "SetGlobal \"%s\" called multiple times", name); | ScriptException::Raise(rq, "SetGlobal \"%s\" called multiple times", name); | ||||
return false; | return false; | ||||
} | } | ||||
// This is not supposed to happen, unless the user has called SetProperty with constant = true on the global object | // This is not supposed to happen, unless the user has called SetProperty with constant = true on the global object | ||||
// instead of using SetGlobal. | // instead of using SetGlobal. | ||||
if (!desc.configurable()) | if (!desc->configurable()) | ||||
{ | { | ||||
ScriptException::Raise(rq, "The global \"%s\" is permanent and cannot be hotloaded", name); | ScriptException::Raise(rq, "The global \"%s\" is permanent and cannot be hotloaded", name); | ||||
return false; | return false; | ||||
} | } | ||||
LOGMESSAGE("Hotloading new value for global \"%s\".", name); | LOGMESSAGE("Hotloading new value for global \"%s\".", name); | ||||
ENSURE(JS_DeleteProperty(rq.cx, global, name)); | ENSURE(JS_DeleteProperty(rq.cx, global, name)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator