Closed Bug 1525627 Opened 5 years ago Closed 5 years ago

Using import() from a Sandbox throws with NS_ERROR_OUT_OF_MEMORY

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla67
Tracking Status
firefox67 --- fixed

People

(Reporter: ochameau, Assigned: jonco)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

I was trying to see if we could start using import() in code DevTools modules,
but I'm getting exception when trying to use import() from a privileged Sandbox:

const s = Cu.Sandbox(Services.scriptSecurityManager.getSystemPrincipal());
Cu.evalInSandbox("import('https://cdn.jsdelivr.net/gh/lodash/lodash/camelCase.js')", s);

=> (NS_ERROR_OUT_OF_MEMORY) [nsIXPCComponents_Utils.evalInSandbox]" nsresult: "0x8007000e (NS_ERROR_OUT_OF_MEMORY)"

Note that the same applies to Sandbox with a content principal:

const s = Cu.Sandbox("http://jsdelivr.net")
Cu.evalInSandbox("import('https://cdn.jsdelivr.net/gh/lodash/lodash/camelCase.js')", s);

And it also fails if I'm trying to load a ES Modules from a resource URI:

const s = Cu.Sandbox(Services.scriptSecurityManager.getSystemPrincipal());
Cu.evalInSandbox("var x = import('resource://devtools/shared/event-emitter.jsm')", s)

(I added this event-emitter.jsm module, it doesn't exists in m-c)

Blocks: 1525652

Note that, this is not a must-have feature.

You may as well say import() is not planned to work in Sandboxes.
It's just that I was hitting this exception while looking into bug 1525652.

Modules are not implemented in the context of a Sandbox. However this should be reporting a more useful error than NS_ERROR_OUT_OF_MEMORY.

Assignee: nobody → jcoppeard

Patch to report an error if we can't find a ScriptLoader for the current context.

Attachment #9042530 - Flags: review?(amarchesini)
Attachment #9042530 - Flags: review?(amarchesini) → review+
Keywords: checkin-needed

Pushed by cbrindusan@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/95fd39d659bc
Report an error if there's no ScriptLoader for the current context. r=baku

Keywords: checkin-needed
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla67
No longer blocks: 1522042
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: