using JS_EvaluateUCScriptForPrincipals() in XULRunner 24
Grant Gayed <[email protected]> Wed, 28 Aug 2013 13:53:44 -0400
| Newsgroups | gmane.comp.mozilla.devel.embedding |
|---|---|
| Message-ID | <[email protected]> |
Hi all, The SWT Browser's embedding of XULRunner uses JS_EvaluateUCScriptForPrincipals() to evaluate arbitrary JS code in the context of a loaded page. This invocation is preceded by a nsIJSContextStack.Push() call to push the JSContext. As of XULRunner 23 the nsIJSContextStack interface is gone, so I tried to just remove our Push() invocation (testing against XULRunner 24b2), and the JS_EvaluateUCScriptForPrincipals() call now crashes in ScriptSourceObject::create()'s invocation of cx->global(), because the JSContext's compartment() resolves to 0. My question is, does the JSContext's compartment() == 0 indicate that not pushing the JSContext is likely the underlying problem? And if so, what is the new way of doing this? I notice within mozilla code the use of AutoPushJSContext, but this is not exported for use by embedders. Or, if compartment() == 0 does not necessarily point at the JSContext not being pushed, does anything in the following sequence seem particularly wrong? securityManager = serviceManager.getByContractID(ScriptSecurityManager) principal = securityManager.getSystemPrincipal() sgo = webBrowser.QI(nsIInterfaceRequestor).getInterface(nsIScriptGlobalObject) sgo.EnsureScriptEnvironment() scriptContext = sgo.getScriptContext() jsContext = scriptContext.GetNativeContext() jsPrincipals = principal.getJSPrincipals() globalJSObject = sgo.GetGlobalJSObject() JS_EvaluateUCScriptForPrincipals(jsContext, globalJSObject, jsPrincipals, ...) Thank-you in advance, Grant