mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 13:04:10 +00:00
Improvements to simulation hotloading before the SM upgrade, refs #4893.
SM45 will enforce property attributes described at https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/Property_attributes. We thus cannot hotload properties with the DontDelete attribute. Fix an oversight in the hotloading code. Rename a confusing parameter. Reviewed By: wraitii Differential Revision: https://code.wildfiregames.com/D1844 This was SVN commit r22516.
This commit is contained in:
@@ -589,21 +589,40 @@ bool ScriptInterface::SetGlobal_(const char* name, JS::HandleValue value, bool r
|
||||
{
|
||||
JSAutoRequest rq(m->m_cx);
|
||||
JS::RootedObject global(m->m_cx, m->m_glob);
|
||||
if (!replace)
|
||||
|
||||
bool found;
|
||||
if (!JS_HasProperty(m->m_cx, global, name, &found))
|
||||
return false;
|
||||
if (found)
|
||||
{
|
||||
bool found;
|
||||
if (!JS_HasProperty(m->m_cx, global, name, &found))
|
||||
JS::Rooted<JSPropertyDescriptor> desc(m->m_cx);
|
||||
if (!JS_GetOwnPropertyDescriptor(m->m_cx, global, name, &desc))
|
||||
return false;
|
||||
if (found)
|
||||
|
||||
if (desc.isReadonly())
|
||||
{
|
||||
JS_ReportError(m->m_cx, "SetGlobal \"%s\" called multiple times", name);
|
||||
return false;
|
||||
if (!replace)
|
||||
{
|
||||
JS_ReportError(m->m_cx, "SetGlobal \"%s\" called multiple times", name);
|
||||
return false;
|
||||
}
|
||||
|
||||
// This is not supposed to happen, unless the user has called SetProperty with constant = true on the global object
|
||||
// instead of using SetGlobal.
|
||||
if (desc.isPermanent())
|
||||
{
|
||||
JS_ReportError(m->m_cx, "The global \"%s\" is permanent and cannot be hotloaded", name);
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGMESSAGE("Hotloading new value for global \"%s\".", name);
|
||||
ENSURE(JS_DeleteProperty(m->m_cx, global, name));
|
||||
}
|
||||
}
|
||||
|
||||
uint attrs = 0;
|
||||
if (constant)
|
||||
attrs |= JSPROP_READONLY | JSPROP_PERMANENT;
|
||||
attrs |= JSPROP_READONLY;
|
||||
if (enumerate)
|
||||
attrs |= JSPROP_ENUMERATE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user