author | Andrew McCreight <continuation@gmail.com> |
Mon, 15 May 2017 14:39:52 -0700 | |
changeset 359833 | 36bb469c723c7400668f6aae028d93178704578f |
parent 359832 | b2b8fadcfa753e9a1571c935a415d076306c0204 |
child 359834 | d9f3972b7d978da13ce781ae42a9140f97a50c9c |
push id | 31859 |
push user | ihsiao@mozilla.com |
push date | Mon, 22 May 2017 03:28:26 +0000 |
treeherder | mozilla-central@367944041b55 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | shu |
bugs | 989373 |
milestone | 55.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
js/src/jsapi-tests/moz.build | file | annotate | diff | comparison | revisions | |
js/src/jsapi-tests/testEnclosingFunction.cpp | file | annotate | diff | comparison | revisions | |
js/src/jsfriendapi.cpp | file | annotate | diff | comparison | revisions | |
js/src/jsfriendapi.h | file | annotate | diff | comparison | revisions | |
js/src/vm/EnvironmentObject.cpp | file | annotate | diff | comparison | revisions |
--- a/js/src/jsapi-tests/moz.build +++ b/js/src/jsapi-tests/moz.build @@ -22,17 +22,16 @@ UNIFIED_SOURCES += [ 'testDateToLocaleString.cpp', 'testDebugger.cpp', 'testDeepFreeze.cpp', 'testDefineGetterSetterNonEnumerable.cpp', 'testDefineProperty.cpp', 'testDefinePropertyIgnoredAttributes.cpp', 'testDeflateStringToUTF8Buffer.cpp', 'testDifferentNewTargetInvokeConstructor.cpp', - 'testEnclosingFunction.cpp', 'testErrorCopying.cpp', 'testException.cpp', 'testExternalArrayBuffer.cpp', 'testExternalStrings.cpp', 'testFindSCCs.cpp', 'testForceLexicalInitialization.cpp', 'testForOfIterator.cpp', 'testForwardSetProperty.cpp',
deleted file mode 100644 --- a/js/src/jsapi-tests/testEnclosingFunction.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * vim: set ts=8 sts=4 et sw=4 tw=99: - * - * Test script cloning. - */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "jsfriendapi.h" - -#include "jsapi-tests/tests.h" - -using namespace js; - -static JSFunction* foundFun = nullptr; - -static bool -CheckEnclosing(JSContext* cx, unsigned argc, Value* vp) -{ - CallArgs args = CallArgsFromVp(argc, vp); - - foundFun = js::GetOutermostEnclosingFunctionOfScriptedCaller(cx); - - args.rval().set(UndefinedValue()); - return true; -} - -BEGIN_TEST(test_enclosingFunction) -{ - CHECK(JS_DefineFunction(cx, global, "checkEnclosing", CheckEnclosing, 0, 0)); - - EXEC("checkEnclosing()"); - CHECK(foundFun == nullptr); - - RootedFunction fun(cx); - - JS::CompileOptions options(cx); - options.setFileAndLine(__FILE__, __LINE__); - - const char s1chars[] = "checkEnclosing()"; - JS::AutoObjectVector emptyScopeChain(cx); - CHECK(JS::CompileFunction(cx, emptyScopeChain, options, "s1", 0, nullptr, s1chars, - strlen(s1chars), &fun)); - CHECK(fun); - CHECK(JS_DefineProperty(cx, global, "s1", fun, JSPROP_ENUMERATE)); - EXEC("s1()"); - CHECK(foundFun == fun); - - const char s2chars[] = "return function() { checkEnclosing() }"; - CHECK(JS::CompileFunction(cx, emptyScopeChain, options, "s2", 0, nullptr, s2chars, - strlen(s2chars), &fun)); - CHECK(fun); - CHECK(JS_DefineProperty(cx, global, "s2", fun, JSPROP_ENUMERATE)); - EXEC("s2()()"); - CHECK(foundFun == fun); - - const char s3chars[] = "return function() { { let x; function g() { checkEnclosing() } return g() } }"; - CHECK(JS::CompileFunction(cx, emptyScopeChain, options, "s3", 0, nullptr, s3chars, - strlen(s3chars), &fun)); - CHECK(fun); - CHECK(JS_DefineProperty(cx, global, "s3", fun, JSPROP_ENUMERATE)); - EXEC("s3()()"); - CHECK(foundFun == fun); - - return true; -} -END_TEST(test_enclosingFunction)
--- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -414,44 +414,16 @@ js::IsObjectInContextCompartment(JSObjec JS_FRIEND_API(bool) js::RunningWithTrustedPrincipals(JSContext* cx) { return cx->runningWithTrustedPrincipals(); } JS_FRIEND_API(JSFunction*) -js::GetOutermostEnclosingFunctionOfScriptedCaller(JSContext* cx) -{ - ScriptFrameIter iter(cx); - - // Skip eval frames. - while (!iter.done() && iter.isEvalFrame()) - ++iter; - - if (iter.done()) - return nullptr; - - if (!iter.isFunctionFrame()) - return nullptr; - - if (iter.compartment() != cx->compartment()) - return nullptr; - - RootedFunction curr(cx, iter.callee(cx)); - for (ScopeIter si(curr->nonLazyScript()); si; si++) { - if (si.kind() == ScopeKind::Function) - curr = si.scope()->as<FunctionScope>().canonicalFunction(); - } - - assertSameCompartment(cx, curr); - return curr; -} - -JS_FRIEND_API(JSFunction*) js::DefineFunctionWithReserved(JSContext* cx, JSObject* objArg, const char* name, JSNative call, unsigned nargs, unsigned attrs) { RootedObject obj(cx, objArg); MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment())); CHECK_REQUEST(cx); assertSameCompartment(cx, obj); JSAtom* atom = Atomize(cx, name, strlen(name));
--- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -662,28 +662,16 @@ JS_FRIEND_API(void) AssertSameCompartment(JSObject* objA, JSObject* objB); #else inline void AssertSameCompartment(JSObject* objA, JSObject* objB) {} #endif JS_FRIEND_API(void) NotifyAnimationActivity(JSObject* obj); -/** - * Return the outermost enclosing function (script) of the scripted caller. - * This function returns nullptr in several cases: - * - no script is running on the context - * - the caller is in global or eval code - * In particular, this function will "stop" its outermost search at eval() and - * thus it will really return the outermost enclosing function *since the - * innermost eval*. - */ -JS_FRIEND_API(JSFunction*) -GetOutermostEnclosingFunctionOfScriptedCaller(JSContext* cx); - JS_FRIEND_API(JSFunction*) DefineFunctionWithReserved(JSContext* cx, JSObject* obj, const char* name, JSNative call, unsigned nargs, unsigned attrs); JS_FRIEND_API(JSFunction*) NewFunctionWithReserved(JSContext* cx, JSNative call, unsigned nargs, unsigned flags, const char* name); @@ -2836,24 +2824,16 @@ typedef long * Gecko must call SetJitExceptionFilter before any JIT code is compiled and * only once per process. */ extern JS_FRIEND_API(void) SetJitExceptionHandler(JitExceptionHandler handler); #endif /** - * Get the nearest enclosing with environment object for a given function. If - * the function is not scripted or is not enclosed by a with scope, returns - * the global. - */ -extern JS_FRIEND_API(JSObject*) -GetNearestEnclosingWithEnvironmentObjectForFunction(JSFunction* fun); - -/** * Get the first SavedFrame object in this SavedFrame stack whose principals are * subsumed by the cx's principals. If there is no such frame, return nullptr. * * Do NOT pass a non-SavedFrame object here. * * The savedFrame and cx do not need to be in the same compartment. */ extern JS_FRIEND_API(JSObject*)
--- a/js/src/vm/EnvironmentObject.cpp +++ b/js/src/vm/EnvironmentObject.cpp @@ -3090,33 +3090,16 @@ js::GetDebugEnvironmentForFrame(JSContex JSObject* js::GetDebugEnvironmentForGlobalLexicalEnvironment(JSContext* cx) { EnvironmentIter ei(cx, &cx->global()->lexicalEnvironment(), &cx->global()->emptyGlobalScope()); return GetDebugEnvironment(cx, ei); } -// See declaration and documentation in jsfriendapi.h -JS_FRIEND_API(JSObject*) -js::GetNearestEnclosingWithEnvironmentObjectForFunction(JSFunction* fun) -{ - if (!fun->isInterpreted()) - return &fun->global(); - - JSObject* env = fun->environment(); - while (env && !env->is<WithEnvironmentObject>()) - env = env->enclosingEnvironment(); - - if (!env) - return &fun->global(); - - return &env->as<WithEnvironmentObject>().object(); -} - bool js::CreateObjectsForEnvironmentChain(JSContext* cx, AutoObjectVector& chain, HandleObject terminatingEnv, MutableHandleObject envObj) { #ifdef DEBUG for (size_t i = 0; i < chain.length(); ++i) { assertSameCompartment(cx, chain[i]); MOZ_ASSERT(!chain[i]->is<GlobalObject>());