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 %DefineProperty(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); |
(...skipping 16 matching lines...) Expand all Loading... |
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 %DefineProperty(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 %DefineProperty(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 %DefineProperty(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 %DefineProperty(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 %DefineProperty(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 %DefineProperty(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 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1390 | 1390 |
1391 // ---------------------------------------------------------------------------- | 1391 // ---------------------------------------------------------------------------- |
1392 // Object | 1392 // Object |
1393 | 1393 |
1394 function SetUpObject() { | 1394 function SetUpObject() { |
1395 %CheckIsBootstrapping(); | 1395 %CheckIsBootstrapping(); |
1396 | 1396 |
1397 %SetNativeFlag($Object); | 1397 %SetNativeFlag($Object); |
1398 %SetCode($Object, ObjectConstructor); | 1398 %SetCode($Object, ObjectConstructor); |
1399 | 1399 |
1400 %SetProperty($Object.prototype, "constructor", $Object, DONT_ENUM); | 1400 %DefineProperty($Object.prototype, "constructor", $Object, DONT_ENUM); |
1401 | 1401 |
1402 // Set up non-enumerable functions on the Object.prototype object. | 1402 // Set up non-enumerable functions on the Object.prototype object. |
1403 InstallFunctions($Object.prototype, DONT_ENUM, $Array( | 1403 InstallFunctions($Object.prototype, DONT_ENUM, $Array( |
1404 "toString", ObjectToString, | 1404 "toString", ObjectToString, |
1405 "toLocaleString", ObjectToLocaleString, | 1405 "toLocaleString", ObjectToLocaleString, |
1406 "valueOf", ObjectValueOf, | 1406 "valueOf", ObjectValueOf, |
1407 "hasOwnProperty", ObjectHasOwnProperty, | 1407 "hasOwnProperty", ObjectHasOwnProperty, |
1408 "isPrototypeOf", ObjectIsPrototypeOf, | 1408 "isPrototypeOf", ObjectIsPrototypeOf, |
1409 "propertyIsEnumerable", ObjectPropertyIsEnumerable, | 1409 "propertyIsEnumerable", ObjectPropertyIsEnumerable, |
1410 "__defineGetter__", ObjectDefineGetter, | 1410 "__defineGetter__", ObjectDefineGetter, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 } | 1477 } |
1478 | 1478 |
1479 | 1479 |
1480 // ---------------------------------------------------------------------------- | 1480 // ---------------------------------------------------------------------------- |
1481 | 1481 |
1482 function SetUpBoolean () { | 1482 function SetUpBoolean () { |
1483 %CheckIsBootstrapping(); | 1483 %CheckIsBootstrapping(); |
1484 | 1484 |
1485 %SetCode($Boolean, BooleanConstructor); | 1485 %SetCode($Boolean, BooleanConstructor); |
1486 %FunctionSetPrototype($Boolean, new $Boolean(false)); | 1486 %FunctionSetPrototype($Boolean, new $Boolean(false)); |
1487 %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); | 1487 %DefineProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); |
1488 | 1488 |
1489 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( | 1489 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( |
1490 "toString", BooleanToString, | 1490 "toString", BooleanToString, |
1491 "valueOf", BooleanValueOf | 1491 "valueOf", BooleanValueOf |
1492 )); | 1492 )); |
1493 } | 1493 } |
1494 | 1494 |
1495 SetUpBoolean(); | 1495 SetUpBoolean(); |
1496 | 1496 |
1497 | 1497 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1660 // ---------------------------------------------------------------------------- | 1660 // ---------------------------------------------------------------------------- |
1661 | 1661 |
1662 function SetUpNumber() { | 1662 function SetUpNumber() { |
1663 %CheckIsBootstrapping(); | 1663 %CheckIsBootstrapping(); |
1664 | 1664 |
1665 %SetCode($Number, NumberConstructor); | 1665 %SetCode($Number, NumberConstructor); |
1666 %FunctionSetPrototype($Number, new $Number(0)); | 1666 %FunctionSetPrototype($Number, new $Number(0)); |
1667 | 1667 |
1668 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); | 1668 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); |
1669 // Set up the constructor property on the Number prototype object. | 1669 // Set up the constructor property on the Number prototype object. |
1670 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); | 1670 %DefineProperty($Number.prototype, "constructor", $Number, DONT_ENUM); |
1671 | 1671 |
1672 InstallConstants($Number, $Array( | 1672 InstallConstants($Number, $Array( |
1673 // ECMA-262 section 15.7.3.1. | 1673 // ECMA-262 section 15.7.3.1. |
1674 "MAX_VALUE", 1.7976931348623157e+308, | 1674 "MAX_VALUE", 1.7976931348623157e+308, |
1675 // ECMA-262 section 15.7.3.2. | 1675 // ECMA-262 section 15.7.3.2. |
1676 "MIN_VALUE", 5e-324, | 1676 "MIN_VALUE", 5e-324, |
1677 // ECMA-262 section 15.7.3.3. | 1677 // ECMA-262 section 15.7.3.3. |
1678 "NaN", NAN, | 1678 "NaN", NAN, |
1679 // ECMA-262 section 15.7.3.4. | 1679 // ECMA-262 section 15.7.3.4. |
1680 "NEGATIVE_INFINITY", -INFINITY, | 1680 "NEGATIVE_INFINITY", -INFINITY, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1843 return f; | 1843 return f; |
1844 } | 1844 } |
1845 | 1845 |
1846 | 1846 |
1847 // ---------------------------------------------------------------------------- | 1847 // ---------------------------------------------------------------------------- |
1848 | 1848 |
1849 function SetUpFunction() { | 1849 function SetUpFunction() { |
1850 %CheckIsBootstrapping(); | 1850 %CheckIsBootstrapping(); |
1851 | 1851 |
1852 %SetCode($Function, FunctionConstructor); | 1852 %SetCode($Function, FunctionConstructor); |
1853 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); | 1853 %DefineProperty($Function.prototype, "constructor", $Function, DONT_ENUM); |
1854 | 1854 |
1855 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1855 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1856 "bind", FunctionBind, | 1856 "bind", FunctionBind, |
1857 "toString", FunctionToString | 1857 "toString", FunctionToString |
1858 )); | 1858 )); |
1859 } | 1859 } |
1860 | 1860 |
1861 SetUpFunction(); | 1861 SetUpFunction(); |
OLD | NEW |