Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/v8natives.js

Issue 14125004: Move global code for builtins into setup functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Even more. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/proxy.js ('K') | « src/uri.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // This file relies on the fact that the following declarations have been made 28 // This file relies on the fact that the following declarations have been made
29 //
30 // in runtime.js: 29 // in runtime.js:
31 // var $Object = global.Object; 30 // var $Object = global.Object;
32 // var $Boolean = global.Boolean; 31 // var $Boolean = global.Boolean;
33 // var $Number = global.Number; 32 // var $Number = global.Number;
34 // var $Function = global.Function; 33 // var $Function = global.Function;
35 // var $Array = global.Array; 34 // var $Array = global.Array;
36 // var $NaN = 0/0; 35 // var $NaN = 0/0;
37 // 36 //
38 // in math.js: 37 // in math.js:
39 // var $floor = MathFloor 38 // var $floor = MathFloor
40 39
41 var $isNaN = GlobalIsNaN; 40 var $isNaN = GlobalIsNaN;
42 var $isFinite = GlobalIsFinite; 41 var $isFinite = GlobalIsFinite;
43 42
44 // ---------------------------------------------------------------------------- 43 // ----------------------------------------------------------------------------
45 44
46
47 // Helper function used to install functions on objects. 45 // Helper function used to install functions on objects.
48 function InstallFunctions(object, attributes, functions) { 46 function InstallFunctions(object, attributes, functions) {
49 if (functions.length >= 8) { 47 if (functions.length >= 8) {
50 %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1); 48 %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1);
51 } 49 }
52 for (var i = 0; i < functions.length; i += 2) { 50 for (var i = 0; i < functions.length; i += 2) {
53 var key = functions[i]; 51 var key = functions[i];
54 var f = functions[i + 1]; 52 var f = functions[i + 1];
55 %FunctionSetName(f, key); 53 %FunctionSetName(f, key);
56 %FunctionRemovePrototype(f); 54 %FunctionRemovePrototype(f);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 189
192 return %_CallFunction(global_receiver, f); 190 return %_CallFunction(global_receiver, f);
193 } 191 }
194 192
195 193
196 // ---------------------------------------------------------------------------- 194 // ----------------------------------------------------------------------------
197 195
198 // Set up global object. 196 // Set up global object.
199 function SetUpGlobal() { 197 function SetUpGlobal() {
200 %CheckIsBootstrapping(); 198 %CheckIsBootstrapping();
199
201 // ECMA 262 - 15.1.1.1. 200 // ECMA 262 - 15.1.1.1.
202 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); 201 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY);
203 202
204 // ECMA-262 - 15.1.1.2. 203 // ECMA-262 - 15.1.1.2.
205 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE | READ_ONLY); 204 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE | READ_ONLY);
206 205
207 // ECMA-262 - 15.1.1.3. 206 // ECMA-262 - 15.1.1.3.
208 %SetProperty(global, "undefined", void 0, 207 %SetProperty(global, "undefined", void 0,
209 DONT_ENUM | DONT_DELETE | READ_ONLY); 208 DONT_ENUM | DONT_DELETE | READ_ONLY);
210 209
211 // Set up non-enumerable function on the global object. 210 // Set up non-enumerable function on the global object.
212 InstallFunctions(global, DONT_ENUM, $Array( 211 InstallFunctions(global, DONT_ENUM, $Array(
213 "isNaN", GlobalIsNaN, 212 "isNaN", GlobalIsNaN,
214 "isFinite", GlobalIsFinite, 213 "isFinite", GlobalIsFinite,
215 "parseInt", GlobalParseInt, 214 "parseInt", GlobalParseInt,
216 "parseFloat", GlobalParseFloat, 215 "parseFloat", GlobalParseFloat,
217 "eval", GlobalEval 216 "eval", GlobalEval
218 )); 217 ));
219 } 218 }
220 219
221 SetUpGlobal(); 220 SetUpGlobal();
222 221
222
223 // ---------------------------------------------------------------------------- 223 // ----------------------------------------------------------------------------
224 // Boolean (first part of definition) 224 // Boolean (first part of definition)
225 225
226 226 function BooleanConstructor(x) {
rossberg 2013/04/11 12:00:18 Move this to the rest of the Boolean stuff.
Michael Starzinger 2013/04/11 12:08:44 Done.
227 %SetCode($Boolean, function(x) {
228 if (%_IsConstructCall()) { 227 if (%_IsConstructCall()) {
229 %_SetValueOf(this, ToBoolean(x)); 228 %_SetValueOf(this, ToBoolean(x));
230 } else { 229 } else {
231 return ToBoolean(x); 230 return ToBoolean(x);
232 } 231 }
233 }); 232 }
234 233
235 %FunctionSetPrototype($Boolean, new $Boolean(false));
236
237 %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM);
238 234
239 // ---------------------------------------------------------------------------- 235 // ----------------------------------------------------------------------------
240 // Object 236 // Object
241 237
242 $Object.prototype.constructor = $Object;
243
244 // ECMA-262 - 15.2.4.2 238 // ECMA-262 - 15.2.4.2
245 function ObjectToString() { 239 function ObjectToString() {
246 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; 240 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
247 if (IS_NULL(this)) return "[object Null]"; 241 if (IS_NULL(this)) return "[object Null]";
248 return "[object " + %_ClassOf(ToObject(this)) + "]"; 242 return "[object " + %_ClassOf(ToObject(this)) + "]";
249 } 243 }
250 244
251 245
252 // ECMA-262 - 15.2.4.3 246 // ECMA-262 - 15.2.4.3
253 function ObjectToLocaleString() { 247 function ObjectToLocaleString() {
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 return %SetPrototype(this, obj); 1344 return %SetPrototype(this, obj);
1351 } 1345 }
1352 1346
1353 1347
1354 // Harmony __proto__ poison pill. 1348 // Harmony __proto__ poison pill.
1355 function ObjectPoisonProto(obj) { 1349 function ObjectPoisonProto(obj) {
1356 throw MakeTypeError("proto_poison_pill", []); 1350 throw MakeTypeError("proto_poison_pill", []);
1357 } 1351 }
1358 1352
1359 1353
1360 %SetCode($Object, function(x) { 1354 function ObjectConstructor(x) {
1361 if (%_IsConstructCall()) { 1355 if (%_IsConstructCall()) {
1362 if (x == null) return this; 1356 if (x == null) return this;
1363 return ToObject(x); 1357 return ToObject(x);
1364 } else { 1358 } else {
1365 if (x == null) return { }; 1359 if (x == null) return { };
1366 return ToObject(x); 1360 return ToObject(x);
1367 } 1361 }
1368 }); 1362 }
1369 1363
1370 1364
1371 // ---------------------------------------------------------------------------- 1365 // ----------------------------------------------------------------------------
1372 // Object 1366 // Object
1373 1367
1374 function SetUpObject() { 1368 function SetUpObject() {
1375 %CheckIsBootstrapping(); 1369 %CheckIsBootstrapping();
1376 1370
1371 $Object.prototype.constructor = $Object;
1372 %SetCode($Object, ObjectConstructor);
1377 %FunctionSetName(ObjectPoisonProto, "__proto__"); 1373 %FunctionSetName(ObjectPoisonProto, "__proto__");
1378 %FunctionRemovePrototype(ObjectPoisonProto); 1374 %FunctionRemovePrototype(ObjectPoisonProto);
1379 %SetExpectedNumberOfProperties($Object, 4); 1375 %SetExpectedNumberOfProperties($Object, 4);
1380 1376
1381 // Set up non-enumerable functions on the Object.prototype object. 1377 // Set up non-enumerable functions on the Object.prototype object.
1382 InstallFunctions($Object.prototype, DONT_ENUM, $Array( 1378 InstallFunctions($Object.prototype, DONT_ENUM, $Array(
1383 "toString", ObjectToString, 1379 "toString", ObjectToString,
1384 "toLocaleString", ObjectToLocaleString, 1380 "toLocaleString", ObjectToLocaleString,
1385 "valueOf", ObjectValueOf, 1381 "valueOf", ObjectValueOf,
1386 "hasOwnProperty", ObjectHasOwnProperty, 1382 "hasOwnProperty", ObjectHasOwnProperty,
(...skipping 21 matching lines...) Expand all
1408 "isExtensible", ObjectIsExtensible, 1404 "isExtensible", ObjectIsExtensible,
1409 "isFrozen", ObjectIsFrozen, 1405 "isFrozen", ObjectIsFrozen,
1410 "isSealed", ObjectIsSealed, 1406 "isSealed", ObjectIsSealed,
1411 "preventExtensions", ObjectPreventExtension, 1407 "preventExtensions", ObjectPreventExtension,
1412 "seal", ObjectSeal 1408 "seal", ObjectSeal
1413 )); 1409 ));
1414 } 1410 }
1415 1411
1416 SetUpObject(); 1412 SetUpObject();
1417 1413
1414
1418 // ---------------------------------------------------------------------------- 1415 // ----------------------------------------------------------------------------
1419 // Boolean 1416 // Boolean
1420 1417
1421 function BooleanToString() { 1418 function BooleanToString() {
1422 // NOTE: Both Boolean objects and values can enter here as 1419 // NOTE: Both Boolean objects and values can enter here as
1423 // 'this'. This is not as dictated by ECMA-262. 1420 // 'this'. This is not as dictated by ECMA-262.
1424 var b = this; 1421 var b = this;
1425 if (!IS_BOOLEAN(b)) { 1422 if (!IS_BOOLEAN(b)) {
1426 if (!IS_BOOLEAN_WRAPPER(b)) { 1423 if (!IS_BOOLEAN_WRAPPER(b)) {
1427 throw new $TypeError('Boolean.prototype.toString is not generic'); 1424 throw new $TypeError('Boolean.prototype.toString is not generic');
1428 } 1425 }
1429 b = %_ValueOf(b); 1426 b = %_ValueOf(b);
1430 } 1427 }
1431 return b ? 'true' : 'false'; 1428 return b ? 'true' : 'false';
1432 } 1429 }
1433 1430
1434 1431
1435 function BooleanValueOf() { 1432 function BooleanValueOf() {
1436 // NOTE: Both Boolean objects and values can enter here as 1433 // NOTE: Both Boolean objects and values can enter here as
1437 // 'this'. This is not as dictated by ECMA-262. 1434 // 'this'. This is not as dictated by ECMA-262.
1438 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) { 1435 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) {
1439 throw new $TypeError('Boolean.prototype.valueOf is not generic'); 1436 throw new $TypeError('Boolean.prototype.valueOf is not generic');
1440 } 1437 }
1441 return %_ValueOf(this); 1438 return %_ValueOf(this);
1442 } 1439 }
1443 1440
1444 1441
1445 // ---------------------------------------------------------------------------- 1442 // ----------------------------------------------------------------------------
1446 1443
1447
1448 function SetUpBoolean () { 1444 function SetUpBoolean () {
1449 %CheckIsBootstrapping(); 1445 %CheckIsBootstrapping();
1446
1447 %SetCode($Boolean, BooleanConstructor);
1448 %FunctionSetPrototype($Boolean, new $Boolean(false));
1449 %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM);
1450
1450 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( 1451 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array(
1451 "toString", BooleanToString, 1452 "toString", BooleanToString,
1452 "valueOf", BooleanValueOf 1453 "valueOf", BooleanValueOf
1453 )); 1454 ));
1454 } 1455 }
1455 1456
1456 SetUpBoolean(); 1457 SetUpBoolean();
1457 1458
1458 1459
1459 // ---------------------------------------------------------------------------- 1460 // ----------------------------------------------------------------------------
1460 // Number 1461 // Number
1461 1462
1462 // Set the Number function and constructor. 1463 function NumberConstructor(x) {
1463 %SetCode($Number, function(x) {
1464 var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); 1464 var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x);
1465 if (%_IsConstructCall()) { 1465 if (%_IsConstructCall()) {
1466 %_SetValueOf(this, value); 1466 %_SetValueOf(this, value);
1467 } else { 1467 } else {
1468 return value; 1468 return value;
1469 } 1469 }
1470 }); 1470 }
1471 1471
1472 %FunctionSetPrototype($Number, new $Number(0));
1473 1472
1474 // ECMA-262 section 15.7.4.2. 1473 // ECMA-262 section 15.7.4.2.
1475 function NumberToString(radix) { 1474 function NumberToString(radix) {
1476 // NOTE: Both Number objects and values can enter here as 1475 // NOTE: Both Number objects and values can enter here as
1477 // 'this'. This is not as dictated by ECMA-262. 1476 // 'this'. This is not as dictated by ECMA-262.
1478 var number = this; 1477 var number = this;
1479 if (!IS_NUMBER(this)) { 1478 if (!IS_NUMBER(this)) {
1480 if (!IS_NUMBER_WRAPPER(this)) { 1479 if (!IS_NUMBER_WRAPPER(this)) {
1481 throw new $TypeError('Number.prototype.toString is not generic'); 1480 throw new $TypeError('Number.prototype.toString is not generic');
1482 } 1481 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 // Harmony isNaN. 1599 // Harmony isNaN.
1601 function NumberIsNaN(number) { 1600 function NumberIsNaN(number) {
1602 return IS_NUMBER(number) && NUMBER_IS_NAN(number); 1601 return IS_NUMBER(number) && NUMBER_IS_NAN(number);
1603 } 1602 }
1604 1603
1605 1604
1606 // ---------------------------------------------------------------------------- 1605 // ----------------------------------------------------------------------------
1607 1606
1608 function SetUpNumber() { 1607 function SetUpNumber() {
1609 %CheckIsBootstrapping(); 1608 %CheckIsBootstrapping();
1609
1610 // Set the Number function and constructor.
rossberg 2013/04/11 12:00:18 Nit: remove this comment
Michael Starzinger 2013/04/11 12:08:44 Done.
1611 %SetCode($Number, NumberConstructor);
1612 %FunctionSetPrototype($Number, new $Number(0));
1613
1610 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); 1614 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8);
1611 // Set up the constructor property on the Number prototype object. 1615 // Set up the constructor property on the Number prototype object.
1612 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); 1616 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM);
1613 1617
1614 %OptimizeObjectForAddingMultipleProperties($Number, 5); 1618 %OptimizeObjectForAddingMultipleProperties($Number, 5);
1615 // ECMA-262 section 15.7.3.1. 1619 // ECMA-262 section 15.7.3.1.
1616 %SetProperty($Number, 1620 %SetProperty($Number,
1617 "MAX_VALUE", 1621 "MAX_VALUE",
1618 1.7976931348623157e+308, 1622 1.7976931348623157e+308,
1619 DONT_ENUM | DONT_DELETE | READ_ONLY); 1623 DONT_ENUM | DONT_DELETE | READ_ONLY);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 "isNaN", NumberIsNaN 1656 "isNaN", NumberIsNaN
1653 )); 1657 ));
1654 } 1658 }
1655 1659
1656 SetUpNumber(); 1660 SetUpNumber();
1657 1661
1658 1662
1659 // ---------------------------------------------------------------------------- 1663 // ----------------------------------------------------------------------------
1660 // Function 1664 // Function
1661 1665
1662 $Function.prototype.constructor = $Function;
1663
1664 function FunctionSourceString(func) { 1666 function FunctionSourceString(func) {
1665 while (%IsJSFunctionProxy(func)) { 1667 while (%IsJSFunctionProxy(func)) {
1666 func = %GetCallTrap(func); 1668 func = %GetCallTrap(func);
1667 } 1669 }
1668 1670
1669 if (!IS_FUNCTION(func)) { 1671 if (!IS_FUNCTION(func)) {
1670 throw new $TypeError('Function.prototype.toString is not generic'); 1672 throw new $TypeError('Function.prototype.toString is not generic');
1671 } 1673 }
1672 1674
1673 var source = %FunctionGetSourceCode(func); 1675 var source = %FunctionGetSourceCode(func);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 1779
1778 // The call to SetNewFunctionAttributes will ensure the prototype 1780 // The call to SetNewFunctionAttributes will ensure the prototype
1779 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). 1781 // property of the resulting function is enumerable (ECMA262, 15.3.5.2).
1780 var global_receiver = %GlobalReceiver(global); 1782 var global_receiver = %GlobalReceiver(global);
1781 var f = %_CallFunction(global_receiver, %CompileString(source, true)); 1783 var f = %_CallFunction(global_receiver, %CompileString(source, true));
1782 1784
1783 %FunctionMarkNameShouldPrintAsAnonymous(f); 1785 %FunctionMarkNameShouldPrintAsAnonymous(f);
1784 return %SetNewFunctionAttributes(f); 1786 return %SetNewFunctionAttributes(f);
1785 } 1787 }
1786 1788
1787 %SetCode($Function, NewFunction);
1788 1789
1789 // ---------------------------------------------------------------------------- 1790 // ----------------------------------------------------------------------------
1790 1791
1791 function SetUpFunction() { 1792 function SetUpFunction() {
1792 %CheckIsBootstrapping(); 1793 %CheckIsBootstrapping();
1794
1795 $Function.prototype.constructor = $Function;
1796 %SetCode($Function, NewFunction);
1797
1793 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1798 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1794 "bind", FunctionBind, 1799 "bind", FunctionBind,
1795 "toString", FunctionToString 1800 "toString", FunctionToString
1796 )); 1801 ));
1797 } 1802 }
1798 1803
1799 SetUpFunction(); 1804 SetUpFunction();
OLDNEW
« src/proxy.js ('K') | « src/uri.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698