diff options
Diffstat (limited to 'node_modules/montage-user/core/deserializer.js')
-rwxr-xr-x | node_modules/montage-user/core/deserializer.js | 859 |
1 files changed, 0 insertions, 859 deletions
diff --git a/node_modules/montage-user/core/deserializer.js b/node_modules/montage-user/core/deserializer.js deleted file mode 100755 index 09635153..00000000 --- a/node_modules/montage-user/core/deserializer.js +++ /dev/null | |||
@@ -1,859 +0,0 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | /** | ||
8 | @module montage/core/deserializer | ||
9 | @requires montage/core/core | ||
10 | @requires montage/core/core/logger | ||
11 | @requires montage/core/promise | ||
12 | */ | ||
13 | |||
14 | var Montage = require("montage").Montage, | ||
15 | logger = require("core/logger").logger("deserializer"), | ||
16 | Promise = require("core/promise").Promise; | ||
17 | |||
18 | // By rebinding eval to a new name, it loses its ability to | ||
19 | // capture the calling scope. | ||
20 | var globalEval = eval; | ||
21 | |||
22 | /** | ||
23 | @class module:montage/core/deserializer.Deserializer | ||
24 | @extends module:montage/core/core.Montage | ||
25 | */ | ||
26 | var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deserializer.Deserializer# */ { | ||
27 | _MONTAGE_ID_ATTRIBUTE: {value: "data-montage-id"}, | ||
28 | |||
29 | _objects: {value: null}, | ||
30 | /** | ||
31 | @private | ||
32 | */ | ||
33 | _objectStack: {value: []}, | ||
34 | _modules: {value: {}}, | ||
35 | /** | ||
36 | @private | ||
37 | */ | ||
38 | _requiredModuleIds: {value: null}, | ||
39 | _objectLabels: {value: null}, | ||
40 | /** | ||
41 | @private | ||
42 | */ | ||
43 | _serializationString: {value: null, enumerable: false}, | ||
44 | /** | ||
45 | @private | ||
46 | */ | ||
47 | _serialization: {value: null, enumerable: false}, | ||
48 | /** | ||
49 | @private | ||
50 | */ | ||
51 | _parseFunction: {value: null, enumerable: false}, | ||
52 | /** | ||
53 | @private | ||
54 | */ | ||
55 | _deserializationUnits: {value: []}, | ||
56 | // name -> function | ||
57 | /** | ||
58 | @private | ||
59 | */ | ||
60 | |||
61 | /** | ||
62 | @private | ||
63 | */ | ||
64 | // list of ids that were just created for optimization | ||
65 | _optimizedIds: {value: {}}, | ||
66 | |||
67 | _indexedDeserializationUnits: {value: {}}, | ||
68 | |||
69 | __sharedDocument: { | ||
70 | value: null | ||
71 | }, | ||
72 | |||
73 | _sharedDocument: { | ||
74 | get: function() { | ||
75 | return this.__cachedDoc ? this.__cachedDoc : (this.__cachedDoc = window.document.implementation.createHTMLDocument("")); | ||
76 | } | ||
77 | }, | ||
78 | /** | ||
79 | @private | ||
80 | */ | ||
81 | _reset: {value: function() { | ||
82 | this._serializationString = null; | ||
83 | this._requiredModuleIds = null; | ||
84 | this._parseFunction = null; | ||
85 | this._serialization = null; | ||
86 | this._compiledDeserializationFunction = null; | ||
87 | this._compiledDeserializationFunctionString = null; | ||
88 | this._origin = null; | ||
89 | }}, | ||
90 | |||
91 | /** | ||
92 | Initializes the deserializer with a string of serialized objects. | ||
93 | @function | ||
94 | @param {String} string A string of serialized objects. | ||
95 | @param {String} origin The origin of the serialization, usually a filename. | ||
96 | @returns itself | ||
97 | */ | ||
98 | initWithString: {value: function(string, origin) { | ||
99 | this._reset(); | ||
100 | this._serializationString = string; | ||
101 | this._origin = origin; | ||
102 | return this; | ||
103 | }}, | ||
104 | /** | ||
105 | Initializes the deserializer object with an object representing a serialization. Since the serialization is a JSON string it is also possible to represent it in a JavaScript object. | ||
106 | @function | ||
107 | @param {object} object The serialization in JavaScript object form. | ||
108 | @returns itself | ||
109 | */ | ||
110 | initWithObject: {value: function(object) { | ||
111 | this._reset(); | ||
112 | this._serializationString = JSON.stringify(object); | ||
113 | return this; | ||
114 | }}, | ||
115 | |||
116 | /** | ||
117 | Initializes the deserializer object with a serialization string and the require object used to load the modules containing the object's prototypes. | ||
118 | @function | ||
119 | @param {string} string The serialization string. | ||
120 | @param {function} require The require function to load the modules. | ||
121 | @param {string} origin The origin of the serialization, usually a filename. | ||
122 | @returns itself | ||
123 | */ | ||
124 | initWithStringAndRequire: {value: function(string, require, origin) { | ||
125 | this._reset(); | ||
126 | this._serializationString = string; | ||
127 | this._require = require; | ||
128 | this._origin = origin; | ||
129 | return this; | ||
130 | }}, | ||
131 | |||
132 | /** | ||
133 | Defines a deserialization unit for an object. | ||
134 | @function | ||
135 | @param {string} name The unit name. | ||
136 | @param {function} funktion The delegate function that reads the serialization unit and deserializes its content into the object being deserialized. This function accepts the object being deserialized and the serialized unit as arguments. | ||
137 | */ | ||
138 | defineDeserializationUnit: {value: function(name, funktion) { | ||
139 | this._deserializationUnits.push({ | ||
140 | name: name, | ||
141 | funktion: this._indexedDeserializationUnits[name] = funktion | ||
142 | }); | ||
143 | }}, | ||
144 | |||
145 | /** | ||
146 | Returns an array with all the objects that were created or used during the call to deserializeWith* functions. | ||
147 | @function | ||
148 | @returns {Array} The array of objects. | ||
149 | */ | ||
150 | getObjectsFromLastDeserialization: {value: function() { | ||
151 | var objects = this._objects; | ||
152 | var objectsArray = []; | ||
153 | |||
154 | for (var key in objects) { | ||
155 | if (objects.hasOwnProperty(key)) { | ||
156 | objectsArray.push(objects[key]); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | return objectsArray; | ||
161 | }}, | ||
162 | /** | ||
163 | This function is to be used in the context of deserializeSelf delegate used for custom object deserializations. | ||
164 | It reads an entry from the "properties" serialization unit of the object being deserialized. | ||
165 | @function | ||
166 | @param {string} name The name of the entry to be read. | ||
167 | @returns {*} The value of the entry | ||
168 | */ | ||
169 | get: {value: function(name) { | ||
170 | var stack = this._objectStack; | ||
171 | var ix = stack.length - 1; | ||
172 | |||
173 | return stack[ix][name]; | ||
174 | }}, | ||
175 | |||
176 | /** | ||
177 | This function is to be used in the context of deserializeSelf delegate used for custom object deserializations. | ||
178 | It deserializes all the named properties of a serialized object into the object given. | ||
179 | @function | ||
180 | @param {Object} object The target of the properties. | ||
181 | @param {Array} properties The property names to be deserialized. | ||
182 | */ | ||
183 | deserializePropertiesForObject: {value: function(object, properties) { | ||
184 | // TODO: ensure backward compatibility | ||
185 | if (properties && "childComponents" in properties) { | ||
186 | properties.childComponents = []; | ||
187 | console.log('Warning: "childComponents" isn\'t supported on components within the current serializaation format, this property will be reset to [].'); | ||
188 | } | ||
189 | for (var key in properties) { | ||
190 | object[key] = properties[key]; | ||
191 | } | ||
192 | }}, | ||
193 | |||
194 | /** | ||
195 | The function works on the top most object of an object stack.<br> | ||
196 | This method pushes an object to that stack making it the target of future calls. | ||
197 | @function | ||
198 | @param {object} object The object to push into the stack. | ||
199 | @private | ||
200 | */ | ||
201 | _pushContextObject: {value: function(object) { | ||
202 | this._objectStack.push(object); | ||
203 | }}, | ||
204 | |||
205 | /** | ||
206 | The function works on the top most object of an object stack.<br> | ||
207 | This method pops the top most object out of that stack making future calls to target the next object in the stack. | ||
208 | @function | ||
209 | @returns {object} The top most object in the stack. | ||
210 | @private | ||
211 | */ | ||
212 | _popContextObject: {value: function() { | ||
213 | return this._objectStack.pop(); | ||
214 | }}, | ||
215 | /** | ||
216 | @private | ||
217 | */ | ||
218 | _require: { | ||
219 | enumerable: false, | ||
220 | value: null | ||
221 | }, | ||
222 | /** | ||
223 | @private | ||
224 | */ | ||
225 | _defaultModuleLoader: { | ||
226 | enumerable: false, | ||
227 | value: function(moduleIds, callback) { | ||
228 | if (typeof require !== "function") { | ||