Closed Bug 1198934 Opened 9 years ago Closed 9 years ago

Error: Accessing TypedArray data over Xrays is slow, and forbidden

Categories

(Firefox OS Graveyard :: General, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(firefox44 fixed)

RESOLVED FIXED
FxOS-S9 (16Oct)
Tracking Status
firefox44 --- fixed

People

(Reporter: madrid.crespo, Assigned: bholley)

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
Build ID: 20150824030206

Steps to reproduce:

I was trying to use NFC in a Firefox OS addon, and It worked okay, but after playing with mozSettings, it started to return the following error:

E/GeckoConsole(  210): [JavaScript Error: "Error: Accessing TypedArray data over Xrays is slow, and forbidden in order to encourage performant code. To copy TypedArrays across origin boundaries, consider using Components.utils.cloneInto()." {file: "app://{955fa431-548a-41ae-b20b-01fdf0988c42}/scripts/nfc.js" line: 111}]

This is my diff: https://github.com/CodingFree/NFC-Sleep/commit/7a6a7a2cd7f130872e0aff8273c9128e89324754#diff-d6c5855a62cf32a4dadbc2831f0f295f
Bobby, here's where the sandbox used to inject the add-on script is created: https://mxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ExtensionContent.jsm#211

Of course the add-on can't Cu.cloneInto()...
Flags: needinfo?(bobbyholley)
(In reply to [:fabrice] Fabrice Desré from comment #1)
> Bobby, here's where the sandbox used to inject the add-on script is created:
> https://mxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/
> ExtensionContent.jsm#211
> 
> Of course the add-on can't Cu.cloneInto()...

Actually it can - just pass { wantExportHelpers: true }
Flags: needinfo?(bobbyholley)
But we don't want to expose that to WebExtensions content scripts, right?
Bobby, is there any way to avoid or fix that error by my side? Any suggestion?
Flags: needinfo?(bobbyholley)
Sorry for the delay, just getting back from PTO.

Hm. So in an ideal world, the Xray caller would be getting its own TypedArray in its own compartment, and then we wouldn't have to deal with this Xrays-to-TypedArray business. However, that's bug 946906, which we haven't done yet. Given that this NFC stuff is all [Constant], we might be able to do something simpler than bug 946906, and just cache the value on the XrayWrapper somehow. Definitely doable, but would require some work.

In the mean time, and in terms of a more general approach, it seems like we can basically do one of the following:
(1) Expose cloning to WebExtensions
(2) Encourage such authors to use .wrappedJSObject. Adrian, this would solve your problem in the interim, but I'm pretty sure Bill wants to forbid .wrappedJSObject, because it's not possible to do anything like it in other engines. Bill, do you want to weigh in here?
(3) Nothing, and limp along with this feature gap.
Flags: needinfo?(bobbyholley) → needinfo?(wmccloskey)
Well, given that the extension here is already b2g-specific, it doesn't seem that horrible to do something Mozilla-specific. However, the point of WebExtensions is to be a stable API for add-on authors. That's not going to happen if we ask them to use internal stuff like this. If there's something future-proof that we can do here, that would be great. I don't really understand what's going on in this code, though, so I can't recommend anything specific.
Flags: needinfo?(wmccloskey)
Bill, I'm not sure where to flip the sandbox bit for WebExtensions content scripts. Can you point me to it?
Flags: needinfo?(wmccloskey)
Assignee: nobody → bobbyholley
Comment on attachment 8673875 [details] [diff] [review]
Support special-case WebExtension behavior for TypedArrays. v1

Review of attachment 8673875 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks!
Attachment #8673875 - Flags: review?(wmccloskey) → review+
Attachment #8673881 - Flags: review?(wmccloskey) → review+
I renamed it form 'isWebExtensionsContentScript' to 'isWebExtensionContentScript', which seems better.
https://hg.mozilla.org/mozilla-central/rev/de3d8a5f6537
https://hg.mozilla.org/mozilla-central/rev/fe814c656647
Status: UNCONFIRMED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → FxOS-S9 (16Oct)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: