js::ExecuteInGlobalAndReturnScope(JSContext* cx, HandleObject global, HandleScript scriptArg, MutableHandleObject scopeArg) { CHECK_REQUEST(cx); assertSameCompartment(cx, global); MOZ_ASSERT(global->is<GlobalObject>()); MOZ_RELEASE_ASSERT(scriptArg->hasNonSyntacticScope()); RootedScript script(cx, scriptArg); Rooted<GlobalObject*> globalRoot(cx, &global->as<GlobalObject>()); if (script->compartment() != cx->compartment()) { Rooted<StaticScope*> staticScope(cx, &globalRoot->lexicalScope().staticBlock()); staticScope = StaticNonSyntacticScope::create(cx, staticScope); if (!staticScope) return false; script = CloneGlobalScript(cx, staticScope, script); if (!script) return false; Debugger::onNewScript(cx, script); } Rooted<ClonedBlockObject*> globalLexical(cx, &globalRoot->lexicalScope()); Rooted<ScopeObject*> scope(cx, NonSyntacticVariablesObject::create(cx, globalLexical)); if (!scope) return false; // Unlike the non-syntactic scope chain API used by the subscript loader, // this API creates a fresh block scope each time. Rooted<StaticNonSyntacticScope*> enclosingStaticScope(cx, &script->enclosingStaticScope()->as<StaticNonSyntacticScope>()); scope = ClonedBlockObject::createNonSyntactic(cx, enclosingStaticScope, scope); if (!scope) return false; RootedValue rval(cx); if (!ExecuteKernel(cx, script, *scope, UndefinedValue(), NullFramePtr() /* evalInFrame */, rval.address())) { return false; } scopeArg.set(scope); return true; }
js::ExecuteInGlobalAndReturnScope(JSContext* cx, HandleObject global, HandleScript scriptArg, MutableHandleObject scopeArg) { CHECK_REQUEST(cx); assertSameCompartment(cx, global); MOZ_ASSERT(global->is<GlobalObject>()); MOZ_RELEASE_ASSERT(scriptArg->hasNonSyntacticScope()); RootedScript script(cx, scriptArg); if (script->compartment() != cx->compartment()) { Rooted<ScopeObject*> staticScope(cx, StaticNonSyntacticScopeObjects::create(cx, nullptr)); if (!staticScope) return false; script = CloneGlobalScript(cx, staticScope, script); if (!script) return false; Debugger::onNewScript(cx, script); } Rooted<GlobalObject*> globalRoot(cx, &global->as<GlobalObject>()); Rooted<ScopeObject*> scope(cx, NonSyntacticVariablesObject::create(cx, globalRoot)); if (!scope) return false; JSObject* thisobj = GetThisObject(cx, global); if (!thisobj) return false; RootedValue thisv(cx, ObjectValue(*thisobj)); RootedValue rval(cx); if (!ExecuteKernel(cx, script, *scope, thisv, UndefinedValue(), EXECUTE_GLOBAL, NullFramePtr() /* evalInFrame */, rval.address())) { return false; } scopeArg.set(scope); return true; }