diff options
Diffstat (limited to 'node_modules/montage/core/core.js')
-rwxr-xr-x | node_modules/montage/core/core.js | 42 |
1 files changed, 26 insertions, 16 deletions
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 @@ | |||
12 | */ | 12 | */ |
13 | require("core/shim"); | 13 | require("core/shim"); |
14 | 14 | ||
15 | var ATTRIBUTE_PROPERTIES = "AttributeProperties", | ||
16 | UNDERSCORE = "_", | ||
17 | PROTO = "__proto__", | ||
18 | VALUE = "value", | ||
19 | ENUMERABLE = "enumerable", | ||
20 | SERIALIZABLE = "serializable", | ||
21 | MODIFY = "modify"; | ||
22 | |||
23 | |||
24 | |||
15 | /** | 25 | /** |
16 | @external Object | 26 | @external Object |
17 | */ | 27 | */ |
@@ -78,14 +88,14 @@ Object.defineProperty(M, "create", { | |||
78 | } | 88 | } |
79 | }); | 89 | }); |
80 | 90 | ||
81 | var extendedPropertyAttributes = ["serializable", "modify"]; | 91 | var extendedPropertyAttributes = [SERIALIZABLE, MODIFY]; |
82 | 92 | ||
83 | // Extended property attributes, the property name format is "_" + attributeName + "AttributeProperties" | 93 | // Extended property attributes, the property name format is "_" + attributeName + "AttributeProperties" |
84 | /** | 94 | /** |
85 | @member external:Object#extendedPropertyAttributes | 95 | @member external:Object#extendedPropertyAttributes |
86 | */ | 96 | */ |
87 | extendedPropertyAttributes.forEach(function(name) { | 97 | extendedPropertyAttributes.forEach(function(name) { |
88 | Object.defineProperty(Object.prototype, "_" + name + "AttributeProperties", { | 98 | Object.defineProperty(Object.prototype, UNDERSCORE + name + ATTRIBUTE_PROPERTIES, { |
89 | enumerable: false, | 99 | enumerable: false, |
90 | configurable: false, | 100 | configurable: false, |
91 | writable: false, | 101 | writable: false, |
@@ -112,11 +122,11 @@ Object.defineProperty(M, "defineProperty", { | |||
112 | value: function(obj, prop, descriptor) { | 122 | value: function(obj, prop, descriptor) { |
113 | var dependencies = descriptor.dependencies; | 123 | var dependencies = descriptor.dependencies; |
114 | //reset defaults appropriately for framework. | 124 | //reset defaults appropriately for framework. |
115 | if ("__proto__" in descriptor) { | 125 | if (PROTO in descriptor) { |
116 | descriptor.__proto__ = ("value" in descriptor ? (typeof descriptor.value === "function" ? _defaultFunctionValueProperty : _defaultObjectValueProperty) : _defaultAccessorProperty); | 126 | descriptor.__proto__ = (VALUE in descriptor ? (typeof descriptor.value === "function" ? _defaultFunctionValueProperty : _defaultObjectValueProperty) : _defaultAccessorProperty); |
117 | } else { | 127 | } else { |
118 | var defaults; | 128 | var defaults; |
119 | if ("value" in descriptor) { | 129 | if (VALUE in descriptor) { |
120 | if (typeof descriptor.value === "function") { | 130 | if (typeof descriptor.value === "function") { |
121 | defaults = _defaultFunctionValueProperty; | 131 | defaults = _defaultFunctionValueProperty; |
122 | } else { | 132 | } else { |
@@ -133,7 +143,7 @@ Object.defineProperty(M, "defineProperty", { | |||
133 | } | 143 | } |
134 | 144 | ||
135 | 145 | ||
136 | if (!descriptor.hasOwnProperty("enumerable") && prop.charAt(0) === "_") { | 146 | if (!descriptor.hasOwnProperty(ENUMERABLE) && prop.charAt(0) === UNDERSCORE) { |
137 | descriptor.enumerable = false; | 147 | descriptor.enumerable = false; |
138 | } | 148 | } |
139 | if (dependencies) { | 149 | if (dependencies) { |
@@ -146,13 +156,13 @@ Object.defineProperty(M, "defineProperty", { | |||
146 | 156 | ||
147 | } | 157 | } |
148 | 158 | ||
149 | if ("serializable" in descriptor) { | 159 | if (SERIALIZABLE in descriptor) { |
150 | // get the _serializableAttributeProperties property or creates it through the entire chain if missing. | 160 | // get the _serializableAttributeProperties property or creates it through the entire chain if missing. |
151 | getAttributeProperties(obj, "serializable")[prop] = descriptor.serializable; | 161 | getAttributeProperties(obj, SERIALIZABLE)[prop] = descriptor.serializable; |
152 | } | 162 | } |
153 | 163 | ||
154 | if ("modify" in descriptor) { | 164 | if (MODIFY in descriptor) { |
155 | getAttributeProperties(obj, "modify")[prop] = descriptor.modify; | 165 | getAttributeProperties(obj, MODIFY)[prop] = descriptor.modify; |
156 | } | 166 | } |
157 | 167 | ||
158 | //this is added to enable value properties with [] or Objects that are new for every instance | 168 | //this is added to enable value properties with [] or Objects that are new for every instance |
@@ -268,7 +278,7 @@ Object.defineProperty(M, "defineProperty", { | |||
268 | } | 278 | } |
269 | }); | 279 | }); |
270 | } | 280 | } |
271 | })("_" + prop, descriptor.value); | 281 | })(UNDERSCORE + prop, descriptor.value); |
272 | 282 | ||
273 | } else { | 283 | } else { |
274 | return Object.defineProperty(obj, prop, descriptor); | 284 | return Object.defineProperty(obj, prop, descriptor); |
@@ -390,7 +400,7 @@ M.defineProperty(M, "removeDependencyFromProperty", {value: function(obj, indepe | |||
390 | }}); | 400 | }}); |
391 | 401 | ||
392 | function getAttributeProperties(proto, attributeName) { | 402 | function getAttributeProperties(proto, attributeName) { |
393 | var attributePropertyName = "_" + attributeName + "AttributeProperties"; | 403 | var attributePropertyName = UNDERSCORE + attributeName + ATTRIBUTE_PROPERTIES; |
394 | 404 | ||
395 | if (proto.hasOwnProperty(attributePropertyName)) { | 405 | if (proto.hasOwnProperty(attributePropertyName)) { |
396 | return proto[attributePropertyName]; | 406 | return proto[attributePropertyName]; |
@@ -474,7 +484,7 @@ M.defineProperty(M, "getSerializablePropertyNames", {value: function(anObject) { | |||
474 | */ | 484 | */ |
475 | M.defineProperty(M, "getPropertyAttribute", {value: function(anObject, propertyName, attributeName) { | 485 | M.defineProperty(M, "getPropertyAttribute", {value: function(anObject, propertyName, attributeName) { |
476 | 486 | ||
477 | var attributePropertyName = "_" + attributeName + "AttributeProperties", | 487 | var attributePropertyName = UNDERSCORE + attributeName + ATTRIBUTE_PROPERTIES, |
478 | attributes = anObject[attributePropertyName]; | 488 | attributes = anObject[attributePropertyName]; |
479 | 489 | ||
480 | if (attributes) { | 490 | if (attributes) { |
@@ -491,7 +501,7 @@ M.defineProperty(M, "getPropertyAttribute", {value: function(anObject, propertyN | |||
491 | */ | 501 | */ |
492 | M.defineProperty(M, "getPropertyAttributes", {value: function(anObject, attributeName) { | 502 | M.defineProperty(M, "getPropertyAttributes", {value: function(anObject, attributeName) { |
493 | var attributeValues = {}, | 503 | var attributeValues = {}, |
494 | attributePropertyName = "_" + attributeName + "AttributeProperties", | 504 | attributePropertyName = UNDERSCORE + attributeName + ATTRIBUTE_PROPERTIES, |
495 | attributes = anObject[attributePropertyName]; | 505 | attributes = anObject[attributePropertyName]; |
496 | 506 | ||
497 | if (!attributes) { | 507 | if (!attributes) { |
@@ -623,7 +633,7 @@ var uuidGetGenerator = function() { | |||
623 | }); | 633 | }); |
624 | } | 634 | } |
625 | //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. | 635 | //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. |
626 | if (this instanceof Element || !info.isInstance || !("value" in Object.getOwnPropertyDescriptor(this, "uuid")) || !("__proto__" in this /* lame way to detect IE */)) { | 636 | if (this instanceof Element || !info.isInstance || !(VALUE in Object.getOwnPropertyDescriptor(this, "uuid")) || !(PROTO in this /* lame way to detect IE */)) { |
627 | //This is needed to workaround some bugs in Safari where re-defining uuid doesn't work for DOMWindow. | 637 | //This is needed to workaround some bugs in Safari where re-defining uuid doesn't work for DOMWindow. |
628 | this._uuid = uuid; | 638 | this._uuid = uuid; |
629 | } | 639 | } |
@@ -846,7 +856,7 @@ Object.defineProperty(Object.prototype, "setProperty", { | |||
846 | 856 | ||
847 | // For these mutation/addition/removal events, use the 'modify' attribute of this property's descriptor | 857 | // For these mutation/addition/removal events, use the 'modify' attribute of this property's descriptor |
848 | if (changeEvent && (changeEvent.currentTarget === lastObjectAtPath) && | 858 | if (changeEvent && (changeEvent.currentTarget === lastObjectAtPath) && |
849 | (modify = M.getPropertyAttribute(setObject, aPropertyPath, "modify"))) { | 859 | (modify = M.getPropertyAttribute(setObject, aPropertyPath, MODIFY))) { |
850 | modify.call(setObject, changeEvent.type, changeEvent.newValue, changeEvent.prevValue); | 860 | modify.call(setObject, changeEvent.type, changeEvent.newValue, changeEvent.prevValue); |
851 | } | 861 | } |
852 | } | 862 | } |