Bug 978042 - Part 8: AutoPushJSContext in nsXBLProtoImplField::InstallField. r=bholley

This commit is contained in:
Bob Owen 2014-03-19 12:09:33 +00:00
parent 102046f234
commit 4522a79449
5 changed files with 22 additions and 74 deletions

View File

@ -27,8 +27,8 @@ class nsIDOMWindow;
class nsIURI;
#define NS_ISCRIPTCONTEXT_IID \
{ 0x513c2c1a, 0xf4f1, 0x44da, \
{ 0x8e, 0x38, 0xf4, 0x0c, 0x30, 0x9a, 0x5d, 0xef } }
{ 0x7cf47061, 0x745d, 0x4c6c, \
{ 0xa0, 0xe5, 0x9f, 0xef, 0xa8, 0xcc, 0x2a, 0xf0 } }
/* This MUST match JSVERSION_DEFAULT. This version stuff if we don't
know what language we have is a little silly... */
@ -45,29 +45,6 @@ class nsIScriptContext : public nsISupports
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.
* @param aOptions an options object. You probably want to at least set
* filename and line number. The principal is computed
* internally, though 'originPrincipals' may be passed.
* @param aCoerceToString if the return value is not JSVAL_VOID, convert it
* to a string before returning.
* @param aRetValue the result of executing the script. Pass null if you
* don't care about the result. Note that asking for a
* result will deoptimize your script somewhat in many cases.
* @param aOffThreadToken if specified, the result of compiling the script
* on another thread.
*/
virtual nsresult EvaluateString(const nsAString& aScript,
JS::Handle<JSObject*> aScopeObject,
JS::CompileOptions& aOptions,
bool aCoerceToString,
JS::Value* aRetValue,
void **aOffThreadToken = nullptr) = 0;
/**
* Bind an already-compiled event handler function to the given
* target. Scripting languages with static scoping must re-bind the

View File

@ -880,23 +880,6 @@ nsJSContext::GetCCRefcnt()
return refcnt;
}
nsresult
nsJSContext::EvaluateString(const nsAString& aScript,
JS::Handle<JSObject*> aScopeObject,
JS::CompileOptions& aCompileOptions,
bool aCoerceToString,
JS::Value* aRetValue,
void **aOffThreadToken)
{
NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_NOT_INITIALIZED);
AutoCxPusher pusher(mContext);
nsJSUtils::EvaluateOptions evalOptions;
evalOptions.setCoerceToString(aCoerceToString);
return nsJSUtils::EvaluateString(mContext, aScript, aScopeObject,
aCompileOptions, evalOptions, aRetValue,
aOffThreadToken);
}
#ifdef DEBUG
bool
AtomIsEventHandlerName(nsIAtom *aName)

View File

@ -44,13 +44,6 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsJSContext,
nsIScriptContext)
virtual nsresult EvaluateString(const nsAString& aScript,
JS::Handle<JSObject*> aScopeObject,
JS::CompileOptions &aOptions,
bool aCoerceToString,
JS::Value* aRetValue,
void **aOffThreadToken = nullptr) MOZ_OVERRIDE;
virtual nsresult BindCompiledEventHandler(nsISupports *aTarget,
JS::Handle<JSObject*> aScope,
JS::Handle<JSObject*> aHandler,

View File

@ -16,8 +16,9 @@
#include "nsIURI.h"
#include "nsXBLSerialize.h"
#include "nsXBLPrototypeBinding.h"
#include "nsCxPusher.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/ScriptSettings.h"
#include "nsGlobalWindow.h"
#include "xpcpublic.h"
#include "WrapperFactory.h"
@ -204,20 +205,7 @@ InstallXBLField(JSContext* cx,
nsXBLProtoImplField* field = protoBinding->FindField(fieldName);
MOZ_ASSERT(field);
// This mirrors code in nsXBLProtoImpl::InstallImplementation
nsCOMPtr<nsIScriptGlobalObject> global =
do_QueryInterface(xblNode->OwnerDoc()->GetWindow());
if (!global) {
return true;
}
nsCOMPtr<nsIScriptContext> context = global->GetContext();
if (!context) {
return true;
}
nsresult rv = field->InstallField(context, thisObj, protoBinding->DocURI(),
installed);
nsresult rv = field->InstallField(thisObj, protoBinding->DocURI(), installed);
if (NS_SUCCEEDED(rv)) {
return true;
}
@ -388,8 +376,7 @@ nsXBLProtoImplField::InstallAccessors(JSContext* aCx,
}
nsresult
nsXBLProtoImplField::InstallField(nsIScriptContext* aContext,
JS::Handle<JSObject*> aBoundNode,
nsXBLProtoImplField::InstallField(JS::Handle<JSObject*> aBoundNode,
nsIURI* aBindingDocURI,
bool* aDidInstall) const
{
@ -413,7 +400,16 @@ nsXBLProtoImplField::InstallField(nsIScriptContext* aContext,
nsAutoCString uriSpec;
aBindingDocURI->GetSpec(uriSpec);
AutoPushJSContext cx(aContext->GetNativeContext());
nsIGlobalObject* globalObject = xpc::WindowGlobalOrNull(aBoundNode);
if (!globalObject) {
return NS_OK;
}
// We are going to run script via EvaluateString, so we need a script entry
// point, but as this is XBL related it does not appear in the HTML spec.
AutoEntryScript entryScript(globalObject, true);
JSContext* cx = entryScript.cx();
NS_ASSERTION(!::JS_IsExceptionPending(cx),
"Shouldn't get here when an exception is pending!");
@ -431,11 +427,11 @@ nsXBLProtoImplField::InstallField(nsIScriptContext* aContext,
JS::CompileOptions options(cx);
options.setFileAndLine(uriSpec.get(), mLineNumber)
.setVersion(JSVERSION_LATEST);
rv = aContext->EvaluateString(nsDependentString(mFieldText,
mFieldTextLength),
wrappedNode, options,
/* aCoerceToString = */ false,
result.address());
nsJSUtils::EvaluateOptions evalOptions;
rv = nsJSUtils::EvaluateString(cx, nsDependentString(mFieldText,
mFieldTextLength),
wrappedNode, options, evalOptions,
result.address());
if (NS_FAILED(rv)) {
return rv;
}

View File

@ -32,8 +32,7 @@ public:
nsXBLProtoImplField* GetNext() const { return mNext; }
void SetNext(nsXBLProtoImplField* aNext) { mNext = aNext; }
nsresult InstallField(nsIScriptContext* aContext,
JS::Handle<JSObject*> aBoundNode,
nsresult InstallField(JS::Handle<JSObject*> aBoundNode,
nsIURI* aBindingDocURI,
bool* aDidInstall) const;