2012-08-19 12:00:19 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict"
|
|
|
|
|
2012-10-25 11:45:14 -07:00
|
|
|
const Cu = Components.utils;
|
2012-08-19 12:00:19 -07:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.EXPORTED_SYMBOLS = ["ObjectWrapper"];
|
2012-08-19 12:00:19 -07:00
|
|
|
|
|
|
|
// Makes sure that we expose correctly chrome JS objects to content.
|
|
|
|
|
2013-12-04 08:53:21 -08:00
|
|
|
const TypedArrayThings = [
|
|
|
|
"Int8Array",
|
|
|
|
"Uint8Array",
|
|
|
|
"Uint8ClampedArray",
|
|
|
|
"Int16Array",
|
|
|
|
"Uint16Array",
|
|
|
|
"Int32Array",
|
|
|
|
"Uint32Array",
|
|
|
|
"Float32Array",
|
|
|
|
"Float64Array",
|
|
|
|
];
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.ObjectWrapper = {
|
2012-12-11 00:30:53 -08:00
|
|
|
getObjectKind: function objWrapper_getObjectKind(aObject) {
|
2012-12-12 14:58:11 -08:00
|
|
|
if (aObject === null || aObject === undefined) {
|
|
|
|
return "primitive";
|
|
|
|
} else if (Array.isArray(aObject)) {
|
2012-10-25 11:45:14 -07:00
|
|
|
return "array";
|
2012-12-11 00:30:53 -08:00
|
|
|
} else if (aObject instanceof Ci.nsIDOMFile) {
|
|
|
|
return "file";
|
|
|
|
} else if (aObject instanceof Ci.nsIDOMBlob) {
|
2012-10-25 11:45:14 -07:00
|
|
|
return "blob";
|
2012-12-16 21:29:00 -08:00
|
|
|
} else if (aObject instanceof Date) {
|
|
|
|
return "date";
|
2013-12-04 08:53:21 -08:00
|
|
|
} else if (TypedArrayThings.indexOf(aObject.constructor.name) !== -1) {
|
|
|
|
return aObject.constructor.name;
|
2012-10-25 11:45:14 -07:00
|
|
|
} else if (typeof aObject == "object") {
|
|
|
|
return "object";
|
|
|
|
} else {
|
|
|
|
return "primitive";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-08-19 12:00:19 -07:00
|
|
|
wrap: function objWrapper_wrap(aObject, aCtxt) {
|
2014-01-30 11:39:46 -08:00
|
|
|
dump("-*- ObjectWrapper is deprecated. Use Components.utils.cloneInto() instead.\n");
|
|
|
|
return Cu.cloneInto(aObject, aCtxt, { cloneFunctions: true });
|
2012-08-19 12:00:19 -07:00
|
|
|
}
|
|
|
|
}
|