зеркало из https://github.com/mozilla/gecko-dev.git
Bug 781035 - Use the C++ JS compile API in more places. r=jorendorff sr=jst
This commit is contained in:
Родитель
4212e7d293
Коммит
74a1052eb5
|
@ -827,17 +827,13 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
|
|||
mGlobal->GetJSObject(&global);
|
||||
if (global) {
|
||||
JSAutoCompartment ac(mCx, global);
|
||||
uint32_t oldopts = JS_GetOptions(mCx);
|
||||
JS_SetOptions(mCx, oldopts | JSOPTION_NO_SCRIPT_RVAL);
|
||||
|
||||
JSScript* script =
|
||||
JS_CompileUCScriptForPrincipals(mCx, nullptr,
|
||||
nsJSPrincipals::get(mPrincipal),
|
||||
static_cast<const jschar*>(dataString.get()),
|
||||
dataString.Length(),
|
||||
url.get(), 1);
|
||||
|
||||
JS_SetOptions(mCx, oldopts);
|
||||
JS::CompileOptions options(mCx);
|
||||
options.setNoScriptRval(true)
|
||||
.setFileAndLine(url.get(), 1)
|
||||
.setPrincipals(nsJSPrincipals::get(mPrincipal));
|
||||
JS::RootedObject empty(mCx, NULL);
|
||||
JSScript* script = JS::Compile(mCx, empty, options,
|
||||
dataString.get(), dataString.Length());
|
||||
|
||||
if (script) {
|
||||
nsCAutoString scheme;
|
||||
|
|
|
@ -1293,15 +1293,13 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
|
|||
|
||||
++mExecuteDepth;
|
||||
|
||||
ok = ::JS_EvaluateUCScriptForPrincipalsVersion(mContext,
|
||||
aScopeObject,
|
||||
nsJSPrincipals::get(principal),
|
||||
static_cast<const jschar*>(PromiseFlatString(aScript).get()),
|
||||
aScript.Length(),
|
||||
aURL,
|
||||
aLineNo,
|
||||
&val,
|
||||
JSVersion(aVersion));
|
||||
JS::CompileOptions options(mContext);
|
||||
options.setFileAndLine(aURL, aLineNo)
|
||||
.setVersion(JSVersion(aVersion))
|
||||
.setPrincipals(nsJSPrincipals::get(principal));
|
||||
JS::RootedObject rootedScope(mContext, aScopeObject);
|
||||
ok = JS::Evaluate(mContext, rootedScope, options, PromiseFlatString(aScript).get(),
|
||||
aScript.Length(), &val);
|
||||
|
||||
--mExecuteDepth;
|
||||
|
||||
|
@ -1490,11 +1488,15 @@ nsJSContext::EvaluateString(const nsAString& aScript,
|
|||
XPCAutoRequest ar(mContext);
|
||||
JSAutoCompartment ac(mContext, aScopeObject);
|
||||
|
||||
ok = JS_EvaluateUCScriptForPrincipalsVersionOrigin(
|
||||
mContext, aScopeObject,
|
||||
nsJSPrincipals::get(principal), nsJSPrincipals::get(aOriginPrincipal),
|
||||
static_cast<const jschar*>(PromiseFlatString(aScript).get()),
|
||||
aScript.Length(), aURL, aLineNo, vp, JSVersion(aVersion));
|
||||
JS::RootedObject rootedScope(mContext, aScopeObject);
|
||||
JS::CompileOptions options(mContext);
|
||||
options.setFileAndLine(aURL, aLineNo)
|
||||
.setPrincipals(nsJSPrincipals::get(principal))
|
||||
.setOriginPrincipals(nsJSPrincipals::get(aOriginPrincipal))
|
||||
.setVersion(JSVersion(aVersion));
|
||||
ok = JS::Evaluate(mContext, rootedScope, options,
|
||||
PromiseFlatString(aScript).get(),
|
||||
aScript.Length(), vp);
|
||||
|
||||
if (!ok) {
|
||||
// Tell XPConnect about any pending exceptions. This is needed
|
||||
|
@ -1751,17 +1753,16 @@ nsJSContext::CompileEventHandler(nsIAtom *aName,
|
|||
#endif
|
||||
|
||||
// Event handlers are always shared, and must be bound before use.
|
||||
// Therefore we never bother compiling with principals.
|
||||
// (that probably means we should avoid JS_CompileUCFunctionForPrincipals!)
|
||||
// Therefore we don't bother compiling with principals.
|
||||
XPCAutoRequest ar(mContext);
|
||||
|
||||
JSFunction* fun =
|
||||
::JS_CompileUCFunctionForPrincipalsVersion(mContext,
|
||||
nullptr, nullptr,
|
||||
nsAtomCString(aName).get(), aArgCount, aArgNames,
|
||||
(jschar*)PromiseFlatString(aBody).get(),
|
||||
aBody.Length(),
|
||||
aURL, aLineNo, JSVersion(aVersion));
|
||||
JS::CompileOptions options(mContext);
|
||||
options.setVersion(JSVersion(aVersion))
|
||||
.setFileAndLine(aURL, aLineNo);
|
||||
JS::RootedObject empty(mContext, NULL);
|
||||
JSFunction* fun = JS::CompileFunction(mContext, empty, options, nsAtomCString(aName).get(),
|
||||
aArgCount, aArgNames,
|
||||
PromiseFlatString(aBody).get(), aBody.Length());
|
||||
|
||||
if (!fun) {
|
||||
ReportPendingException();
|
||||
|
@ -1814,20 +1815,18 @@ nsJSContext::CompileFunction(JSObject* aTarget,
|
|||
}
|
||||
}
|
||||
|
||||
JSObject *target = aTarget;
|
||||
JS::RootedObject target(mContext, aShared ? NULL : aTarget);
|
||||
|
||||
XPCAutoRequest ar(mContext);
|
||||
|
||||
JSFunction* fun =
|
||||
::JS_CompileUCFunctionForPrincipalsVersion(mContext,
|
||||
aShared ? nullptr : target,
|
||||
nsJSPrincipals::get(principal),
|
||||
PromiseFlatCString(aName).get(),
|
||||
aArgCount, aArgArray,
|
||||
static_cast<const jschar*>(PromiseFlatString(aBody).get()),
|
||||
aBody.Length(),
|
||||
aURL, aLineNo,
|
||||
JSVersion(aVersion));
|
||||
JS::CompileOptions options(mContext);
|
||||
options.setPrincipals(nsJSPrincipals::get(principal))
|
||||
.setVersion(JSVersion(aVersion))
|
||||
.setFileAndLine(aURL, aLineNo);
|
||||
JSFunction* fun = JS::CompileFunction(mContext, target,
|
||||
options, PromiseFlatCString(aName).get(),
|
||||
aArgCount, aArgArray,
|
||||
PromiseFlatString(aBody).get(), aBody.Length());
|
||||
|
||||
if (!fun)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
|
@ -576,7 +576,7 @@ ScriptExecutorRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
|
|||
}
|
||||
}
|
||||
|
||||
JSObject* global = JS_GetGlobalObject(aCx);
|
||||
JS::RootedObject global(aCx, JS_GetGlobalObject(aCx));
|
||||
NS_ASSERTION(global, "Must have a global by now!");
|
||||
|
||||
JSPrincipals* principal = GetWorkerPrincipal();
|
||||
|
@ -615,10 +615,11 @@ ScriptExecutorRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
|
|||
|
||||
NS_ConvertUTF16toUTF8 filename(loadInfo.mURL);
|
||||
|
||||
if (!JS_EvaluateUCScriptForPrincipals(aCx, global, principal,
|
||||
loadInfo.mScriptText.get(),
|
||||
loadInfo.mScriptText.Length(),
|
||||
filename.get(), 1, nullptr)) {
|
||||
JS::CompileOptions options(aCx);
|
||||
options.setPrincipals(principal)
|
||||
.setFileAndLine(filename.get(), 1);
|
||||
if (!JS::Evaluate(aCx, global, options, loadInfo.mScriptText.get(),
|
||||
loadInfo.mScriptText.Length(), nullptr)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -3760,7 +3760,7 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
|
|||
bool retval = true;
|
||||
|
||||
AutoPtrComparator<TimeoutInfo> comparator = GetAutoPtrComparator(mTimeouts);
|
||||
JSObject* global = JS_GetGlobalObject(aCx);
|
||||
JS::RootedObject global(aCx, JS_GetGlobalObject(aCx));
|
||||
JSPrincipals* principal = GetWorkerPrincipal();
|
||||
|
||||
// We want to make sure to run *something*, even if the timer fired a little
|
||||
|
@ -3794,18 +3794,17 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
|
|||
if (info->mTimeoutVal.isString()) {
|
||||
JSString* expression = info->mTimeoutVal.toString();
|
||||
|
||||
JS::CompileOptions options(aCx);
|
||||
options.setPrincipals(principal)
|
||||
.setFileAndLine(info->mFilename.get(), info->mLineNumber);
|
||||
|
||||
size_t stringLength;
|
||||
const jschar* string = JS_GetStringCharsAndLength(aCx, expression,
|
||||
&stringLength);
|
||||
|
||||
if ((!string ||
|
||||
!JS_EvaluateUCScriptForPrincipals(aCx, global, principal, string,
|
||||
stringLength,
|
||||
info->mFilename.get(),
|
||||
info->mLineNumber, nullptr)) &&
|
||||
if ((!string || !JS::Evaluate(aCx, global, options, string, stringLength, nullptr)) &&
|
||||
!JS_ReportPendingException(aCx)) {
|
||||
retval = false;
|
||||
break;
|
||||
retval = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -195,9 +195,11 @@ nsresult EvaluateAdminConfigScript(const char *js_buffer, size_t length,
|
|||
JS_BeginRequest(autoconfig_cx);
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(principal));
|
||||
ok = JS_EvaluateScriptForPrincipals(autoconfig_cx, autoconfig_glob,
|
||||
nsJSPrincipals::get(principal),
|
||||
js_buffer, length, filename, 0, nullptr);
|
||||
JS::CompileOptions options(autoconfig_cx);
|
||||
options.setPrincipals(nsJSPrincipals::get(principal))
|
||||
.setFileAndLine(filename, 1);
|
||||
JS::RootedObject glob(autoconfig_cx, autoconfig_glob);
|
||||
ok = JS::Evaluate(autoconfig_cx, glob, options, js_buffer, length, nullptr);
|
||||
JS_EndRequest(autoconfig_cx);
|
||||
|
||||
JS_MaybeGC(autoconfig_cx);
|
||||
|
|
|
@ -3915,13 +3915,12 @@ xpc_EvalInSandbox(JSContext *cx, JSObject *sandbox, const nsAString& source,
|
|||
|
||||
jsval v;
|
||||
JSString *str = nullptr;
|
||||
JSBool ok =
|
||||
JS_EvaluateUCScriptForPrincipals(sandcx->GetJSContext(), sandbox,
|
||||
nsJSPrincipals::get(prin),
|
||||
reinterpret_cast<const jschar *>
|
||||
(PromiseFlatString(source).get()),
|
||||
source.Length(), filename, lineNo,
|
||||
&v);
|
||||
JS::CompileOptions options(sandcx->GetJSContext());
|
||||
options.setPrincipals(nsJSPrincipals::get(prin))
|
||||
.setFileAndLine(filename, lineNo);
|
||||
JS::RootedObject rootedSandbox(sandcx->GetJSContext(), sandbox);
|
||||
bool ok = JS::Evaluate(sandcx->GetJSContext(), rootedSandbox, options,
|
||||
PromiseFlatString(source).get(), source.Length(), &v);
|
||||
if (ok && returnStringOnly && !(JSVAL_IS_VOID(v))) {
|
||||
ok = !!(str = JS_ValueToString(sandcx->GetJSContext(), v));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче