mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 19:33:18 +00:00
Bug 824864 - Remove nsIScriptContext::EvaluateString. r=bz
This commit is contained in:
parent
1f2a4747c6
commit
d3d15aa3fe
@ -61,37 +61,6 @@ class nsIScriptContext : public nsIScriptContextPrincipal
|
||||
public:
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTCONTEXT_IID)
|
||||
|
||||
/**
|
||||
* Compile and execute a script.
|
||||
*
|
||||
* @param aScript a string representing the script to be executed
|
||||
* @param aScopeObject a script object for the scope to execute in, or
|
||||
* nullptr to use a default scope
|
||||
* @param aPrincipal the principal the script should be evaluated with
|
||||
* @param aOriginPrincipal the principal the script originates from. If null,
|
||||
* aPrincipal is used.
|
||||
* @param aURL the URL or filename for error messages
|
||||
* @param aLineNo the starting line number of the script for error messages
|
||||
* @param aVersion the script language version to use when executing
|
||||
* @param aRetValue the result of executing the script, or null for no result.
|
||||
* If this is a JS context, it's the caller's responsibility to
|
||||
* preserve aRetValue from GC across this call
|
||||
* @param aIsUndefined true if the result of executing the script is the
|
||||
* undefined value
|
||||
*
|
||||
* @return NS_OK if the script was valid and got executed
|
||||
*
|
||||
**/
|
||||
virtual nsresult EvaluateString(const nsAString& aScript,
|
||||
JSObject* aScopeObject,
|
||||
nsIPrincipal *aPrincipal,
|
||||
nsIPrincipal *aOriginPrincipal,
|
||||
const char *aURL,
|
||||
uint32_t aLineNo,
|
||||
JSVersion aVersion,
|
||||
nsAString *aRetValue,
|
||||
bool* aIsUndefined) = 0;
|
||||
|
||||
/**
|
||||
* Compile and execute a script.
|
||||
*
|
||||
|
@ -1373,141 +1373,6 @@ nsJSContext::GetObjectPrincipal()
|
||||
return prin;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSContext::EvaluateString(const nsAString& aScript,
|
||||
JSObject* aScopeObject,
|
||||
nsIPrincipal *aPrincipal,
|
||||
nsIPrincipal *aOriginPrincipal,
|
||||
const char *aURL,
|
||||
uint32_t aLineNo,
|
||||
JSVersion aVersion,
|
||||
nsAString *aRetValue,
|
||||
bool* aIsUndefined)
|
||||
{
|
||||
SAMPLE_LABEL("JS", "EvaluateString");
|
||||
NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
if (!mScriptsEnabled) {
|
||||
if (aIsUndefined) {
|
||||
*aIsUndefined = true;
|
||||
}
|
||||
|
||||
if (aRetValue) {
|
||||
aRetValue->Truncate();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoMicroTask mt;
|
||||
|
||||
if (!aScopeObject) {
|
||||
aScopeObject = JS_GetGlobalObject(mContext);
|
||||
}
|
||||
|
||||
xpc_UnmarkGrayObject(aScopeObject);
|
||||
|
||||
// Ignore the principal that was passed in, and just assert that it matches
|
||||
// the one we pull off the global.
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(GetGlobalObject());
|
||||
if (!objPrincipal)
|
||||
return NS_ERROR_FAILURE;
|
||||
principal = objPrincipal->GetPrincipal();
|
||||
if (!principal)
|
||||
return NS_ERROR_FAILURE;
|
||||
#ifdef DEBUG
|
||||
bool equal = false;
|
||||
principal->Equals(aPrincipal, &equal);
|
||||
MOZ_ASSERT(equal);
|
||||
nsIPrincipal *scopeObjectPrincipal =
|
||||
nsJSPrincipals::get(JS_GetCompartmentPrincipals(js::GetObjectCompartment(aScopeObject)));
|
||||
equal = false;
|
||||
principal->Equals(scopeObjectPrincipal, &equal);
|
||||
MOZ_ASSERT(equal);
|
||||
#endif
|
||||
|
||||
bool ok = false;
|
||||
|
||||
nsresult rv = sSecurityManager->CanExecuteScripts(mContext, principal, &ok);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Push our JSContext on the current thread's context stack so JS called
|
||||
// from native code via XPConnect uses the right context. Do this whether
|
||||
// or not the SecurityManager said "ok", in order to simplify control flow
|
||||
// below where we pop before returning.
|
||||
nsCOMPtr<nsIJSContextStack> stack =
|
||||
do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
|
||||
if (NS_FAILED(rv) || NS_FAILED(stack->Push(mContext))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// The result of evaluation, used only if there were no errors. This need
|
||||
// not be a GC root currently, provided we run the GC only from the
|
||||
// operation callback or from ScriptEvaluated.
|
||||
jsval val = JSVAL_VOID;
|
||||
jsval* vp = aRetValue ? &val : NULL;
|
||||
|
||||
nsJSContext::TerminationFuncHolder holder(this);
|
||||
|
||||
++mExecuteDepth;
|
||||
|
||||
// SecurityManager said "ok", but don't compile if aVersion is unknown.
|
||||
// Since the caller is responsible for parsing the version strings, we just
|
||||
// check it isn't JSVERSION_UNKNOWN.
|
||||
if (ok && JSVersion(aVersion) != JSVERSION_UNKNOWN) {
|
||||
XPCAutoRequest ar(mContext);
|
||||
JSAutoCompartment ac(mContext, aScopeObject);
|
||||
|
||||
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
|
||||
// to avoid dropping JS exceptions in case we got here through
|
||||
// nested calls through XPConnect.
|
||||
|
||||
ReportPendingException();
|
||||
}
|
||||
}
|
||||
|
||||
// If all went well, convert val to a string if one is wanted.
|
||||
if (ok) {
|
||||
XPCAutoRequest ar(mContext);
|
||||
JSAutoCompartment ac(mContext, aScopeObject);
|
||||
rv = JSValueToAString(mContext, val, aRetValue, aIsUndefined);
|
||||
}
|
||||
else {
|
||||
if (aIsUndefined) {
|
||||
*aIsUndefined = true;
|
||||
}
|
||||
|
||||
if (aRetValue) {
|
||||
aRetValue->Truncate();
|
||||
}
|
||||
}
|
||||
|
||||
--mExecuteDepth;
|
||||
|
||||
// Pop here, after JS_ValueToString and any other possible evaluation.
|
||||
if (NS_FAILED(stack->Pop(nullptr)))
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
// ScriptEvaluated needs to come after we pop the stack
|
||||
ScriptEvaluated(true);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSContext::CompileScript(const PRUnichar* aText,
|
||||
int32_t aTextLength,
|
||||
|
@ -44,15 +44,6 @@ public:
|
||||
|
||||
virtual nsIScriptObjectPrincipal* GetObjectPrincipal();
|
||||
|
||||
virtual nsresult EvaluateString(const nsAString& aScript,
|
||||
JSObject* aScopeObject,
|
||||
nsIPrincipal *principal,
|
||||
nsIPrincipal *originPrincipal,
|
||||
const char *aURL,
|
||||
uint32_t aLineNo,
|
||||
JSVersion aVersion,
|
||||
nsAString *aRetValue,
|
||||
bool* aIsUndefined);
|
||||
virtual nsresult EvaluateStringWithValue(const nsAString& aScript,
|
||||
JSObject& aScopeObject,
|
||||
JS::CompileOptions &aOptions,
|
||||
|
Loading…
Reference in New Issue
Block a user