From 3af5215454ddbdc83e110906967dbe88703f2fda Mon Sep 17 00:00:00 2001 From: Ted Campbell Date: Fri, 20 Dec 2019 03:12:12 +0000 Subject: [PATCH] Bug 1605207 - Remove unnecessary roots in XDRScript. r=caroline We had a few extra RootedFunction when we only cared if about if the pointer was null or not, so lets remove them. Also rename to isFunctionScript since this is called for stand-alone functions as well. Semantics should be unchanged. Depends on D57862 Differential Revision: https://phabricator.services.mozilla.com/D57917 --HG-- extra : moz-landing-system : lando --- js/src/vm/JSScript.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/js/src/vm/JSScript.cpp b/js/src/vm/JSScript.cpp index eb8bc16ad45f..23c7f531e585 100644 --- a/js/src/vm/JSScript.cpp +++ b/js/src/vm/JSScript.cpp @@ -1083,7 +1083,8 @@ XDRResult js::XDRScript(XDRState* xdr, HandleScope scriptEnclosingScope, JSContext* cx = xdr->cx(); RootedScript script(cx); - bool isInnerFunction = funOrMod && funOrMod->is(); + + bool isFunctionScript = funOrMod && funOrMod->is(); // Instrumented scripts cannot be encoded, as they have extra instructions // which are not normally present. Globals with instrumentation enabled must @@ -1097,13 +1098,9 @@ XDRResult js::XDRScript(XDRState* xdr, HandleScope scriptEnclosingScope, if (mode == XDR_ENCODE) { script = scriptp.get(); - RootedFunction fun(cx); - if (isInnerFunction) { - MOZ_ASSERT(script->function() == funOrMod); - fun.set(&funOrMod->as()); - } + MOZ_ASSERT_IF(isFunctionScript, script->function() == funOrMod); - if (!fun && script->treatAsRunOnce() && script->hasRunOnce()) { + if (!isFunctionScript && script->treatAsRunOnce() && script->hasRunOnce()) { // This is a toplevel or eval script that's runOnce. We want to // make sure that we're not XDR-saving an object we emitted for // JSOP_OBJECT that then got modified. So throw if we're not @@ -1215,8 +1212,8 @@ XDRResult js::XDRScript(XDRState* xdr, HandleScope scriptEnclosingScope, if (mode == XDR_DECODE) { RootedObject functionOrGlobal( - cx, isInnerFunction ? static_cast(funOrMod) - : static_cast(cx->global())); + cx, isFunctionScript ? static_cast(funOrMod) + : static_cast(cx->global())); script = JSScript::Create(cx, functionOrGlobal, *options, sourceObject, sourceStart, sourceEnd, toStringStart, @@ -1236,7 +1233,7 @@ XDRResult js::XDRScript(XDRState* xdr, HandleScope scriptEnclosingScope, // Set the script in its function now so that inner scripts to be // decoded may iterate the static scope chain. - if (isInnerFunction) { + if (isFunctionScript) { funOrMod->as().initScript(script); } } @@ -1256,11 +1253,6 @@ XDRResult js::XDRScript(XDRState* xdr, HandleScope scriptEnclosingScope, scriptEnclosingScope, funOrMod)); MOZ_TRY(RuntimeScriptData::XDR(xdr, script)); - RootedFunction fun(cx); - if (isInnerFunction) { - fun.set(&funOrMod->as()); - } - if (mode == XDR_DECODE) { if (!script->shareScriptData(cx)) { return xdr->fail(JS::TranscodeResult_Throw); @@ -1273,6 +1265,7 @@ XDRResult js::XDRScript(XDRState* xdr, HandleScope scriptEnclosingScope, lazy = script->maybeLazyScript(); } + RootedFunction fun(cx, &funOrMod->as()); MOZ_TRY( XDRRelazificationInfo(xdr, fun, script, scriptEnclosingScope, &lazy)); @@ -1289,7 +1282,7 @@ XDRResult js::XDRScript(XDRState* xdr, HandleScope scriptEnclosingScope, } /* see BytecodeEmitter::tellDebuggerAboutCompiledScript */ - if (!fun && !cx->isHelperThreadContext()) { + if (!isFunctionScript && !cx->isHelperThreadContext()) { DebugAPI::onNewScript(cx, script); } }