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 %AddProperty(object, key, f, attributes); | 31 %AddNamedProperty(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 %AddProperty(object, name, k, attributes); | 68 %AddNamedProperty(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 %AddProperty(prototype, fields[i], UNDEFINED, DONT_ENUM | DONT_DELETE); | 89 %AddNamedProperty(prototype, fields[i], |
| 90 UNDEFINED, DONT_ENUM | DONT_DELETE); |
90 } | 91 } |
91 } | 92 } |
92 for (var i = 0; i < methods.length; i += 2) { | 93 for (var i = 0; i < methods.length; i += 2) { |
93 var key = methods[i]; | 94 var key = methods[i]; |
94 var f = methods[i + 1]; | 95 var f = methods[i + 1]; |
95 %AddProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY); | 96 %AddNamedProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY); |
96 %SetNativeFlag(f); | 97 %SetNativeFlag(f); |
97 } | 98 } |
98 %SetPrototype(prototype, null); | 99 %SetPrototype(prototype, null); |
99 %ToFastProperties(prototype); | 100 %ToFastProperties(prototype); |
100 } | 101 } |
101 | 102 |
102 | 103 |
103 // ---------------------------------------------------------------------------- | 104 // ---------------------------------------------------------------------------- |
104 | 105 |
105 | 106 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 184 |
184 // ---------------------------------------------------------------------------- | 185 // ---------------------------------------------------------------------------- |
185 | 186 |
186 // Set up global object. | 187 // Set up global object. |
187 function SetUpGlobal() { | 188 function SetUpGlobal() { |
188 %CheckIsBootstrapping(); | 189 %CheckIsBootstrapping(); |
189 | 190 |
190 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; | 191 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY; |
191 | 192 |
192 // ECMA 262 - 15.1.1.1. | 193 // ECMA 262 - 15.1.1.1. |
193 %AddProperty(global, "NaN", NAN, attributes); | 194 %AddNamedProperty(global, "NaN", NAN, attributes); |
194 | 195 |
195 // ECMA-262 - 15.1.1.2. | 196 // ECMA-262 - 15.1.1.2. |
196 %AddProperty(global, "Infinity", INFINITY, attributes); | 197 %AddNamedProperty(global, "Infinity", INFINITY, attributes); |
197 | 198 |
198 // ECMA-262 - 15.1.1.3. | 199 // ECMA-262 - 15.1.1.3. |
199 %AddProperty(global, "undefined", UNDEFINED, attributes); | 200 %AddNamedProperty(global, "undefined", UNDEFINED, attributes); |
200 | 201 |
201 // Set up non-enumerable function on the global object. | 202 // Set up non-enumerable function on the global object. |
202 InstallFunctions(global, DONT_ENUM, $Array( | 203 InstallFunctions(global, DONT_ENUM, $Array( |
203 "isNaN", GlobalIsNaN, | 204 "isNaN", GlobalIsNaN, |
204 "isFinite", GlobalIsFinite, | 205 "isFinite", GlobalIsFinite, |
205 "parseInt", GlobalParseInt, | 206 "parseInt", GlobalParseInt, |
206 "parseFloat", GlobalParseFloat, | 207 "parseFloat", GlobalParseFloat, |
207 "eval", GlobalEval | 208 "eval", GlobalEval |
208 )); | 209 )); |
209 } | 210 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 configurable: desc.isConfigurable() }; | 380 configurable: desc.isConfigurable() }; |
380 } | 381 } |
381 | 382 |
382 | 383 |
383 // Harmony Proxies | 384 // Harmony Proxies |
384 function FromGenericPropertyDescriptor(desc) { | 385 function FromGenericPropertyDescriptor(desc) { |
385 if (IS_UNDEFINED(desc)) return desc; | 386 if (IS_UNDEFINED(desc)) return desc; |
386 var obj = new $Object(); | 387 var obj = new $Object(); |
387 | 388 |
388 if (desc.hasValue()) { | 389 if (desc.hasValue()) { |
389 %AddProperty(obj, "value", desc.getValue(), NONE); | 390 %AddNamedProperty(obj, "value", desc.getValue(), NONE); |
390 } | 391 } |
391 if (desc.hasWritable()) { | 392 if (desc.hasWritable()) { |
392 %AddProperty(obj, "writable", desc.isWritable(), NONE); | 393 %AddNamedProperty(obj, "writable", desc.isWritable(), NONE); |
393 } | 394 } |
394 if (desc.hasGetter()) { | 395 if (desc.hasGetter()) { |
395 %AddProperty(obj, "get", desc.getGet(), NONE); | 396 %AddNamedProperty(obj, "get", desc.getGet(), NONE); |
396 } | 397 } |
397 if (desc.hasSetter()) { | 398 if (desc.hasSetter()) { |
398 %AddProperty(obj, "set", desc.getSet(), NONE); | 399 %AddNamedProperty(obj, "set", desc.getSet(), NONE); |
399 } | 400 } |
400 if (desc.hasEnumerable()) { | 401 if (desc.hasEnumerable()) { |
401 %AddProperty(obj, "enumerable", desc.isEnumerable(), NONE); | 402 %AddNamedProperty(obj, "enumerable", desc.isEnumerable(), NONE); |
402 } | 403 } |
403 if (desc.hasConfigurable()) { | 404 if (desc.hasConfigurable()) { |
404 %AddProperty(obj, "configurable", desc.isConfigurable(), NONE); | 405 %AddNamedProperty(obj, "configurable", desc.isConfigurable(), NONE); |
405 } | 406 } |
406 return obj; | 407 return obj; |
407 } | 408 } |
408 | 409 |
409 | 410 |
410 // ES5 8.10.5. | 411 // ES5 8.10.5. |
411 function ToPropertyDescriptor(obj) { | 412 function ToPropertyDescriptor(obj) { |
412 if (!IS_SPEC_OBJECT(obj)) { | 413 if (!IS_SPEC_OBJECT(obj)) { |
413 throw MakeTypeError("property_desc_object", [obj]); | 414 throw MakeTypeError("property_desc_object", [obj]); |
414 } | 415 } |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 | 1389 |
1389 // ---------------------------------------------------------------------------- | 1390 // ---------------------------------------------------------------------------- |
1390 // Object | 1391 // Object |
1391 | 1392 |
1392 function SetUpObject() { | 1393 function SetUpObject() { |
1393 %CheckIsBootstrapping(); | 1394 %CheckIsBootstrapping(); |
1394 | 1395 |
1395 %SetNativeFlag($Object); | 1396 %SetNativeFlag($Object); |
1396 %SetCode($Object, ObjectConstructor); | 1397 %SetCode($Object, ObjectConstructor); |
1397 | 1398 |
1398 %AddProperty($Object.prototype, "constructor", $Object, DONT_ENUM); | 1399 %AddNamedProperty($Object.prototype, "constructor", $Object, DONT_ENUM); |
1399 | 1400 |
1400 // Set up non-enumerable functions on the Object.prototype object. | 1401 // Set up non-enumerable functions on the Object.prototype object. |
1401 InstallFunctions($Object.prototype, DONT_ENUM, $Array( | 1402 InstallFunctions($Object.prototype, DONT_ENUM, $Array( |
1402 "toString", ObjectToString, | 1403 "toString", ObjectToString, |
1403 "toLocaleString", ObjectToLocaleString, | 1404 "toLocaleString", ObjectToLocaleString, |
1404 "valueOf", ObjectValueOf, | 1405 "valueOf", ObjectValueOf, |
1405 "hasOwnProperty", ObjectHasOwnProperty, | 1406 "hasOwnProperty", ObjectHasOwnProperty, |
1406 "isPrototypeOf", ObjectIsPrototypeOf, | 1407 "isPrototypeOf", ObjectIsPrototypeOf, |
1407 "propertyIsEnumerable", ObjectPropertyIsEnumerable, | 1408 "propertyIsEnumerable", ObjectPropertyIsEnumerable, |
1408 "__defineGetter__", ObjectDefineGetter, | 1409 "__defineGetter__", ObjectDefineGetter, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 } | 1476 } |
1476 | 1477 |
1477 | 1478 |
1478 // ---------------------------------------------------------------------------- | 1479 // ---------------------------------------------------------------------------- |
1479 | 1480 |
1480 function SetUpBoolean () { | 1481 function SetUpBoolean () { |
1481 %CheckIsBootstrapping(); | 1482 %CheckIsBootstrapping(); |
1482 | 1483 |
1483 %SetCode($Boolean, BooleanConstructor); | 1484 %SetCode($Boolean, BooleanConstructor); |
1484 %FunctionSetPrototype($Boolean, new $Boolean(false)); | 1485 %FunctionSetPrototype($Boolean, new $Boolean(false)); |
1485 %AddProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); | 1486 %AddNamedProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); |
1486 | 1487 |
1487 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( | 1488 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( |
1488 "toString", BooleanToString, | 1489 "toString", BooleanToString, |
1489 "valueOf", BooleanValueOf | 1490 "valueOf", BooleanValueOf |
1490 )); | 1491 )); |
1491 } | 1492 } |
1492 | 1493 |
1493 SetUpBoolean(); | 1494 SetUpBoolean(); |
1494 | 1495 |
1495 | 1496 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 // ---------------------------------------------------------------------------- | 1659 // ---------------------------------------------------------------------------- |
1659 | 1660 |
1660 function SetUpNumber() { | 1661 function SetUpNumber() { |
1661 %CheckIsBootstrapping(); | 1662 %CheckIsBootstrapping(); |
1662 | 1663 |
1663 %SetCode($Number, NumberConstructor); | 1664 %SetCode($Number, NumberConstructor); |
1664 %FunctionSetPrototype($Number, new $Number(0)); | 1665 %FunctionSetPrototype($Number, new $Number(0)); |
1665 | 1666 |
1666 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); | 1667 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); |
1667 // Set up the constructor property on the Number prototype object. | 1668 // Set up the constructor property on the Number prototype object. |
1668 %AddProperty($Number.prototype, "constructor", $Number, DONT_ENUM); | 1669 %AddNamedProperty($Number.prototype, "constructor", $Number, DONT_ENUM); |
1669 | 1670 |
1670 InstallConstants($Number, $Array( | 1671 InstallConstants($Number, $Array( |
1671 // ECMA-262 section 15.7.3.1. | 1672 // ECMA-262 section 15.7.3.1. |
1672 "MAX_VALUE", 1.7976931348623157e+308, | 1673 "MAX_VALUE", 1.7976931348623157e+308, |
1673 // ECMA-262 section 15.7.3.2. | 1674 // ECMA-262 section 15.7.3.2. |
1674 "MIN_VALUE", 5e-324, | 1675 "MIN_VALUE", 5e-324, |
1675 // ECMA-262 section 15.7.3.3. | 1676 // ECMA-262 section 15.7.3.3. |
1676 "NaN", NAN, | 1677 "NaN", NAN, |
1677 // ECMA-262 section 15.7.3.4. | 1678 // ECMA-262 section 15.7.3.4. |
1678 "NEGATIVE_INFINITY", -INFINITY, | 1679 "NEGATIVE_INFINITY", -INFINITY, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1841 return f; | 1842 return f; |
1842 } | 1843 } |
1843 | 1844 |
1844 | 1845 |
1845 // ---------------------------------------------------------------------------- | 1846 // ---------------------------------------------------------------------------- |
1846 | 1847 |
1847 function SetUpFunction() { | 1848 function SetUpFunction() { |
1848 %CheckIsBootstrapping(); | 1849 %CheckIsBootstrapping(); |
1849 | 1850 |
1850 %SetCode($Function, FunctionConstructor); | 1851 %SetCode($Function, FunctionConstructor); |
1851 %AddProperty($Function.prototype, "constructor", $Function, DONT_ENUM); | 1852 %AddNamedProperty($Function.prototype, "constructor", $Function, DONT_ENUM); |
1852 | 1853 |
1853 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1854 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1854 "bind", FunctionBind, | 1855 "bind", FunctionBind, |
1855 "toString", FunctionToString | 1856 "toString", FunctionToString |
1856 )); | 1857 )); |
1857 } | 1858 } |
1858 | 1859 |
1859 SetUpFunction(); | 1860 SetUpFunction(); |
OLD | NEW |