michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict" michael@0: michael@0: const Cu = Components.utils; michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: michael@0: this.EXPORTED_SYMBOLS = ["ObjectWrapper"]; michael@0: michael@0: // Makes sure that we expose correctly chrome JS objects to content. michael@0: michael@0: const TypedArrayThings = [ michael@0: "Int8Array", michael@0: "Uint8Array", michael@0: "Uint8ClampedArray", michael@0: "Int16Array", michael@0: "Uint16Array", michael@0: "Int32Array", michael@0: "Uint32Array", michael@0: "Float32Array", michael@0: "Float64Array", michael@0: ]; michael@0: michael@0: this.ObjectWrapper = { michael@0: getObjectKind: function objWrapper_getObjectKind(aObject) { michael@0: if (aObject === null || aObject === undefined) { michael@0: return "primitive"; michael@0: } else if (Array.isArray(aObject)) { michael@0: return "array"; michael@0: } else if (aObject instanceof Ci.nsIDOMFile) { michael@0: return "file"; michael@0: } else if (aObject instanceof Ci.nsIDOMBlob) { michael@0: return "blob"; michael@0: } else if (aObject instanceof Date) { michael@0: return "date"; michael@0: } else if (TypedArrayThings.indexOf(aObject.constructor.name) !== -1) { michael@0: return aObject.constructor.name; michael@0: } else if (typeof aObject == "object") { michael@0: return "object"; michael@0: } else { michael@0: return "primitive"; michael@0: } michael@0: }, michael@0: michael@0: wrap: function objWrapper_wrap(aObject, aCtxt) { michael@0: dump("-*- ObjectWrapper is deprecated. Use Components.utils.cloneInto() instead.\n"); michael@0: return Cu.cloneInto(aObject, aCtxt, { cloneFunctions: true }); michael@0: } michael@0: }