OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file relies on the fact that the following declarations have been made | 5 // This file relies on the fact that the following declarations have been made |
6 // in runtime.js: | 6 // in runtime.js: |
7 // var $Object = global.Object; | 7 // var $Object = global.Object; |
8 // var $Boolean = global.Boolean; | 8 // var $Boolean = global.Boolean; |
9 // var $Number = global.Number; | 9 // var $Number = global.Number; |
10 // var $Function = global.Function; | 10 // var $Function = global.Function; |
(...skipping 10 matching lines...) Expand all Loading... |
21 // Helper function used to install functions on objects. | 21 // Helper function used to install functions on objects. |
22 function InstallFunctions(object, attributes, functions) { | 22 function InstallFunctions(object, attributes, functions) { |
23 if (functions.length >= 8) { | 23 if (functions.length >= 8) { |
24 %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1); | 24 %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1); |
25 } | 25 } |
26 for (var i = 0; i < functions.length; i += 2) { | 26 for (var i = 0; i < functions.length; i += 2) { |
27 var key = functions[i]; | 27 var key = functions[i]; |
28 var f = functions[i + 1]; | 28 var f = functions[i + 1]; |
29 %FunctionSetName(f, key); | 29 %FunctionSetName(f, key); |
30 %FunctionRemovePrototype(f); | 30 %FunctionRemovePrototype(f); |
31 %SetProperty(object, key, f, attributes); | 31 %AddProperty(object, key, f, attributes); |
32 %SetNativeFlag(f); | 32 %SetNativeFlag(f); |
33 } | 33 } |
34 %ToFastProperties(object); | 34 %ToFastProperties(object); |
35 } | 35 } |
36 | 36 |
37 | 37 |
38 // Helper function to install a getter-only accessor property. | 38 // Helper function to install a getter-only accessor property. |
39 function InstallGetter(object, name, getter) { | 39 function InstallGetter(object, name, getter) { |
40 %FunctionSetName(getter, name); | 40 %FunctionSetName(getter, name); |
41 %FunctionRemovePrototype(getter); | 41 %FunctionRemovePrototype(getter); |
42 %DefineOrRedefineAccessorProperty(object, name, getter, null, DONT_ENUM); | 42 %DefineAccessorPropertyUnchecked(object, name, getter, null, DONT_ENUM); |
43 %SetNativeFlag(getter); | 43 %SetNativeFlag(getter); |
44 } | 44 } |
45 | 45 |
46 | 46 |
47 // Helper function to install a getter/setter accessor property. | 47 // Helper function to install a getter/setter accessor property. |
48 function InstallGetterSetter(object, name, getter, setter) { | 48 function InstallGetterSetter(object, name, getter, setter) { |
49 %FunctionSetName(getter, name); | 49 %FunctionSetName(getter, name); |
50 %FunctionSetName(setter, name); | 50 %FunctionSetName(setter, name); |
51 %FunctionRemovePrototype(getter); | 51 %FunctionRemovePrototype(getter); |
52 %FunctionRemovePrototype(setter); | 52 %FunctionRemovePrototype(setter); |
53 %DefineOrRedefineAccessorProperty(object, name, getter, setter, DONT_ENUM); | 53 %DefineAccessorPropertyUnchecked(object, name, getter, setter, DONT_ENUM); |
54 %SetNativeFlag(getter); | 54 %SetNativeFlag(getter); |
55 %SetNativeFlag(setter); | 55 %SetNativeFlag(setter); |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 // Helper function for installing constant properties on objects. | 59 // Helper function for installing constant properties on objects. |
60 function InstallConstants(object, constants) { | 60 function InstallConstants(object, constants) { |
61 if (constants.length >= 4) { | 61 if (constants.length >= 4) { |
62 %OptimizeObjectForAddingMultipleProperties(object, constants.length >> 1); | 62 %OptimizeObjectForAddingMultipleProperties(object, constants.length >> 1); |
63 } | 63 } |
64 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; | 64 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; |
65 for (var i = 0; i < constants.length; i += 2) { | 65 for (var i = 0; i < constants.length; i += 2) { |
66 var name = constants[i]; | 66 var name = constants[i]; |
67 var k = constants[i + 1]; | 67 var k = constants[i + 1]; |
68 %SetProperty(object, name, k, attributes); | 68 %AddProperty(object, name, k, attributes); |
69 } | 69 } |
70 %ToFastProperties(object); | 70 %ToFastProperties(object); |
71 } | 71 } |
72 | 72 |
73 | 73 |
74 // Prevents changes to the prototype of a built-in function. | 74 // Prevents changes to the prototype of a built-in function. |
75 // The "prototype" property of the function object is made non-configurable, | 75 // The "prototype" property of the function object is made non-configurable, |
76 // and the prototype object is made non-extensible. The latter prevents | 76 // and the prototype object is made non-extensible. The latter prevents |
77 // changing the __proto__ property. | 77 // changing the __proto__ property. |
78 function SetUpLockedPrototype(constructor, fields, methods) { | 78 function SetUpLockedPrototype(constructor, fields, methods) { |
79 %CheckIsBootstrapping(); | 79 %CheckIsBootstrapping(); |
80 var prototype = constructor.prototype; | 80 var prototype = constructor.prototype; |
81 // Install functions first, because this function is used to initialize | 81 // Install functions first, because this function is used to initialize |
82 // PropertyDescriptor itself. | 82 // PropertyDescriptor itself. |
83 var property_count = (methods.length >> 1) + (fields ? fields.length : 0); | 83 var property_count = (methods.length >> 1) + (fields ? fields.length : 0); |
84 if (property_count >= 4) { | 84 if (property_count >= 4) { |
85 %OptimizeObjectForAddingMultipleProperties(prototype, property_count); | 85 %OptimizeObjectForAddingMultipleProperties(prototype, property_count); |
86 } | 86 } |
87 if (fields) { | 87 if (fields) { |
88 for (var i = 0; i < fields.length; i++) { | 88 for (var i = 0; i < fields.length; i++) { |
89 %SetProperty(prototype, fields[i], UNDEFINED, DONT_ENUM | DONT_DELETE); | 89 %AddProperty(prototype, fields[i], UNDEFINED, DONT_ENUM | DONT_DELETE); |
90 } | 90 } |
91 } | 91 } |
92 for (var i = 0; i < methods.length; i += 2) { | 92 for (var i = 0; i < methods.length; i += 2) { |
93 var key = methods[i]; | 93 var key = methods[i]; |
94 var f = methods[i + 1]; | 94 var f = methods[i + 1]; |
95 %SetProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY); | 95 %AddProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY); |
96 %SetNativeFlag(f); | 96 %SetNativeFlag(f); |
97 } | 97 } |
98 %SetPrototype(prototype, null); | 98 %SetPrototype(prototype, null); |
99 %ToFastProperties(prototype); | 99 %ToFastProperties(prototype); |
100 } | 100 } |
101 | 101 |
102 | 102 |
103 // ---------------------------------------------------------------------------- | 103 // ---------------------------------------------------------------------------- |
104 | 104 |
105 | 105 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 183 |
184 // ---------------------------------------------------------------------------- | 184 // ---------------------------------------------------------------------------- |
185 | 185 |
186 // Set up global object. | 186 // Set up global object. |
187 function SetUpGlobal() { | 187 function SetUpGlobal() { |
188 %CheckIsBootstrapping(); | 188 %CheckIsBootstrapping(); |
189 | 189 |
190 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; | 190 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; |
191 | 191 |
192 // ECMA 262 - 15.1.1.1. | 192 // ECMA 262 - 15.1.1.1. |
193 %SetProperty(global, "NaN", NAN, attributes); | 193 %AddProperty(global, "NaN", NAN, attributes); |
194 | 194 |
195 // ECMA-262 - 15.1.1.2. | 195 // ECMA-262 - 15.1.1.2. |
196 %SetProperty(global, "Infinity", INFINITY, attributes); | 196 %AddProperty(global, "Infinity", INFINITY, attributes); |
197 | 197 |
198 // ECMA-262 - 15.1.1.3. | 198 // ECMA-262 - 15.1.1.3. |
199 %SetProperty(global, "undefined", UNDEFINED, attributes); | 199 %AddProperty(global, "undefined", UNDEFINED, attributes); |
200 | 200 |
201 // Set up non-enumerable function on the global object. | 201 // Set up non-enumerable function on the global object. |
202 InstallFunctions(global, DONT_ENUM, $Array( | 202 InstallFunctions(global, DONT_ENUM, $Array( |
203 "isNaN", GlobalIsNaN, | 203 "isNaN", GlobalIsNaN, |
204 "isFinite", GlobalIsFinite, | 204 "isFinite", GlobalIsFinite, |
205 "parseInt", GlobalParseInt, | 205 "parseInt", GlobalParseInt, |
206 "parseFloat", GlobalParseFloat, | 206 "parseFloat", GlobalParseFloat, |
207 "eval", GlobalEval | 207 "eval", GlobalEval |
208 )); | 208 )); |
209 } | 209 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 configurable: desc.isConfigurable() }; | 379 configurable: desc.isConfigurable() }; |
380 } | 380 } |
381 | 381 |
382 | 382 |
383 // Harmony Proxies | 383 // Harmony Proxies |
384 function FromGenericPropertyDescriptor(desc) { | 384 function FromGenericPropertyDescriptor(desc) { |
385 if (IS_UNDEFINED(desc)) return desc; | 385 if (IS_UNDEFINED(desc)) return desc; |
386 var obj = new $Object(); | 386 var obj = new $Object(); |
387 | 387 |
388 if (desc.hasValue()) { | 388 if (desc.hasValue()) { |
389 %IgnoreAttributesAndSetProperty(obj, "value", desc.getValue(), NONE); | 389 %AddProperty(obj, "value", desc.getValue(), NONE); |
390 } | 390 } |
391 if (desc.hasWritable()) { | 391 if (desc.hasWritable()) { |
392 %IgnoreAttributesAndSetProperty(obj, "writable", desc.isWritable(), NONE); | 392 %AddProperty(obj, "writable", desc.isWritable(), NONE); |
393 } | 393 } |
394 if (desc.hasGetter()) { | 394 if (desc.hasGetter()) { |
395 %IgnoreAttributesAndSetProperty(obj, "get", desc.getGet(), NONE); | 395 %AddProperty(obj, "get", desc.getGet(), NONE); |
396 } | 396 } |
397 if (desc.hasSetter()) { | 397 if (desc.hasSetter()) { |
398 %IgnoreAttributesAndSetProperty(obj, "set", desc.getSet(), NONE); | 398 %AddProperty(obj, "set", desc.getSet(), NONE); |
399 } | 399 } |
400 if (desc.hasEnumerable()) { | 400 if (desc.hasEnumerable()) { |
401 %IgnoreAttributesAndSetProperty(obj, "enumerable", | 401 %AddProperty(obj, "enumerable", desc.isEnumerable(), NONE); |
402 desc.isEnumerable(), NONE); | |
403 } | 402 } |
404 if (desc.hasConfigurable()) { | 403 if (desc.hasConfigurable()) { |
405 %IgnoreAttributesAndSetProperty(obj, "configurable", | 404 %AddProperty(obj, "configurable", desc.isConfigurable(), NONE); |
406 desc.isConfigurable(), NONE); | |
407 } | 405 } |
408 return obj; | 406 return obj; |
409 } | 407 } |
410 | 408 |
411 | 409 |
412 // ES5 8.10.5. | 410 // ES5 8.10.5. |
413 function ToPropertyDescriptor(obj) { | 411 function ToPropertyDescriptor(obj) { |
414 if (!IS_SPEC_OBJECT(obj)) { | 412 if (!IS_SPEC_OBJECT(obj)) { |
415 throw MakeTypeError("property_desc_object", [obj]); | 413 throw MakeTypeError("property_desc_object", [obj]); |
416 } | 414 } |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 flag |= READ_ONLY; | 824 flag |= READ_ONLY; |
827 } | 825 } |
828 | 826 |
829 var value = UNDEFINED; // Default value is undefined. | 827 var value = UNDEFINED; // Default value is undefined. |
830 if (desc.hasValue()) { | 828 if (desc.hasValue()) { |
831 value = desc.getValue(); | 829 value = desc.getValue(); |
832 } else if (!IS_UNDEFINED(current) && IsDataDescriptor(current)) { | 830 } else if (!IS_UNDEFINED(current) && IsDataDescriptor(current)) { |
833 value = current.getValue(); | 831 value = current.getValue(); |
834 } | 832 } |
835 | 833 |
836 %DefineOrRedefineDataProperty(obj, p, value, flag); | 834 %DefineDataPropertyUnchecked(obj, p, value, flag); |
837 } else { | 835 } else { |
838 // There are 3 cases that lead here: | 836 // There are 3 cases that lead here: |
839 // Step 4b - defining a new accessor property. | 837 // Step 4b - defining a new accessor property. |
840 // Steps 9c & 12 - replacing an existing data property with an accessor | 838 // Steps 9c & 12 - replacing an existing data property with an accessor |
841 // property. | 839 // property. |
842 // Step 12 - updating an existing accessor property with an accessor | 840 // Step 12 - updating an existing accessor property with an accessor |
843 // descriptor. | 841 // descriptor. |
844 var getter = desc.hasGetter() ? desc.getGet() : null; | 842 var getter = desc.hasGetter() ? desc.getGet() : null; |
845 var setter = desc.hasSetter() ? desc.getSet() : null; | 843 var setter = desc.hasSetter() ? desc.getSet() : null; |
846 %DefineOrRedefineAccessorProperty(obj, p, getter, setter, flag); | 844 %DefineAccessorPropertyUnchecked(obj, p, getter, setter, flag); |
847 } | 845 } |
848 return true; | 846 return true; |
849 } | 847 } |
850 | 848 |
851 | 849 |
852 // ES5 section 15.4.5.1. | 850 // ES5 section 15.4.5.1. |
853 function DefineArrayProperty(obj, p, desc, should_throw) { | 851 function DefineArrayProperty(obj, p, desc, should_throw) { |
854 // Note that the length of an array is not actually stored as part of the | 852 // Note that the length of an array is not actually stored as part of the |
855 // property, hence we use generated code throughout this function instead of | 853 // property, hence we use generated code throughout this function instead of |
856 // DefineObjectProperty() to modify its value. | 854 // DefineObjectProperty() to modify its value. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 } | 892 } |
895 if (!Delete(obj, index, false)) { | 893 if (!Delete(obj, index, false)) { |
896 new_length = length + 1; | 894 new_length = length + 1; |
897 threw = true; | 895 threw = true; |
898 break; | 896 break; |
899 } | 897 } |
900 } | 898 } |
901 // Make sure the below call to DefineObjectProperty() doesn't overwrite | 899 // Make sure the below call to DefineObjectProperty() doesn't overwrite |
902 // any magic "length" property by removing the value. | 900 // any magic "length" property by removing the value. |
903 // TODO(mstarzinger): This hack should be removed once we have addressed the | 901 // TODO(mstarzinger): This hack should be removed once we have addressed the |
904 // respective TODO in Runtime_DefineOrRedefineDataProperty. | 902 // respective TODO in Runtime_DefineDataPropertyUnchecked. |
905 // For the time being, we need a hack to prevent Object.observe from | 903 // For the time being, we need a hack to prevent Object.observe from |
906 // generating two change records. | 904 // generating two change records. |
907 obj.length = new_length; | 905 obj.length = new_length; |
908 desc.value_ = UNDEFINED; | 906 desc.value_ = UNDEFINED; |
909 desc.hasValue_ = false; | 907 desc.hasValue_ = false; |
910 threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw; | 908 threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw; |
911 if (emit_splice) { | 909 if (emit_splice) { |
912 EndPerformSplice(obj); | 910 EndPerformSplice(obj); |
913 EnqueueSpliceRecord(obj, | 911 EnqueueSpliceRecord(obj, |
914 new_length < old_length ? new_length : old_length, | 912 new_length < old_length ? new_length : old_length, |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1390 | 1388 |
1391 // ---------------------------------------------------------------------------- | 1389 // ---------------------------------------------------------------------------- |
1392 // Object | 1390 // Object |
1393 | 1391 |
1394 function SetUpObject() { | 1392 function SetUpObject() { |
1395 %CheckIsBootstrapping(); | 1393 %CheckIsBootstrapping(); |
1396 | 1394 |
1397 %SetNativeFlag($Object); | 1395 %SetNativeFlag($Object); |
1398 %SetCode($Object, ObjectConstructor); | 1396 %SetCode($Object, ObjectConstructor); |
1399 | 1397 |
1400 %SetProperty($Object.prototype, "constructor", $Object, DONT_ENUM); | 1398 %AddProperty($Object.prototype, "constructor", $Object, DONT_ENUM); |
1401 | 1399 |
1402 // Set up non-enumerable functions on the Object.prototype object. | 1400 // Set up non-enumerable functions on the Object.prototype object. |
1403 InstallFunctions($Object.prototype, DONT_ENUM, $Array( | 1401 InstallFunctions($Object.prototype, DONT_ENUM, $Array( |
1404 "toString", ObjectToString, | 1402 "toString", ObjectToString, |
1405 "toLocaleString", ObjectToLocaleString, | 1403 "toLocaleString", ObjectToLocaleString, |
1406 "valueOf", ObjectValueOf, | 1404 "valueOf", ObjectValueOf, |
1407 "hasOwnProperty", ObjectHasOwnProperty, | 1405 "hasOwnProperty", ObjectHasOwnProperty, |
1408 "isPrototypeOf", ObjectIsPrototypeOf, | 1406 "isPrototypeOf", ObjectIsPrototypeOf, |
1409 "propertyIsEnumerable", ObjectPropertyIsEnumerable, | 1407 "propertyIsEnumerable", ObjectPropertyIsEnumerable, |
1410 "__defineGetter__", ObjectDefineGetter, | 1408 "__defineGetter__", ObjectDefineGetter, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 } | 1475 } |
1478 | 1476 |
1479 | 1477 |
1480 // ---------------------------------------------------------------------------- | 1478 // ---------------------------------------------------------------------------- |
1481 | 1479 |
1482 function SetUpBoolean () { | 1480 function SetUpBoolean () { |
1483 %CheckIsBootstrapping(); | 1481 %CheckIsBootstrapping(); |
1484 | 1482 |
1485 %SetCode($Boolean, BooleanConstructor); | 1483 %SetCode($Boolean, BooleanConstructor); |
1486 %FunctionSetPrototype($Boolean, new $Boolean(false)); | 1484 %FunctionSetPrototype($Boolean, new $Boolean(false)); |
1487 %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); | 1485 %AddProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); |
1488 | 1486 |
1489 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( | 1487 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( |
1490 "toString", BooleanToString, | 1488 "toString", BooleanToString, |
1491 "valueOf", BooleanValueOf | 1489 "valueOf", BooleanValueOf |
1492 )); | 1490 )); |
1493 } | 1491 } |
1494 | 1492 |
1495 SetUpBoolean(); | 1493 SetUpBoolean(); |
1496 | 1494 |
1497 | 1495 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1660 // ---------------------------------------------------------------------------- | 1658 // ---------------------------------------------------------------------------- |
1661 | 1659 |
1662 function SetUpNumber() { | 1660 function SetUpNumber() { |
1663 %CheckIsBootstrapping(); | 1661 %CheckIsBootstrapping(); |
1664 | 1662 |
1665 %SetCode($Number, NumberConstructor); | 1663 %SetCode($Number, NumberConstructor); |
1666 %FunctionSetPrototype($Number, new $Number(0)); | 1664 %FunctionSetPrototype($Number, new $Number(0)); |
1667 | 1665 |
1668 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); | 1666 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); |
1669 // Set up the constructor property on the Number prototype object. | 1667 // Set up the constructor property on the Number prototype object. |
1670 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); | 1668 %AddProperty($Number.prototype, "constructor", $Number, DONT_ENUM); |
1671 | 1669 |
1672 InstallConstants($Number, $Array( | 1670 InstallConstants($Number, $Array( |
1673 // ECMA-262 section 15.7.3.1. | 1671 // ECMA-262 section 15.7.3.1. |
1674 "MAX_VALUE", 1.7976931348623157e+308, | 1672 "MAX_VALUE", 1.7976931348623157e+308, |
1675 // ECMA-262 section 15.7.3.2. | 1673 // ECMA-262 section 15.7.3.2. |
1676 "MIN_VALUE", 5e-324, | 1674 "MIN_VALUE", 5e-324, |
1677 // ECMA-262 section 15.7.3.3. | 1675 // ECMA-262 section 15.7.3.3. |
1678 "NaN", NAN, | 1676 "NaN", NAN, |
1679 // ECMA-262 section 15.7.3.4. | 1677 // ECMA-262 section 15.7.3.4. |
1680 "NEGATIVE_INFINITY", -INFINITY, | 1678 "NEGATIVE_INFINITY", -INFINITY, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1843 return f; | 1841 return f; |
1844 } | 1842 } |
1845 | 1843 |
1846 | 1844 |
1847 // ---------------------------------------------------------------------------- | 1845 // ---------------------------------------------------------------------------- |
1848 | 1846 |
1849 function SetUpFunction() { | 1847 function SetUpFunction() { |
1850 %CheckIsBootstrapping(); | 1848 %CheckIsBootstrapping(); |
1851 | 1849 |
1852 %SetCode($Function, FunctionConstructor); | 1850 %SetCode($Function, FunctionConstructor); |
1853 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); | 1851 %AddProperty($Function.prototype, "constructor", $Function, DONT_ENUM); |
1854 | 1852 |
1855 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1853 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1856 "bind", FunctionBind, | 1854 "bind", FunctionBind, |
1857 "toString", FunctionToString | 1855 "toString", FunctionToString |
1858 )); | 1856 )); |
1859 } | 1857 } |
1860 | 1858 |
1861 SetUpFunction(); | 1859 SetUpFunction(); |
OLD | NEW |