Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

using JS_EvaluateUCScriptForPrincipals() in XULRunner 24

瀏覽次數:18 次
跳到第一則未讀訊息

Grant Gayed

未讀,
2013年8月28日 下午1:53:442013/8/28
收件者:
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
0 則新訊息