2012-08-19 19:00:19 +00: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 18:45:14 +00:00
|
|
|
const Cu = Components.utils;
|
2012-08-19 19:00:19 +00:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.EXPORTED_SYMBOLS = ["ObjectWrapper"];
|
2012-08-19 19:00:19 +00:00
|
|
|
|
|
|
|
// Makes sure that we expose correctly chrome JS objects to content.
|
|
|
|
|
2013-12-04 16:53:21 +00:00
|
|
|
const TypedArrayThings = [
|
|
|
|
"Int8Array",
|
|
|
|
"Uint8Array",
|
|
|
|
"Uint8ClampedArray",
|
|
|
|
"Int16Array",
|
|
|
|
"Uint16Array",
|
|
|
|
"Int32Array",
|
|
|
|
"Uint32Array",
|
|
|
|
"Float32Array",
|
|
|
|
"Float64Array",
|
|
|
|
];
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.ObjectWrapper = {
|
2012-12-11 08:30:53 +00:00
|
|
|
getObjectKind: function objWrapper_getObjectKind(aObject) {
|
2012-12-12 22:58:11 +00:00
|
|
|
if (aObject === null || aObject === undefined) {
|
|
|
|
return "primitive";
|
|
|
|
} else if (Array.isArray(aObject)) {
|
2012-10-25 18:45:14 +00:00
|
|
|
return "array";
|
2012-12-11 08:30:53 +00:00
|
|
|
} else if (aObject instanceof Ci.nsIDOMFile) {
|
|
|
|
return "file";
|
|
|
|
} else if (aObject instanceof Ci.nsIDOMBlob) {
|
2012-10-25 18:45:14 +00:00
|
|
|
return "blob";
|
2012-12-17 05:29:00 +00:00
|
|
|
} else if (aObject instanceof Date) {
|
|
|
|
return "date";
|
2013-12-04 16:53:21 +00:00
|
|
|
} else if (TypedArrayThings.indexOf(aObject.constructor.name) !== -1) {
|
|
|
|
return aObject.constructor.name;
|
2012-10-25 18:45:14 +00:00
|
|
|
} else if (typeof aObject == "object") {
|
|
|
|
return "object";
|
|
|
|
} else {
|
|
|
|
return "primitive";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-08-19 19:00:19 +00:00
|
|
|
wrap: function objWrapper_wrap(aObject, aCtxt) {
|
2014-01-30 19:39:46 +00:00
|
|
|
dump("-*- ObjectWrapper is deprecated. Use Components.utils.cloneInto() instead.\n");
|
|
|
|
return Cu.cloneInto(aObject, aCtxt, { cloneFunctions: true });
|
2012-08-19 19:00:19 +00:00
|
|
|
}
|
|
|
|
}
|