Closed Bug 648828 Opened 14 years ago Closed 1 year ago

Typed arrays from chrome code are wrapped

Categories

(Core :: JavaScript Engine, enhancement)

enhancement

Tracking

()

RESOLVED INACTIVE

People

(Reporter: sunhaitao, Unassigned)

Details

(Whiteboard: [js-triage-done])

User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:2.0) Gecko/20100101 Firefox/4.0 Build Identifier: All typed arrays returned from chrome code seems being wrapped currently. This makes some operations quiet hard (if not impossible) -- for example, building an extension which returns an ImageData object (using an typed array as its 'data' field) can be drawn on canvas directly. Since typed arrays are sealed objects and contain raw numbers only, wrapping them seems not necessary. Reproducible: Always
Can you tell us exactly what operations you are trying to do on wrapped typed arrays, and exactly how they fail? Or better yet, provide a reduced test case?
I'm so sorry for not noticing and replying this in time. I'm working on an extension ( https://addons.mozilla.org/en-US/firefox/addon/conductory/ ) which can expose raw input/output data from/to devices to JS codes. It returns ImageData-like objects from chrome code to represent video frames. Due to this problem, such objects cannot be passed as the first argument of 'putImageData'. Here is a reduced list of steps to demonstrate this problem more clearly: 0. Ensure 'devtools.chrome.enabled' is true. Open 'about:blank'. 1. Open a Scratchpad. Set 'Environment' to 'Browser'. Execute following code: gBrowser.contentWindow.wrappedJSObject.createImageData = function (width, height) { var data = new Uint8Array(width * height * 4); for (var i = 0; i < data.length; i += 4) { data[i+3] = 255; } return { width:width, height:height, data:data } } 2. Open another Scratchpad. Set 'Environment' to 'Content'. Execute following code: var w = 320; var h = 240; var canvas = document.createElement("canvas"); canvas.setAttribute( "width", w); canvas.setAttribute("height", h); document.body.appendChild(canvas); var ctx = canvas..getContext('2d'); ctx.putImageData(createImageData(w, h), 0, 0); 3. The last line will throw an error, instead of drawing a black box.
Whiteboard: js-triage-needed
Exact class check in aisle three! This is the usual "code checks getClass() for an exact match and doesn't check for a wrapped match" problem, see the putImageData custom quickstub, specifically the part that expects the imagedata's "data" property is the necessary kind of typed array. Bug 654646 could be part of addressing this. For this bug, it's also possible better use of specific typed array APIs might be a solution.
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Windows 7 → All
Hardware: x86 → All
Whiteboard: js-triage-needed → [js-triage-done]
A related problem is that accessing wrapped typed arrays in Gecko are much slower than unwrapped ones. This makes many operations (for example, motion detection) hard to finish in reasonable time. So I think either "not wrapping typed arrays" or "creating a unwrapped typed array sharing the same buffer" is a better solution for this bug.
Accessing wrapped anything is slower, since it has to do security checks. And for that very same reason, I think your proposed better solutions don't necessarily work, unless we can prove that it's ok to skip those security checks....
Assignee: general → nobody
Severity: normal → S3

From what I can tell, putImageData() does unwrap its array now.

Status: NEW → RESOLVED
Type: defect → enhancement
Closed: 1 year ago
Resolution: --- → INACTIVE
You need to log in before you can comment on or make changes to this bug.