Search code examples
javascriptspidermonkey

How to get 'chrome' code running in SpiderMonkey


I'm embedding Mozilla's SpiderMonkey in my application and would like to use its new JS Debugger API Guide - MDN introduced in v1.8.6. From the documentation, I understand that this API is not available to 'content code' but only to trusted so-called 'chrome code'. Now I have gone through a number of resources trying to understand how to execute 'chrome code', without much success. My guess is that the trusted script should be execute with JS_EvaluateScriptForPrincipals, but then I cannot understand how to use JSPrincipals...

Any help appreciated, thanks!


Solution

  • For a SpiderMonkey engine embedding, there are no such concepts. The idea of "chrome" and "content" is only legitimate in the browser, where "chrome" is privileged (like the Firefox UI / addons) and "content" is untrusted (like a web page).

    When you embed the JS engine you just have access to JavaScript, the language, with its typical built in classes and language features. When you build the shell and run it, you can just type "Debugger" and you'll see the debugger object is present. This happens whenever you create a new global in the SpiderMonkey engine.

    $ ./js
    js> Debugger
    function Debugger() {[native code]}