From 712b7ebf9ad23ba1b2cb0929d6bc690120d1a065 Mon Sep 17 00:00:00 2001 From: wraitii Date: Wed, 12 Jan 2022 16:51:32 +0000 Subject: [PATCH] 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. --- source/scriptinterface/ScriptInterface.cpp | 9 ++++++--- .../serialization/StdDeserializer.cpp | 17 ++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/source/scriptinterface/ScriptInterface.cpp b/source/scriptinterface/ScriptInterface.cpp index 1fa8d9c6f3..67a319ba1f 100644 --- a/source/scriptinterface/ScriptInterface.cpp +++ b/source/scriptinterface/ScriptInterface.cpp @@ -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) diff --git a/source/simulation2/serialization/StdDeserializer.cpp b/source/simulation2/serialization/StdDeserializer.cpp index abf9a4f573..5efb2a83a1 100644 --- a/source/simulation2/serialization/StdDeserializer.cpp +++ b/source/simulation2/serialization/StdDeserializer.cpp @@ -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);