mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 698378 - Give nsIScriptContext::EvaluateStringWithValue a JSObject* scope parameter; r=peterv
This commit is contained in:
parent
1dacc7fc0b
commit
d8a3105318
@ -74,8 +74,8 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptContextPrincipal,
|
|||||||
NS_ISCRIPTCONTEXTPRINCIPAL_IID)
|
NS_ISCRIPTCONTEXTPRINCIPAL_IID)
|
||||||
|
|
||||||
#define NS_ISCRIPTCONTEXT_IID \
|
#define NS_ISCRIPTCONTEXT_IID \
|
||||||
{ 0x0ffcb42a, 0xd2cf, 0x4e16, \
|
{ 0xace7960f, 0x263b, 0x4a9a, \
|
||||||
{ 0xac, 0x24, 0x5e, 0x7d, 0xd0, 0x71, 0x72, 0x12 } }
|
{ 0xaa, 0x1f, 0x87, 0x86, 0x5c, 0x67, 0x03, 0x7f } }
|
||||||
|
|
||||||
/* This MUST match JSVERSION_DEFAULT. This version stuff if we don't
|
/* This MUST match JSVERSION_DEFAULT. This version stuff if we don't
|
||||||
know what language we have is a little silly... */
|
know what language we have is a little silly... */
|
||||||
@ -121,10 +121,9 @@ public:
|
|||||||
nsAString *aRetValue,
|
nsAString *aRetValue,
|
||||||
bool* aIsUndefined) = 0;
|
bool* aIsUndefined) = 0;
|
||||||
|
|
||||||
// Note JS bigotry remains here - 'void *aRetValue' is assumed to be a
|
// 'void *aRetValue' is assumed to be a jsval.
|
||||||
// jsval. This must move to JSObject before it can be made agnostic.
|
|
||||||
virtual nsresult EvaluateStringWithValue(const nsAString& aScript,
|
virtual nsresult EvaluateStringWithValue(const nsAString& aScript,
|
||||||
void *aScopeObject,
|
JSObject* aScopeObject,
|
||||||
nsIPrincipal *aPrincipal,
|
nsIPrincipal *aPrincipal,
|
||||||
const char *aURL,
|
const char *aURL,
|
||||||
PRUint32 aLineNo,
|
PRUint32 aLineNo,
|
||||||
|
@ -1196,7 +1196,7 @@ nsJSContext::GetCCRefcnt()
|
|||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
|
nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
|
||||||
void *aScopeObject,
|
JSObject* aScopeObject,
|
||||||
nsIPrincipal *aPrincipal,
|
nsIPrincipal *aPrincipal,
|
||||||
const char *aURL,
|
const char *aURL,
|
||||||
PRUint32 aLineNo,
|
PRUint32 aLineNo,
|
||||||
@ -1207,6 +1207,9 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
|
|||||||
NS_TIME_FUNCTION_MIN_FMT(1.0, "%s (line %d) (url: %s, line: %d)", MOZ_FUNCTION_NAME,
|
NS_TIME_FUNCTION_MIN_FMT(1.0, "%s (line %d) (url: %s, line: %d)", MOZ_FUNCTION_NAME,
|
||||||
__LINE__, aURL, aLineNo);
|
__LINE__, aURL, aLineNo);
|
||||||
|
|
||||||
|
NS_ABORT_IF_FALSE(aScopeObject,
|
||||||
|
"Shouldn't call EvaluateStringWithValue with null scope object.");
|
||||||
|
|
||||||
NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_NOT_INITIALIZED);
|
NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_NOT_INITIALIZED);
|
||||||
|
|
||||||
if (!mScriptsEnabled) {
|
if (!mScriptsEnabled) {
|
||||||
@ -1217,15 +1220,12 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult rv;
|
|
||||||
if (!aScopeObject)
|
|
||||||
aScopeObject = ::JS_GetGlobalObject(mContext);
|
|
||||||
|
|
||||||
// Safety first: get an object representing the script's principals, i.e.,
|
// Safety first: get an object representing the script's principals, i.e.,
|
||||||
// the entities who signed this script, or the fully-qualified-domain-name
|
// the entities who signed this script, or the fully-qualified-domain-name
|
||||||
// or "codebase" from which it was loaded.
|
// or "codebase" from which it was loaded.
|
||||||
JSPrincipals *jsprin;
|
JSPrincipals *jsprin;
|
||||||
nsIPrincipal *principal = aPrincipal;
|
nsIPrincipal *principal = aPrincipal;
|
||||||
|
nsresult rv;
|
||||||
if (!aPrincipal) {
|
if (!aPrincipal) {
|
||||||
nsIScriptGlobalObject *global = GetGlobalObject();
|
nsIScriptGlobalObject *global = GetGlobalObject();
|
||||||
if (!global)
|
if (!global)
|
||||||
@ -1277,7 +1277,7 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
|
|||||||
JSAutoRequest ar(mContext);
|
JSAutoRequest ar(mContext);
|
||||||
|
|
||||||
JSAutoEnterCompartment ac;
|
JSAutoEnterCompartment ac;
|
||||||
if (!ac.enter(mContext, (JSObject *)aScopeObject)) {
|
if (!ac.enter(mContext, aScopeObject)) {
|
||||||
JSPRINCIPALS_DROP(mContext, jsprin);
|
JSPRINCIPALS_DROP(mContext, jsprin);
|
||||||
stack->Pop(nsnull);
|
stack->Pop(nsnull);
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
@ -1286,9 +1286,9 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
|
|||||||
++mExecuteDepth;
|
++mExecuteDepth;
|
||||||
|
|
||||||
ok = ::JS_EvaluateUCScriptForPrincipalsVersion(mContext,
|
ok = ::JS_EvaluateUCScriptForPrincipalsVersion(mContext,
|
||||||
(JSObject *)aScopeObject,
|
aScopeObject,
|
||||||
jsprin,
|
jsprin,
|
||||||
(jschar*)PromiseFlatString(aScript).get(),
|
static_cast<const jschar*>(PromiseFlatString(aScript).get()),
|
||||||
aScript.Length(),
|
aScript.Length(),
|
||||||
aURL,
|
aURL,
|
||||||
aLineNo,
|
aLineNo,
|
||||||
|
@ -81,13 +81,13 @@ public:
|
|||||||
nsAString *aRetValue,
|
nsAString *aRetValue,
|
||||||
bool* aIsUndefined);
|
bool* aIsUndefined);
|
||||||
virtual nsresult EvaluateStringWithValue(const nsAString& aScript,
|
virtual nsresult EvaluateStringWithValue(const nsAString& aScript,
|
||||||
void *aScopeObject,
|
JSObject* aScopeObject,
|
||||||
nsIPrincipal *aPrincipal,
|
nsIPrincipal* aPrincipal,
|
||||||
const char *aURL,
|
const char* aURL,
|
||||||
PRUint32 aLineNo,
|
PRUint32 aLineNo,
|
||||||
PRUint32 aVersion,
|
PRUint32 aVersion,
|
||||||
void* aRetValue,
|
void* aRetValue,
|
||||||
bool* aIsUndefined);
|
bool* aIsUndefined);
|
||||||
|
|
||||||
virtual nsresult CompileScript(const PRUnichar* aText,
|
virtual nsresult CompileScript(const PRUnichar* aText,
|
||||||
PRInt32 aTextLength,
|
PRInt32 aTextLength,
|
||||||
|
@ -1646,6 +1646,8 @@ _evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
obj = JS_ObjectToInnerObject(cx, obj);
|
obj = JS_ObjectToInnerObject(cx, obj);
|
||||||
|
NS_ABORT_IF_FALSE(obj,
|
||||||
|
"JS_ObjectToInnerObject should never return null with non-null input.");
|
||||||
|
|
||||||
// Root obj and the rval (below).
|
// Root obj and the rval (below).
|
||||||
jsval vec[] = { OBJECT_TO_JSVAL(obj), JSVAL_NULL };
|
jsval vec[] = { OBJECT_TO_JSVAL(obj), JSVAL_NULL };
|
||||||
|
Loading…
Reference in New Issue
Block a user