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/core.js | 42 ++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'node_modules/montage/core/core.js') 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); } } -- cgit v1.2.3