From be465ba470c5577dea139731872f027f26ec9a6c Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 12 Dec 2012 17:09:37 -0800 Subject: [PATCH] Bug 820666 - Tag XBL script for elements and child scripts. r=jorendorff --- content/xbl/src/nsXBLProtoImplField.cpp | 1 + dom/base/nsIScriptContext.h | 1 + dom/base/nsJSEnvironment.cpp | 20 +++++++------------- dom/base/nsJSEnvironment.h | 1 + dom/plugins/base/nsNPAPIPlugin.cpp | 2 +- js/src/frontend/BytecodeEmitter.cpp | 3 ++- js/src/jsapi.cpp | 1 + js/src/jsapi.h | 2 ++ js/src/jsscript.cpp | 5 +++-- 9 files changed, 19 insertions(+), 17 deletions(-) diff --git a/content/xbl/src/nsXBLProtoImplField.cpp b/content/xbl/src/nsXBLProtoImplField.cpp index ca483c2b9ae8..41d6ce98ec66 100644 --- a/content/xbl/src/nsXBLProtoImplField.cpp +++ b/content/xbl/src/nsXBLProtoImplField.cpp @@ -113,6 +113,7 @@ nsXBLProtoImplField::InstallField(nsIScriptContext* aContext, aBoundNode, aPrincipal, uriSpec.get(), mLineNumber, JSVERSION_LATEST, + /* aIsXBL = */ true, &result, &undefined); if (NS_FAILED(rv)) { return rv; diff --git a/dom/base/nsIScriptContext.h b/dom/base/nsIScriptContext.h index af49b7168086..c077b109e4d8 100644 --- a/dom/base/nsIScriptContext.h +++ b/dom/base/nsIScriptContext.h @@ -98,6 +98,7 @@ public: const char *aURL, uint32_t aLineNo, uint32_t aVersion, + bool aIsXBL, JS::Value* aRetValue, bool* aIsUndefined) = 0; diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 0470c65916e8..5fe7f0fe5c45 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -1250,6 +1250,7 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript, const char *aURL, uint32_t aLineNo, uint32_t aVersion, + bool aIsXBL, JS::Value* aRetValue, bool* aIsUndefined) { @@ -1324,7 +1325,8 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript, JS::CompileOptions options(mContext); options.setFileAndLine(aURL, aLineNo) .setVersion(JSVersion(aVersion)) - .setPrincipals(nsJSPrincipals::get(principal)); + .setPrincipals(nsJSPrincipals::get(principal)) + .setUserBit(aIsXBL); js::RootedObject rootedScope(mContext, aScopeObject); ok = JS::Evaluate(mContext, rootedScope, options, PromiseFlatString(aScript).get(), aScript.Length(), &val); @@ -1782,7 +1784,8 @@ nsJSContext::CompileEventHandler(nsIAtom *aName, JS::CompileOptions options(mContext); options.setVersion(JSVersion(aVersion)) - .setFileAndLine(aURL, aLineNo); + .setFileAndLine(aURL, aLineNo) + .setUserBit(aIsXBL); js::RootedObject empty(mContext, NULL); JSFunction* fun = JS::CompileFunction(mContext, empty, options, nsAtomCString(aName).get(), aArgCount, aArgNames, @@ -1793,11 +1796,6 @@ nsJSContext::CompileEventHandler(nsIAtom *aName, return NS_ERROR_ILLEGAL_VALUE; } - // If this is an XBL function, make a note to that effect on its script. - if (aIsXBL) { - JS_SetScriptUserBit(JS_GetFunctionScript(mContext, fun), true); - } - JSObject *handler = ::JS_GetFunctionObject(fun); return aHandler.set(handler); } @@ -1849,7 +1847,8 @@ nsJSContext::CompileFunction(JSObject* aTarget, JS::CompileOptions options(mContext); options.setPrincipals(nsJSPrincipals::get(principal)) .setVersion(JSVersion(aVersion)) - .setFileAndLine(aURL, aLineNo); + .setFileAndLine(aURL, aLineNo) + .setUserBit(aIsXBL); JSFunction* fun = JS::CompileFunction(mContext, target, options, PromiseFlatCString(aName).get(), aArgCount, aArgArray, @@ -1858,11 +1857,6 @@ nsJSContext::CompileFunction(JSObject* aTarget, if (!fun) return NS_ERROR_FAILURE; - // If this is an XBL function, make a note to that effect on its script. - if (aIsXBL) { - JS_SetScriptUserBit(JS_GetFunctionScript(mContext, fun), true); - } - *aFunctionObject = JS_GetFunctionObject(fun); return NS_OK; } diff --git a/dom/base/nsJSEnvironment.h b/dom/base/nsJSEnvironment.h index 3207c3f758e2..6efec53ac106 100644 --- a/dom/base/nsJSEnvironment.h +++ b/dom/base/nsJSEnvironment.h @@ -59,6 +59,7 @@ public: const char* aURL, uint32_t aLineNo, uint32_t aVersion, + bool aIsXBL, JS::Value* aRetValue, bool* aIsUndefined); diff --git a/dom/plugins/base/nsNPAPIPlugin.cpp b/dom/plugins/base/nsNPAPIPlugin.cpp index ed5f26b7813a..75a1b980feca 100644 --- a/dom/plugins/base/nsNPAPIPlugin.cpp +++ b/dom/plugins/base/nsNPAPIPlugin.cpp @@ -1593,7 +1593,7 @@ _evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result) npp, npobj, script->UTF8Characters)); nsresult rv = scx->EvaluateStringWithValue(utf16script, obj, principal, - spec, 0, 0, rval, nullptr); + spec, 0, 0, false, rval, nullptr); return NS_SUCCEEDED(rv) && (!result || JSValToNPVariant(npp, cx, *rval, result)); diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 0a9b8089cf8a..988eb9896e1f 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -4862,7 +4862,8 @@ EmitFunc(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) .setOriginPrincipals(parent->originPrincipals) .setCompileAndGo(parent->compileAndGo) .setNoScriptRval(false) - .setVersion(parent->getVersion()); + .setVersion(parent->getVersion()) + .setUserBit(parent->userBit); Rooted script(cx, JSScript::Create(cx, enclosingScope, false, options, parent->staticLevel + 1, bce->script->scriptSource(), diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 4e6b895b64ad..d26a2f9fd3a5 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -5225,6 +5225,7 @@ JS::CompileOptions::CompileOptions(JSContext *cx) compileAndGo(cx->hasRunOption(JSOPTION_COMPILE_N_GO)), noScriptRval(cx->hasRunOption(JSOPTION_NO_SCRIPT_RVAL)), selfHostingMode(false), + userBit(false), sourcePolicy(SAVE_SOURCE) { } diff --git a/js/src/jsapi.h b/js/src/jsapi.h index cbc1279c9f25..552acfda05cb 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -4915,6 +4915,7 @@ struct JS_PUBLIC_API(CompileOptions) { bool compileAndGo; bool noScriptRval; bool selfHostingMode; + bool userBit; enum SourcePolicy { NO_SOURCE, LAZY_SOURCE, @@ -4932,6 +4933,7 @@ struct JS_PUBLIC_API(CompileOptions) { CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; } CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; } CompileOptions &setSelfHostingMode(bool shm) { selfHostingMode = shm; return *this; } + CompileOptions &setUserBit(bool bit) { userBit = bit; return *this; } CompileOptions &setSourcePolicy(SourcePolicy sp) { sourcePolicy = sp; return *this; } }; diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index ea8c0a178be0..5a7947b8c368 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -1615,6 +1615,7 @@ JSScript::Create(JSContext *cx, HandleObject enclosingScope, bool savedCallerFun script->setScriptSource(ss); script->sourceStart = bufStart; script->sourceEnd = bufEnd; + script->userBit = options.userBit; return script; } @@ -2255,7 +2256,8 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun, .setOriginPrincipals(src->originPrincipals) .setCompileAndGo(src->compileAndGo) .setNoScriptRval(src->noScriptRval) - .setVersion(src->getVersion()); + .setVersion(src->getVersion()) + .setUserBit(src->userBit); RootedScript dst(cx, JSScript::Create(cx, enclosingScope, src->savedCallerFun, options, src->staticLevel, src->scriptSource(), src->sourceStart, src->sourceEnd)); @@ -2301,7 +2303,6 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun, dst->hasSingletons = src->hasSingletons; dst->isGenerator = src->isGenerator; dst->isGeneratorExp = src->isGeneratorExp; - dst->userBit = src->userBit; /* * initScriptCounts updates scriptCountsMap if necessary. The other script