aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/core
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/core')
-rwxr-xr-xnode_modules/montage/core/core.js20
-rwxr-xr-xnode_modules/montage/core/deserializer.js115
-rwxr-xr-xnode_modules/montage/core/serializer.js45
3 files changed, 145 insertions, 35 deletions
diff --git a/node_modules/montage/core/core.js b/node_modules/montage/core/core.js
index ff94f303..8fcf7977 100755
--- a/node_modules/montage/core/core.js
+++ b/node_modules/montage/core/core.js
@@ -71,14 +71,14 @@ Object.defineProperty(M, "create", {
71 71
72 var newObject = Object.create(typeof aPrototype === "undefined" ? this : aPrototype); 72 var newObject = Object.create(typeof aPrototype === "undefined" ? this : aPrototype);
73 73
74 if (typeof newObject.didCreate === "function") {
75 newObject.didCreate();
76 }
77
78 if (newObject._dependenciesForProperty) { 74 if (newObject._dependenciesForProperty) {
79 newObject._dependencyListeners = {}; 75 newObject._dependencyListeners = {};
80 } 76 }
81 77
78 if (typeof newObject.didCreate === "function") {
79 newObject.didCreate();
80 }
81
82 return newObject; 82 return newObject;
83 } else { 83 } else {
84 var result = Object.create(aPrototype); 84 var result = Object.create(aPrototype);
@@ -713,13 +713,17 @@ if (!Object.seal) {
713 */ 713 */
714Object.defineProperty(M, "callDelegateMethod", { 714Object.defineProperty(M, "callDelegateMethod", {
715 value: function(name) { 715 value: function(name) {
716 var delegate, delegateFunctionName, delegateFunction; 716 var delegate = this.delegate, delegateFunctionName, delegateFunction;
717 if (typeof this.identifier === "string") { 717 if (typeof this.identifier === "string") {
718 delegateFunctionName = this.identifier + name.toCapitalized(); 718 delegateFunctionName = this.identifier + name.toCapitalized();
719 } else { 719 if (delegate && typeof (delegateFunction = delegate[delegateFunctionName]) === "function") {
720 delegateFunctionName = name; 720 // remove first argument
721 Array.prototype.shift.call(arguments);
722 return delegateFunction.apply(delegate, arguments);
723 }
721 } 724 }
722 if ((delegate = this.delegate) && typeof (delegateFunction = delegate[delegateFunctionName]) === "function") { 725
726 if (delegate && typeof (delegateFunction = delegate[name]) === "function") {
723 // remove first argument 727 // remove first argument
724 Array.prototype.shift.call(arguments); 728 Array.prototype.shift.call(arguments);
725 return delegateFunction.apply(delegate, arguments); 729 return delegateFunction.apply(delegate, arguments);
diff --git a/node_modules/montage/core/deserializer.js b/node_modules/montage/core/deserializer.js
index 0abc924b..7e812235 100755
--- a/node_modules/montage/core/deserializer.js
+++ b/node_modules/montage/core/deserializer.js
@@ -18,6 +18,14 @@ var Montage = require("montage").Montage,
18// By rebinding eval to a new name, it loses its ability to 18// By rebinding eval to a new name, it loses its ability to
19// capture the calling scope. 19// capture the calling scope.
20var globalEval = eval; 20var globalEval = eval;
21var canEval = true;
22
23// CSP doesn't let you eval
24try {
25 eval("");
26} catch(ex) {
27 canEval = false;
28}
21 29
22/** 30/**
23 @class module:montage/core/deserializer.Deserializer 31 @class module:montage/core/deserializer.Deserializer
@@ -81,6 +89,7 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri
81 _reset: {value: function() { 89 _reset: {value: function() {
82 this._serializationString = null; 90 this._serializationString = null;
83 this._requiredModuleIds = null; 91 this._requiredModuleIds = null;
92 this._areModulesLoaded = false;
84 this._parseFunction = null; 93 this._parseFunction = null;
85 this._serialization = null; 94 this._serialization = null;
86 this._compiledDeserializationFunction = null; 95 this._compiledDeserializationFunction = null;
@@ -342,7 +351,12 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri
342 this._parseForModules(); 351 this._parseForModules();
343 } 352 }
344 353
345 this._loadModules(this._requiredModuleIds, callback); 354 if (this._requiredModuleIds.length > 0) {
355 this._loadModules(this._requiredModuleIds, callback);
356 } else {
357 this._areModulesLoaded = true;
358 return callback();
359 }
346 }}, 360 }},
347 361
348 /** 362 /**
@@ -356,16 +370,40 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri
356/** 370/**
357 @private 371 @private
358*/ 372*/
373 _findObjectNameRegExp: {
374 value: /([^\/]+?)(\.reel)?$/
375 },
376 _toCamelCaseRegExp: {
377 value: /(?:^|-)([^-])/g
378 },
379 _replaceToCamelCase: {
380 value: function(_, g1) { return g1.toUpperCase() }
381 },
359 _parseForModules: {value: function() { 382 _parseForModules: {value: function() {
360 var serialization = this._serialization, 383 var serialization = this._serialization,
361 moduleIds = this._requiredModuleIds = [], 384 moduleIds = this._requiredModuleIds = [],
362 modules = this._modules; 385 modules = this._modules,
386 desc, moduleId;
363 387
364 for (var label in serialization) { 388 for (var label in serialization) {
365 var desc = serialization[label]; 389 desc = serialization[label];
366 var moduleId = desc.module; 390 moduleId = null;
391
392 if ("module" in desc) {
393 moduleId = desc.module;
394 } else if (name = /*assignment*/(desc.prototype || desc.object)) {
395 objectLocation = name.split("[");
396 moduleId = objectLocation[0];
397 desc.module = moduleId;
398 if (objectLocation.length == 2) {
399 desc.name = objectLocation[1].slice(0, -1);
400 } else {
401 this._findObjectNameRegExp.test(moduleId);
402 desc.name = RegExp.$1.replace(this._toCamelCaseRegExp, this._replaceToCamelCase);
403 }
404 }
367 405
368 if (moduleId && moduleIds.indexOf(moduleId) == -1 && !modules[moduleId]) { 406 if (moduleId && !modules[moduleId] && moduleIds.indexOf(moduleId) == -1) {
369 moduleIds.push(moduleId); 407 moduleIds.push(moduleId);
370 } 408 }
371 } 409 }
@@ -404,7 +442,7 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri
404*/ 442*/
405 _compileAndDeserialize: {value: function(element, deserialize) { 443 _compileAndDeserialize: {value: function(element, deserialize) {
406 var self = this, 444 var self = this,
407 serialization = this._serialization, 445 serialization,
408 exportsStrings = "", 446 exportsStrings = "",
409 unitsStrings = "", 447 unitsStrings = "",
410 objectsStrings = "", 448 objectsStrings = "",
@@ -418,6 +456,12 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri
418 objectNamesCounter = {}, 456 objectNamesCounter = {},
419 label; 457 label;
420 458
459 if (canEval) {
460 serialization = this._serialization;
461 } else {
462 serialization = JSON.parse(this._serializationString);
463 }
464
421 for (label in serialization) { 465 for (label in serialization) {
422 var objectDesc = serialization[label]; 466 var objectDesc = serialization[label];
423 467
@@ -452,28 +496,56 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri
452 } 496 }
453 } 497 }
454 498
455 this._compiledDeserializationFunctionString = "(function() {\n" + requireStrings.join("\n") + "\nreturn function(element) {\nvar exports = {};\n" + exportsStrings + "\n\n" + objectsStrings + "\n\n" + unitsStrings + "\n\n" + cleanupStrings + "\nreturn exports;\n}}).call(this)"; 499 if (canEval) {
500 this._compiledDeserializationFunctionString = "(function() {\n" + requireStrings.join("\n") + "\nreturn function(element) {\nvar exports = {};\n" + exportsStrings + "\n\n" + objectsStrings + "\n\n" + unitsStrings + "\n\n" + cleanupStrings + "\nreturn exports;\n}}).call(this)";
501 this._serializationString = this._serialization = serialization = null;
502 }
503
456 if (logger.isDebug) { 504 if (logger.isDebug) {
457 logger.debug(this._compiledDeserializationFunctionString); 505 logger.debug(this._compiledDeserializationFunctionString);
458 } 506 }
459 507
460 this._serialization = serialization = null;
461
462 return exports; 508 return exports;
463 509
464 function deserializeObject(label, desc) { 510 function deserializeObject(label, desc) {
465 var moduleId = desc.module, 511 var moduleId,
466 name = desc.name, 512 name,
467 objectName = name, 513 instance,
468 fqn = moduleId + "." + name, 514 objectName,
515 fqn,
469 properties = desc.properties, 516 properties = desc.properties,
517 isType,
470 object, 518 object,
471 counter, 519 counter,
472 propertiesString; 520 propertiesString,
521 objectLocation;
522
523 if ("module" in desc) {
524 moduleId = desc.module;
525 objectName = name = desc.name;
526 } else {
527 objectLocation = (desc.prototype || desc.object).split("[");
528 // this code is actually only used when canEval == false,
529 // module+name are added when the modules are parsed but it's
530 // slow to redo the _serializationString in order to keep the
531 // added module+name when we do JSON.parse(_serializationString)
532 // at canEval == false.
533 moduleId = objectLocation[0];
534 if (objectLocation.length == 2) {