dom/base/ObjectWrapper.jsm

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict"
michael@0 6
michael@0 7 const Cu = Components.utils;
michael@0 8 const Cc = Components.classes;
michael@0 9 const Ci = Components.interfaces;
michael@0 10
michael@0 11 this.EXPORTED_SYMBOLS = ["ObjectWrapper"];
michael@0 12
michael@0 13 // Makes sure that we expose correctly chrome JS objects to content.
michael@0 14
michael@0 15 const TypedArrayThings = [
michael@0 16 "Int8Array",
michael@0 17 "Uint8Array",
michael@0 18 "Uint8ClampedArray",
michael@0 19 "Int16Array",
michael@0 20 "Uint16Array",
michael@0 21 "Int32Array",
michael@0 22 "Uint32Array",
michael@0 23 "Float32Array",
michael@0 24 "Float64Array",
michael@0 25 ];
michael@0 26
michael@0 27 this.ObjectWrapper = {
michael@0 28 getObjectKind: function objWrapper_getObjectKind(aObject) {
michael@0 29 if (aObject === null || aObject === undefined) {
michael@0 30 return "primitive";
michael@0 31 } else if (Array.isArray(aObject)) {
michael@0 32 return "array";
michael@0 33 } else if (aObject instanceof Ci.nsIDOMFile) {
michael@0 34 return "file";
michael@0 35 } else if (aObject instanceof Ci.nsIDOMBlob) {
michael@0 36 return "blob";
michael@0 37 } else if (aObject instanceof Date) {
michael@0 38 return "date";
michael@0 39 } else if (TypedArrayThings.indexOf(aObject.constructor.name) !== -1) {
michael@0 40 return aObject.constructor.name;
michael@0 41 } else if (typeof aObject == "object") {
michael@0 42 return "object";
michael@0 43 } else {
michael@0 44 return "primitive";
michael@0 45 }
michael@0 46 },
michael@0 47
michael@0 48 wrap: function objWrapper_wrap(aObject, aCtxt) {
michael@0 49 dump("-*- ObjectWrapper is deprecated. Use Components.utils.cloneInto() instead.\n");
michael@0 50 return Cu.cloneInto(aObject, aCtxt, { cloneFunctions: true });
michael@0 51 }
michael@0 52 }

mercurial