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