Bug 1359653: Part 2 - Allow CloneAndExecuteScript with non-lexical scripts. r=shu
MozReview-Commit-ID: Hq3rvgjwH3f
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -4580,16 +4580,33 @@ JS::CloneAndExecuteScript(JSContext* cx,
if (!script)
return false;
js::Debugger::onNewScript(cx, script);
}
return ExecuteScript(cx, globalLexical, script, rval.address());
}
+JS_PUBLIC_API(bool)
+JS::CloneAndExecuteScript(JSContext* cx, JS::AutoObjectVector& envChain,
+ HandleScript scriptArg,
+ JS::MutableHandleValue rval)
+{
+ CHECK_REQUEST(cx);
+ RootedScript script(cx, scriptArg);
+ if (script->compartment() != cx->compartment()) {
+ script = CloneGlobalScript(cx, ScopeKind::NonSyntactic, script);
+ if (!script)
+ return false;
+
+ js::Debugger::onNewScript(cx, script);
+ }
+ return ExecuteScript(cx, envChain, script, rval.address());
+}
+
static const unsigned LARGE_SCRIPT_LENGTH = 500*1024;
static bool
Evaluate(JSContext* cx, ScopeKind scopeKind, HandleObject env,
const ReadOnlyCompileOptions& optionsArg,
SourceBufferHolder& srcBuf, MutableHandleValue rval)
{
CompileOptions options(cx, optionsArg);
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -4370,16 +4370,25 @@ namespace JS {
/**
* Like the above, but handles a cross-compartment script. If the script is
* cross-compartment, it is cloned into the current compartment before executing.
*/
extern JS_PUBLIC_API(bool)
CloneAndExecuteScript(JSContext* cx, JS::Handle<JSScript*> script,
JS::MutableHandleValue rval);
+/**
+ * Like CloneAndExecuteScript above, but allows executing under a non-syntactic
+ * environment chain.
+ */
+extern JS_PUBLIC_API(bool)
+CloneAndExecuteScript(JSContext* cx, JS::AutoObjectVector& envChain,
+ JS::Handle<JSScript*> script,
+ JS::MutableHandleValue rval);
+
} /* namespace JS */
namespace JS {
/**
* Evaluate the given source buffer in the scope of the current global of cx.
*/
extern JS_PUBLIC_API(bool)