Bug 933497: Teach ObjectWrapper.jsm to deal with Typed Arrays. r=bholley

--HG--
extra : rebase_source : ed6d5f41e302e7e0d721f533c9cdb773b381fc4f
This commit is contained in:
Kyle Huey 2013-12-04 11:53:21 -05:00
parent c5cf24313d
commit a935cc55b1

View File

@ -12,6 +12,18 @@ this.EXPORTED_SYMBOLS = ["ObjectWrapper"];
// Makes sure that we expose correctly chrome JS objects to content.
const TypedArrayThings = [
"Int8Array",
"Uint8Array",
"Uint8ClampedArray",
"Int16Array",
"Uint16Array",
"Int32Array",
"Uint32Array",
"Float32Array",
"Float64Array",
];
this.ObjectWrapper = {
getObjectKind: function objWrapper_getObjectKind(aObject) {
if (aObject === null || aObject === undefined) {
@ -24,6 +36,8 @@ this.ObjectWrapper = {
return "blob";
} else if (aObject instanceof Date) {
return "date";
} else if (TypedArrayThings.indexOf(aObject.constructor.name) !== -1) {
return aObject.constructor.name;
} else if (typeof aObject == "object") {
return "object";
} else {
@ -40,6 +54,11 @@ this.ObjectWrapper = {
res.push(this.wrap(aObj, aCtxt));
}, this);
return res;
} else if (TypedArrayThings.indexOf(kind) !== -1) {
// This is slow, because from the perspective of the constructor in aCtxt
// aObject is a CCW, and it gets the indexed properties one by one rather
// instead of realizing that this is already a typed array thing.
return new aCtxt[kind](aObject);
} else if (kind == "file") {
return new aCtxt.File(aObject,
{ name: aObject.name,