1
0
forked from 0ad/0ad

Remove JS_New in favour of JS::Construct in preparation for SM91

Spidermonkey 91, the next ESR, removes JS_New in favour or
JS::Construct.
See
https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples/blob/migration-guide/docs/Migration%20Guide.md#object-construction
and
https://bugzilla.mozilla.org/show_bug.cgi?id=1491055

This change is SM78 compatible and therefore done beforehand.

Tested by: Freagarach
Refs #5986

Differential Revision: https://code.wildfiregames.com/D4427
This was SVN commit r26205.
This commit is contained in:
wraitii 2022-01-12 16:51:32 +00:00
parent 6d14932d98
commit 712b7ebf9a
2 changed files with 16 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2022 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -448,8 +448,11 @@ void ScriptInterface::CallConstructor(JS::HandleValue ctor, JS::HandleValueArray
return;
}
JS::RootedObject ctorObj(rq.cx, &ctor.toObject());
out.setObjectOrNull(JS_New(rq.cx, ctorObj, argv));
JS::RootedObject objOut(rq.cx);
if (!JS::Construct(rq.cx, ctor, argv, &objOut))
out.setNull();
else
out.setObjectOrNull(objOut);
}
void ScriptInterface::DefineCustomObjectType(JSClass *clasp, JSNative constructor, uint minArgs, JSPropertySpec *ps, JSFunctionSpec *fs, JSPropertySpec *static_ps, JSFunctionSpec *static_fs)

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2022 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -278,9 +278,10 @@ JS::Value CStdDeserializer::ReadScriptVal(const char* UNUSED(name), JS::HandleOb
JS::RootedObject ctorobj(rq.cx);
if (!JS_GetClassObject(rq.cx, JSProto_Number, &ctorobj))
throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed");
JS::RootedValue protoval(rq.cx, JS::ObjectOrNullValue(ctorobj));
JS::RootedObject obj(rq.cx, JS_New(rq.cx, ctorobj, JS::HandleValueArray(val)));
if (!obj)
JS::RootedObject obj(rq.cx);
if (!JS::Construct(rq.cx, protoval, JS::HandleValueArray(val), &obj))
throw PSERROR_Deserialize_ScriptError("JS_New failed");
AddScriptBackref(obj);
return JS::ObjectValue(*obj);
@ -296,9 +297,10 @@ JS::Value CStdDeserializer::ReadScriptVal(const char* UNUSED(name), JS::HandleOb
JS::RootedObject ctorobj(rq.cx);
if (!JS_GetClassObject(rq.cx, JSProto_String, &ctorobj))
throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed");
JS::RootedValue protoval(rq.cx, JS::ObjectOrNullValue(ctorobj));
JS::RootedObject obj(rq.cx, JS_New(rq.cx, ctorobj, JS::HandleValueArray(val)));
if (!obj)
JS::RootedObject obj(rq.cx);
if (!JS::Construct(rq.cx, protoval, JS::HandleValueArray(val), &obj))
throw PSERROR_Deserialize_ScriptError("JS_New failed");
AddScriptBackref(obj);
return JS::ObjectValue(*obj);
@ -312,9 +314,10 @@ JS::Value CStdDeserializer::ReadScriptVal(const char* UNUSED(name), JS::HandleOb
JS::RootedObject ctorobj(rq.cx);
if (!JS_GetClassObject(rq.cx, JSProto_Boolean, &ctorobj))
throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed");
JS::RootedValue protoval(rq.cx, JS::ObjectOrNullValue(ctorobj));
JS::RootedObject obj(rq.cx, JS_New(rq.cx, ctorobj, JS::HandleValueArray(val)));
if (!obj)
JS::RootedObject obj(rq.cx);
if (!JS::Construct(rq.cx, protoval, JS::HandleValueArray(val), &obj))
throw PSERROR_Deserialize_ScriptError("JS_New failed");
AddScriptBackref(obj);
return JS::ObjectValue(*obj);