using JS_EvaluateUCScriptForPrincipals() in XULRunner 24

Skip to first unread message

Grant Gayed

Aug 28, 2013, 1:53:44 PM8/28/13
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 =
scriptContext = sgo.getScriptContext()
jsContext = scriptContext.GetNativeContext()
jsPrincipals = principal.getJSPrincipals()
globalJSObject = sgo.GetGlobalJSObject()
JS_EvaluateUCScriptForPrincipals(jsContext, globalJSObject,
jsPrincipals, ...)

Thank-you in advance,
Reply all
Reply to author
0 new messages