From d52aca45e0357b5597e13d9b74998abb75fabea5 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 16 Feb 2012 10:54:48 -0800 Subject: integrating the latest montage fixes for v0.6 into master Signed-off-by: Valerio Virgillito --- node_modules/montage/core/converter/converter.js | 10 ------ .../montage/core/converter/date-converter.js | 10 +++--- node_modules/montage/core/core.js | 42 +++++++++++++--------- node_modules/montage/core/deserializer.js | 4 +-- node_modules/montage/core/event/binding.js | 8 +++-- node_modules/montage/core/event/event-manager.js | 5 +-- node_modules/montage/core/event/mutable-event.js | 1 + node_modules/montage/core/promise.js | 36 +++++++++++-------- node_modules/montage/core/shim/string.js | 15 ++++++++ node_modules/montage/core/undo-manager.js | 0 node_modules/montage/core/url.js | 0 11 files changed, 77 insertions(+), 54 deletions(-) mode change 100755 => 100644 node_modules/montage/core/undo-manager.js mode change 100755 => 100644 node_modules/montage/core/url.js (limited to 'node_modules/montage/core') diff --git a/node_modules/montage/core/converter/converter.js b/node_modules/montage/core/converter/converter.js index abce44e2..a23d2702 100755 --- a/node_modules/montage/core/converter/converter.js +++ b/node_modules/montage/core/converter/converter.js @@ -20,16 +20,6 @@ var FUNCTION_CLASS = '[object Function]', var _toString = Object.prototype.toString; -// TODO should maybe move these into String.isString and Number.isNumber to parallel Array.isArray - -/** - @exports module:montage/core/converter#isString - @function -*/ -var isString = function(object) { - return _toString.call(object) === STRING_CLASS; -}; -exports.isString = isString; /** @exports module:montage/core/converter#isNumber diff --git a/node_modules/montage/core/converter/date-converter.js b/node_modules/montage/core/converter/date-converter.js index f0d3e540..f484f7aa 100755 --- a/node_modules/montage/core/converter/date-converter.js +++ b/node_modules/montage/core/converter/date-converter.js @@ -2502,16 +2502,13 @@ var _toString = Object.prototype.toString; var isDate = function(object) { return _toString.call(object) === DATE_CLASS; }; -var isString = function(object) { - return _toString.call(object) === STRING_CLASS; -}; var isNumber = function(object) { return _toString.call(object) === NUMBER_CLASS; }; var formatDate = function(v, format) { var date; - if (isString(v)) { + if (String.isString(v)) { // try to create a Date instance from the string // date must be a string that can be parsed by Date // see - http://www.w3schools.com/jsref/jsref_parse.asp @@ -2605,7 +2602,7 @@ var DateConverter = exports.DateConverter = Montage.create(Converter,/** @lends */ convert: { value: function(v) { - if (isDate(v) || isString(v) || isNumber(v)) { + if (isDate(v) || String.isString(v) || isNumber(v)) { return formatDate(v, this.pattern); } return v; @@ -2617,6 +2614,9 @@ var DateConverter = exports.DateConverter = Montage.create(Converter,/** @lends */ revert: { value: function(v) { + if(isDate(v)) { + return v; + } this.validator.pattern = this.pattern; var result = this.validator.validate(v); diff --git a/node_modules/montage/core/core.js b/node_modules/montage/core/core.js index 8c1f4249..ff94f303 100755 --- a/node_modules/montage/core/core.js +++ b/node_modules/montage/core/core.js @@ -12,6 +12,16 @@ */ require("core/shim"); +var ATTRIBUTE_PROPERTIES = "AttributeProperties", + UNDERSCORE = "_", + PROTO = "__proto__", + VALUE = "value", + ENUMERABLE = "enumerable", + SERIALIZABLE = "serializable", + MODIFY = "modify"; + + + /** @external Object */ @@ -78,14 +88,14 @@ Object.defineProperty(M, "create", { } }); -var extendedPropertyAttributes = ["serializable", "modify"]; +var extendedPropertyAttributes = [SERIALIZABLE, MODIFY]; // Extended property attributes, the property name format is "_" + attributeName + "AttributeProperties" /** @member external:Object#extendedPropertyAttributes */ extendedPropertyAttributes.forEach(function(name) { - Object.defineProperty(Object.prototype, "_" + name + "AttributeProperties", { + Object.defineProperty(Object.prototype, UNDERSCORE + name + ATTRIBUTE_PROPERTIES, { enumerable: false, configurable: false, writable: false, @@ -112,11 +122,11 @@ Object.defineProperty(M, "defineProperty", { value: function(obj, prop, descriptor) { var dependencies = descriptor.dependencies; //reset defaults appropriately for framework. - if ("__proto__" in descriptor) { - descriptor.__proto__ = ("value" in descriptor ? (typeof descriptor.value === "function" ? _defaultFunctionValueProperty : _defaultObjectValueProperty) : _defaultAccessorProperty); + if (PROTO in descriptor) { + descriptor.__proto__ = (VALUE in descriptor ? (typeof descriptor.value === "function" ? _defaultFunctionValueProperty : _defaultObjectValueProperty) : _defaultAccessorProperty); } else { var defaults; - if ("value" in descriptor) { + if (VALUE in descriptor) { if (typeof descriptor.value === "function") { defaults = _defaultFunctionValueProperty; } else { @@ -133,7 +143,7 @@ Object.defineProperty(M, "defineProperty", { } - if (!descriptor.hasOwnProperty("enumerable") && prop.charAt(0) === "_") { + if (!descriptor.hasOwnProperty(ENUMERABLE) && prop.charAt(0) === UNDERSCORE) { descriptor.enumerable = false; } if (dependencies) { @@ -146,13 +156,13 @@ Object.defineProperty(M, "defineProperty", { } - if ("serializable" in descriptor) { + if (SERIALIZABLE in descriptor) { // get the _serializableAttributeProperties property or creates it through the entire chain if missing. - getAttributeProperties(obj, "serializable")[prop] = descriptor.serializable; + getAttributeProperties(obj, SERIALIZABLE)[prop] = descriptor.serializable; } - if ("modify" in descriptor) { - getAttributeProperties(obj, "modify")[prop] = descriptor.modify; + if (MODIFY in descriptor) { + getAttributeProperties(obj, MODIFY)[prop] = descriptor.modify; } //this is added to enable value properties with [] or Objects that are new for every instance @@ -268,7 +278,7 @@ Object.defineProperty(M, "defineProperty", { } }); } - })("_" + prop, descriptor.value); + })(UNDERSCORE + prop, descriptor.value); } else { return Object.defineProperty(obj, prop, descriptor); @@ -390,7 +400,7 @@ M.defineProperty(M, "removeDependencyFromProperty", {value: function(obj, indepe }}); function getAttributeProperties(proto, attributeName) { - var attributePropertyName = "_" + attributeName + "AttributeProperties"; + var attributePropertyName = UNDERSCORE + attributeName + ATTRIBUTE_PROPERTIES; if (proto.hasOwnProperty(attributePropertyName)) { return proto[attributePropertyName]; @@ -474,7 +484,7 @@ M.defineProperty(M, "getSerializablePropertyNames", {value: function(anObject) { */ M.defineProperty(M, "getPropertyAttribute", {value: function(anObject, propertyName, attributeName) { - var attributePropertyName = "_" + attributeName + "AttributeProperties", + var attributePropertyName = UNDERSCORE + attributeName + ATTRIBUTE_PROPERTIES, attributes = anObject[attributePropertyName]; if (attributes) { @@ -491,7 +501,7 @@ M.defineProperty(M, "getPropertyAttribute", {value: function(anObject, propertyN */ M.defineProperty(M, "getPropertyAttributes", {value: function(anObject, attributeName) { var attributeValues = {}, - attributePropertyName = "_" + attributeName + "AttributeProperties", + attributePropertyName = UNDERSCORE + attributeName + ATTRIBUTE_PROPERTIES, attributes = anObject[attributePropertyName]; if (!attributes) { @@ -623,7 +633,7 @@ var uuidGetGenerator = function() { }); } //This is really because re-defining the property on DOMWindow actually doesn't work, so the original property with the getter is still there and return this._uuid if there. - if (this instanceof Element || !info.isInstance || !("value" in Object.getOwnPropertyDescriptor(this, "uuid")) || !("__proto__" in this /* lame way to detect IE */)) { + if (this instanceof Element || !info.isInstance || !(VALUE in Object.getOwnPropertyDescriptor(this, "uuid")) || !(PROTO in this /* lame way to detect IE */)) { //This is needed to workaround some bugs in Safari where re-defining uuid doesn't work for DOMWindow. this._uuid = uuid; } @@ -846,7 +856,7 @@ Object.defineProperty(Object.prototype, "setProperty", { // For these mutation/addition/removal events, use the 'modify' attribute of this property's descriptor if (changeEvent && (changeEvent.currentTarget === lastObjectAtPath) && - (modify = M.getPropertyAttribute(setObject, aPropertyPath, "modify"))) { + (modify = M.getPropertyAttribute(setObject, aPropertyPath, MODIFY))) { modify.call(setObject, changeEvent.type, changeEvent.newValue, changeEvent.prevValue); } } diff --git a/node_modules/montage/core/deserializer.js b/node_modules/montage/core/deserializer.js index 09635153..0abc924b 100755 --- a/node_modules/montage/core/deserializer.js +++ b/node_modules/montage/core/deserializer.js @@ -62,7 +62,7 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri @private */ // list of ids that were just created for optimization - _optimizedIds: {value: {}}, + _optimizedIds: {value: Object.create(null)}, _indexedDeserializationUnits: {value: {}}, @@ -388,7 +388,7 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri value: function(doc) { var idAttributeName = Deserializer._MONTAGE_ID_ATTRIBUTE, elements = doc.querySelectorAll('*[' + idAttributeName + ']'), - ids = this._optimizedIds = {}; + ids = this._optimizedIds = Object.create(null); for (var i = 0, element; (element = elements[i]); i++) { if (!element.id) { diff --git a/node_modules/montage/core/event/binding.js b/node_modules/montage/core/event/binding.js index f061e89a..21b40609 100755 --- a/node_modules/montage/core/event/binding.js +++ b/node_modules/montage/core/event/binding.js @@ -19,7 +19,9 @@ var Montage = require("montage").Montage, Serializer = require("core/serializer").Serializer, Deserializer = require("core/deserializer").Deserializer, defaultEventManager = require("core/event/event-manager").defaultEventManager, - AT_TARGET = 2; + AT_TARGET = 2, + UNDERSCORE = "_"; + /** @member external:Array#dispatchChangeEvent @@ -918,7 +920,7 @@ Object.defineProperty(Object.prototype, "addEventListener", { if ("value" in currentPropertyDescriptor) { //Create internal storage: - Object.defineProperty(currentObject, (internalStorageProperty = "_" + key), { + Object.defineProperty(currentObject, (internalStorageProperty = UNDERSCORE + key), { value: currentObject.getProperty(key), configurable: true, writable: true @@ -1009,7 +1011,7 @@ Object.defineProperty(Object.prototype, "addEventListener", { //TODO this is all duplicated from above, clean it up //Create internal storage: - Object.defineProperty(currentObject, (internalStorageProperty = "_" + key), { + Object.defineProperty(currentObject, (internalStorageProperty = UNDERSCORE + key), { value: currentObject.getProperty(key), configurable: true, writable: true diff --git a/node_modules/montage/core/event/event-manager.js b/node_modules/montage/core/event/event-manager.js index b3e97dbe..bef8a67c 100755 --- a/node_modules/montage/core/event/event-manager.js +++ b/node_modules/montage/core/event/event-manager.js @@ -19,7 +19,6 @@ var Montage = require("montage").Montage, MutableEvent = require("core/event/mutable-event").MutableEvent, - ActionEventListener = require("core/event/action-event-listener").ActionEventListener, Serializer = require("core/serializer").Serializer, Deserializer = require("core/deserializer").Deserializer, defaultEventManager; @@ -28,9 +27,7 @@ var Montage = require("montage").Montage, if (typeof window !== "undefined") { // client-side /* This is to handle browsers that have TouchEvents but don't have the global constructor function Touch */ -//if(TouchEvent && typeof window.Touch === "undefined") { -// HACK: The commented expression fails because Chrome on the desktop also has TouchEvent and in the code we're either registering touch events OR mouse events on most components. -if (typeof window.Touch === "undefined" && /Xoom|TouchPad/.test(navigator.userAgent)) { +if (typeof window.Touch === "undefined" && "ontouchstart" in window) { window.Touch = function() { }; (function() { diff --git a/node_modules/montage/core/event/mutable-event.js b/node_modules/montage/core/event/mutable-event.js index f94ee0b9..6f6a0cfd 100755 --- a/node_modules/montage/core/event/mutable-event.js +++ b/node_modules/montage/core/event/mutable-event.js @@ -105,6 +105,7 @@ var MutableEvent = exports.MutableEvent = Montage.create(Montage,/** @lends modu var changeEvent = new _changeEventConstructor(); changeEvent.type = "change@" + key; changeEvent.minus = minus; + changeEvent.plus = undefined; changeEvent.propertyChange = ChangeTypes.MODIFICATION; return changeEvent; } diff --git a/node_modules/montage/core/promise.js b/node_modules/montage/core/promise.js index df063846..eb9ccd86 100755 --- a/node_modules/montage/core/promise.js +++ b/node_modules/montage/core/promise.js @@ -30,7 +30,15 @@ "use strict"; -var TIMER; +var GET = "get", + PUT = "put", + DELETE = "delete", + POST = "post", + APPLY = "apply", + KEYS = "keys", + THEN = "then", + TIMER; + try { // bootstrapping can't handle relative identifiers TIMER = require("core/next-tick"); @@ -76,7 +84,7 @@ var Creatable = Object.create(Object.prototype, { }, writable: true, configurable: true - }, + } }); // Common implementation details of FulfilledPromise, RejectedPromise, and @@ -335,7 +343,7 @@ var PrimordialPromise = Creatable.create({ this.Promise.reject(reason, error) ); } - }, + } }) }, @@ -370,7 +378,7 @@ var PrimordialPromise = Creatable.create({ } }) - }, + } }); @@ -433,11 +441,11 @@ var Promise = PrimordialPromise.create({}, { // Descriptor for each of the three toPromise(value) .sendPromise( fulfill, - "then", + THEN, reject ) }, - "then", + THEN, function (reason, error, rejection) { if (done) { return; @@ -473,51 +481,51 @@ var Promise = PrimordialPromise.create({}, { // Descriptor for each of the three get: { value: function () { - return this.send("get", arguments); + return this.send(GET, arguments); } }, put: { value: function () { - return this.send("put", arguments); + return this.send(PUT, arguments); } }, "delete": { value: function () { - return this.send("delete", arguments); + return this.send(DELETE, arguments); } }, post: { value: function () { - return this.send("post", arguments); + return this.send(POST, arguments); } }, invoke: { value: function (name /*, ...args*/) { var args = Array.prototype.slice.call(arguments, 1); - return this.send("post", [name, args]); + return this.send(POST, [name, args]); } }, apply: { value: function () { - return this.send("apply", arguments); + return this.send(APPLY, arguments); } }, call: { value: function (thisp /*, ...args*/) { var args = Array.prototype.slice.call(arguments, 1); - return this.send("apply", [thisp, args]); + return this.send(APPLY, [thisp, args]); } }, keys: { value: function () { - return this.send("keys", []); + return this.send(KEYS, []); } }, diff --git a/node_modules/montage/core/shim/string.js b/node_modules/montage/core/shim/string.js index 1b71cec3..52f89710 100755 --- a/node_modules/montage/core/shim/string.js +++ b/node_modules/montage/core/shim/string.js @@ -63,4 +63,19 @@ Object.defineProperties(String.prototype, /** @lends external:String.prototype#* }); +/** + Shim implementation of String.isString() for browsers that don't yet support it. + @function external:String.isString() + @param {object} obj The object to determine if its a String. + @returns {boolean} Object.prototype.toString.call(obj) === "[object String]" +*/ +if (!String.isString) { + Object.defineProperty(String, "isString", { + value: function(obj) { + return Object.prototype.toString.call(obj) === "[object String]"; + } + }); +} + + diff --git a/node_modules/montage/core/undo-manager.js b/node_modules/montage/core/undo-manager.js old mode 100755 new mode 100644 diff --git a/node_modules/montage/core/url.js b/node_modules/montage/core/url.js old mode 100755 new mode 100644 -- cgit v1.2.3