sandbox = new Components.utils.Sandbox(win);
sandbox.__proto__ = (win.wrappedJSObject?win.wrappedJSObject:win);
var scriptToEval = expr;
scriptToEval = "with (window?window:null) { " + scriptToEval + " \n};";
result = Components.utils.evalInSandbox(scriptToEval, sandbox);
(see
http://code.google.com/p/fbug/source/browse/branches/firebug1.4/content/firebug/commandLine.js#189)
Fails with
[Exception... "Component returned failure code: 0x80070057
(NS_ERROR_ILLEGAL_VALUE) [nsIXPCComponents_Utils.evalInSandbox]
I did not see any bugzilla entries about this and the MDC pages don't
mention ILLEGAL_VALUE exceptions. The only files in near to
xpccomponents.cpp that have ILLEGAL_VALUE are *Wrapper.cpp.
Any hints?
jjb
One possibility is the argument to the Sandbox constructor, which needs
to be a URI string or an object with a principal.
[What's with the (window?window:null) ?]
--
Warning: May contain traces of nuts.
The problem seems to be related to win.wrappedJSObject. If the true path
is taken above, then the eval step throws the exception, but only in
some cases. I found a way not to have to take this path in the case
that fails so I'm writing this off as "spells that don't work but aren't
needed"
>> var scriptToEval = expr;
>>
>> scriptToEval = "with (window?window:null) { " + scriptToEval + "
>> \n};";
>>
>> result = Components.utils.evalInSandbox(scriptToEval, sandbox);
...
>> Fails with
>> [Exception... "Component returned failure code: 0x80070057
>> (NS_ERROR_ILLEGAL_VALUE) [nsIXPCComponents_Utils.evalInSandbox]
...
>
> One possibility is the argument to the Sandbox constructor, which needs
> to be a URI string or an object with a principal.
How can I determine if an object has a principal?
>
> [What's with the (window?window:null) ?]
In case you eval in a component, there will be no 'window' object.
jjb
> Neil wrote:
>
>> One possibility is the argument to the Sandbox constructor, which
>> needs to be a URI string or an object with a principal.
>
> How can I determine if an object has a principal?
I don't know, but I believe all DOM nodes, documents and windows should
have one.
>> [What's with the (window?window:null) ?]
>
> In case you eval in a component, there will be no 'window' object.
Ah, is this some trick to work around a strict JS warning which would
otherwise result?
jjb
The problem is that the sandbox object:
result = Components.utils.evalInSandbox(scriptToEval, sandbox);
is a XPCSafeJSObjectWrapper so it's class is no longer Sandbox, and the
evalInSandbox() call aborts.
I simplified the code that fails:
var sandbox = new Components.utils.Sandbox(win.location.toString());
sandbox.__proto__ = win.wrappedJSObject;
I wonder if setting __proto__ causes the wrapper. This part is just
voodoo, there are no docs for the sandbox.
jjb