Bug 1089026 part 3. Add a friend API for getting the scope object for a function, if it has one. r=shu
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 30 Oct 2014 19:40:28 -0400
changeset 213336 cb53a4bac4c8c778823cec7c0769e6e894e6c0c5
parent 213335 dd4ec08078387e78ee34a33432a03bdc3675f882
child 213337 5ccd3c29891cdf7b7cd817ca96c20157b78a8b1f
push id27748
push userryanvm@gmail.com
push dateFri, 31 Oct 2014 20:14:33 +0000
treeherdermozilla-central@12ac66e2c016 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1089026
milestone36.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
Bug 1089026 part 3. Add a friend API for getting the scope object for a function, if it has one. r=shu
js/src/jsfriendapi.h
js/src/vm/ScopeObject.cpp
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -2670,16 +2670,25 @@ typedef long
 // the fault, but this is not generally allowed.
 //
 // 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 object underlying the object environment (in the ES
+ * NewObjectEnvironment) sense for a given function.  If the function is not
+ * scripted or does not have an object environment, just returns the function's
+ * parent.
+ */
+extern JS_FRIEND_API(JSObject *)
+GetObjectEnvironmentObjectForFunction(JSFunction *fun);
+
 } /* namespace js */
 
 extern JS_FRIEND_API(bool)
 js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg,
                      JS::Handle<JSPropertyDescriptor> descriptor, bool *bp);
 
 extern JS_FRIEND_API(bool)
 js_ReportIsNotFunction(JSContext *cx, JS::HandleValue v);
--- a/js/src/vm/ScopeObject.cpp
+++ b/js/src/vm/ScopeObject.cpp
@@ -2512,16 +2512,30 @@ js::GetDebugScopeForFrame(JSContext *cx,
 {
     assertSameCompartment(cx, frame);
     if (CanUseDebugScopeMaps(cx) && !DebugScopes::updateLiveScopes(cx))
         return nullptr;
     ScopeIter si(frame, pc, cx);
     return GetDebugScope(cx, si);
 }
 
+// See declaration and documentation in jsfriendapi.h
+JS_FRIEND_API(JSObject *)
+js::GetObjectEnvironmentObjectForFunction(JSFunction *fun)
+{
+    if (!fun->isInterpreted())
+        return fun->getParent();
+
+    JSObject *env = fun->environment();
+    if (!env || !env->is<DynamicWithObject>())
+        return fun->getParent();
+
+    return &env->as<DynamicWithObject>().object();
+}
+
 #ifdef DEBUG
 
 typedef HashSet<PropertyName *> PropertyNameSet;
 
 static bool
 RemoveReferencedNames(JSContext *cx, HandleScript script, PropertyNameSet &remainingNames)
 {
     // Remove from remainingNames --- the closure variables in some outer