Bug 1088228 part 4. Add a version of JS_CloneFunctionObject that allows passing in a scope chain. r=shu
☠☠ backed out by a37fedd51b7d ☠ ☠
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 30 Oct 2014 17:40:15 -0400
changeset 213249 2d449a2b4e1cc684f316f2ad116e352497f6798e
parent 213248 49ac8f33ab70633088ef1121f9646d5dac9294a6
child 213250 de692c3335f2c67402d155a6b512cab4b7b88e70
push id27745
push usercbook@mozilla.com
push dateFri, 31 Oct 2014 13:09:12 +0000
treeherdermozilla-central@6bd2071b373f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1088228
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 1088228 part 4. Add a version of JS_CloneFunctionObject that allows passing in a scope chain. r=shu
js/src/jsapi.cpp
js/src/jsapi.h
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -3914,16 +3914,31 @@ JS_CloneFunctionObject(JSContext *cx, Ha
     if (fun->isNative() && IsAsmJSModuleNative(fun->native())) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_CANT_CLONE_OBJECT);
         return nullptr;
     }
 
     return CloneFunctionObject(cx, fun, parent, fun->getAllocKind());
 }
 
+namespace JS {
+
+JS_PUBLIC_API(JSObject *)
+CloneFunctionObject(JSContext *cx, HandleObject funobj, AutoObjectVector &scopeChain)
+{
+    RootedObject dynamicScope(cx);
+    RootedObject unusedStaticScope(cx);
+    if (!CreateScopeObjectsForScopeChain(cx, scopeChain, &dynamicScope, &unusedStaticScope))
+        return nullptr;
+
+    return JS_CloneFunctionObject(cx, funobj, dynamicScope);
+}
+
+} // namespace JS
+
 JS_PUBLIC_API(JSObject *)
 JS_GetFunctionObject(JSFunction *fun)
 {
     return fun;
 }
 
 JS_PUBLIC_API(JSString *)
 JS_GetFunctionId(JSFunction *fun)
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -3529,16 +3529,28 @@ JS_DefineFunctionById(JSContext *cx, JS:
 
 /*
  * Clone a top-level function into a new scope. This function will dynamically
  * fail if funobj was lexically nested inside some other function.
  */
 extern JS_PUBLIC_API(JSObject *)
 JS_CloneFunctionObject(JSContext *cx, JS::Handle<JSObject*> funobj, JS::Handle<JSObject*> parent);
 
+namespace JS {
+
+/*
+ * As above, but providing an explicit scope chain.  scopeChain must not include
+ * the global object on it; that's implicit.  It needs to contain the other
+ * objects that should end up on the clone's scope chain.
+ */
+extern JS_PUBLIC_API(JSObject *)
+CloneFunctionObject(JSContext *cx, HandleObject funobj, AutoObjectVector &scopeChain);
+
+} // namespace JS
+
 /*
  * Given a buffer, return false if the buffer might become a valid
  * javascript statement with the addition of more lines.  Otherwise return
  * true.  The intent is to support interactive compilation - accumulate
  * lines in a buffer until JS_BufferIsCompilableUnit is true, then pass it to
  * the compiler.
  */
 extern JS_PUBLIC_API(bool)