Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXPCComponents_Utils.evalInSandbox]

217 views
Skip to first unread message

John J Barton

unread,
Mar 17, 2009, 1:19:02 PM3/17/09
to
In Firefox 3.1b3, code something like this:

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

Neil

unread,
Mar 18, 2009, 8:23:26 AM3/18/09
to
John J Barton wrote:

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.

John J Barton

unread,
Mar 19, 2009, 7:30:11 PM3/19/09
to
Neil wrote:
> John J Barton wrote:
>
>> In Firefox 3.1b3, code something like this:
>>
>> sandbox = new Components.utils.Sandbox(win);
>> sandbox.__proto__ = (win.wrappedJSObject?win.wrappedJSObject:win);

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

unread,
Mar 20, 2009, 6:50:45 AM3/20/09
to
John J Barton wrote:

> 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?

John J Barton

unread,
Mar 20, 2009, 3:29:35 PM3/20/09
to
I ran into this problem again so I opened a bug report for it,
https://bugzilla.mozilla.org/show_bug.cgi?id=484459


jjb

John J Barton

unread,
Mar 20, 2009, 4:41:18 PM3/20/09
to
John J Barton wrote:
> I ran into this problem again so I opened a bug report for it,
> https://bugzilla.mozilla.org/show_bug.cgi?id=484459

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

0 new messages