1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/ObjectWrapper.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict" 1.9 + 1.10 +const Cu = Components.utils; 1.11 +const Cc = Components.classes; 1.12 +const Ci = Components.interfaces; 1.13 + 1.14 +this.EXPORTED_SYMBOLS = ["ObjectWrapper"]; 1.15 + 1.16 +// Makes sure that we expose correctly chrome JS objects to content. 1.17 + 1.18 +const TypedArrayThings = [ 1.19 + "Int8Array", 1.20 + "Uint8Array", 1.21 + "Uint8ClampedArray", 1.22 + "Int16Array", 1.23 + "Uint16Array", 1.24 + "Int32Array", 1.25 + "Uint32Array", 1.26 + "Float32Array", 1.27 + "Float64Array", 1.28 +]; 1.29 + 1.30 +this.ObjectWrapper = { 1.31 + getObjectKind: function objWrapper_getObjectKind(aObject) { 1.32 + if (aObject === null || aObject === undefined) { 1.33 + return "primitive"; 1.34 + } else if (Array.isArray(aObject)) { 1.35 + return "array"; 1.36 + } else if (aObject instanceof Ci.nsIDOMFile) { 1.37 + return "file"; 1.38 + } else if (aObject instanceof Ci.nsIDOMBlob) { 1.39 + return "blob"; 1.40 + } else if (aObject instanceof Date) { 1.41 + return "date"; 1.42 + } else if (TypedArrayThings.indexOf(aObject.constructor.name) !== -1) { 1.43 + return aObject.constructor.name; 1.44 + } else if (typeof aObject == "object") { 1.45 + return "object"; 1.46 + } else { 1.47 + return "primitive"; 1.48 + } 1.49 + }, 1.50 + 1.51 + wrap: function objWrapper_wrap(aObject, aCtxt) { 1.52 + dump("-*- ObjectWrapper is deprecated. Use Components.utils.cloneInto() instead.\n"); 1.53 + return Cu.cloneInto(aObject, aCtxt, { cloneFunctions: true }); 1.54 + } 1.55 +}