| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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. |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 return %_CallFunction(receiver, f); | 156 return %_CallFunction(receiver, f); |
| 157 } | 157 } |
| 158 | 158 |
| 159 | 159 |
| 160 // ---------------------------------------------------------------------------- | 160 // ---------------------------------------------------------------------------- |
| 161 | 161 |
| 162 | 162 |
| 163 function SetupGlobal() { | 163 function SetupGlobal() { |
| 164 // ECMA 262 - 15.1.1.1. | 164 // ECMA 262 - 15.1.1.1. |
| 165 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); | 165 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); |
| 166 | 166 |
| 167 // ECMA-262 - 15.1.1.2. | 167 // ECMA-262 - 15.1.1.2. |
| 168 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE | READ_ONLY); | 168 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE); |
| 169 | 169 |
| 170 // ECMA-262 - 15.1.1.3. | 170 // ECMA-262 - 15.1.1.3. |
| 171 %SetProperty(global, "undefined", void 0, | 171 %SetProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE); |
| 172 DONT_ENUM | DONT_DELETE | READ_ONLY); | |
| 173 | 172 |
| 174 // Setup non-enumerable function on the global object. | 173 // Setup non-enumerable function on the global object. |
| 175 InstallFunctions(global, DONT_ENUM, $Array( | 174 InstallFunctions(global, DONT_ENUM, $Array( |
| 176 "isNaN", GlobalIsNaN, | 175 "isNaN", GlobalIsNaN, |
| 177 "isFinite", GlobalIsFinite, | 176 "isFinite", GlobalIsFinite, |
| 178 "parseInt", GlobalParseInt, | 177 "parseInt", GlobalParseInt, |
| 179 "parseFloat", GlobalParseFloat, | 178 "parseFloat", GlobalParseFloat, |
| 180 "eval", GlobalEval | 179 "eval", GlobalEval |
| 181 )); | 180 )); |
| 182 } | 181 } |
| (...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1422 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { | 1421 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { |
| 1423 var name = %FunctionGetName(func); | 1422 var name = %FunctionGetName(func); |
| 1424 if (name) { | 1423 if (name) { |
| 1425 // Mimic what KJS does. | 1424 // Mimic what KJS does. |
| 1426 return 'function ' + name + '() { [native code] }'; | 1425 return 'function ' + name + '() { [native code] }'; |
| 1427 } else { | 1426 } else { |
| 1428 return 'function () { [native code] }'; | 1427 return 'function () { [native code] }'; |
| 1429 } | 1428 } |
| 1430 } | 1429 } |
| 1431 | 1430 |
| 1432 var name = %FunctionGetName(func); | 1431 var name = %FunctionNameShouldPrintAsAnonymous(func) |
| 1432 ? 'anonymous' |
| 1433 : %FunctionGetName(func); |
| 1433 return 'function ' + name + source; | 1434 return 'function ' + name + source; |
| 1434 } | 1435 } |
| 1435 | 1436 |
| 1436 | 1437 |
| 1437 function FunctionToString() { | 1438 function FunctionToString() { |
| 1438 return FunctionSourceString(this); | 1439 return FunctionSourceString(this); |
| 1439 } | 1440 } |
| 1440 | 1441 |
| 1441 | 1442 |
| 1442 // ES5 15.3.4.5 | 1443 // ES5 15.3.4.5 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1492 | 1493 |
| 1493 // We already have caller and arguments properties on functions, | 1494 // We already have caller and arguments properties on functions, |
| 1494 // which are non-configurable. It therefore makes no sence to | 1495 // which are non-configurable. It therefore makes no sence to |
| 1495 // try to redefine these as defined by the spec. The spec says | 1496 // try to redefine these as defined by the spec. The spec says |
| 1496 // that bind should make these throw a TypeError if get or set | 1497 // that bind should make these throw a TypeError if get or set |
| 1497 // is called and make them non-enumerable and non-configurable. | 1498 // is called and make them non-enumerable and non-configurable. |
| 1498 // To be consistent with our normal functions we leave this as it is. | 1499 // To be consistent with our normal functions we leave this as it is. |
| 1499 | 1500 |
| 1500 // Set the correct length. | 1501 // Set the correct length. |
| 1501 var length = (this.length - argc_bound) > 0 ? this.length - argc_bound : 0; | 1502 var length = (this.length - argc_bound) > 0 ? this.length - argc_bound : 0; |
| 1502 %FunctionSetLength(result, length); | |
| 1503 %FunctionRemovePrototype(result); | 1503 %FunctionRemovePrototype(result); |
| 1504 %FunctionSetBound(result); | 1504 %FunctionSetBound(result); |
| 1505 %BoundFunctionSetLength(result, length); |
| 1505 return result; | 1506 return result; |
| 1506 } | 1507 } |
| 1507 | 1508 |
| 1508 | 1509 |
| 1509 function NewFunction(arg1) { // length == 1 | 1510 function NewFunction(arg1) { // length == 1 |
| 1510 var n = %_ArgumentsLength(); | 1511 var n = %_ArgumentsLength(); |
| 1511 var p = ''; | 1512 var p = ''; |
| 1512 if (n > 1) { | 1513 if (n > 1) { |
| 1513 p = new InternalArray(n - 1); | 1514 p = new InternalArray(n - 1); |
| 1514 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); | 1515 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); |
| 1515 p = Join(p, n - 1, ',', NonStringToString); | 1516 p = Join(p, n - 1, ',', NonStringToString); |
| 1516 // If the formal parameters string include ) - an illegal | 1517 // If the formal parameters string include ) - an illegal |
| 1517 // character - it may make the combined function expression | 1518 // character - it may make the combined function expression |
| 1518 // compile. We avoid this problem by checking for this early on. | 1519 // compile. We avoid this problem by checking for this early on. |
| 1519 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); | 1520 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); |
| 1520 } | 1521 } |
| 1521 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; | 1522 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; |
| 1522 var source = '(function(' + p + ') {\n' + body + '\n})'; | 1523 var source = '(function(' + p + ') {\n' + body + '\n})'; |
| 1523 | 1524 |
| 1524 // The call to SetNewFunctionAttributes will ensure the prototype | 1525 // The call to SetNewFunctionAttributes will ensure the prototype |
| 1525 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). | 1526 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). |
| 1526 var f = %CompileString(source)(); | 1527 var f = %CompileString(source)(); |
| 1527 %FunctionSetName(f, "anonymous"); | 1528 %FunctionMarkNameShouldPrintAsAnonymous(f); |
| 1528 return %SetNewFunctionAttributes(f); | 1529 return %SetNewFunctionAttributes(f); |
| 1529 } | 1530 } |
| 1530 | 1531 |
| 1531 %SetCode($Function, NewFunction); | 1532 %SetCode($Function, NewFunction); |
| 1532 | 1533 |
| 1533 // ---------------------------------------------------------------------------- | 1534 // ---------------------------------------------------------------------------- |
| 1534 | 1535 |
| 1535 function SetupFunction() { | 1536 function SetupFunction() { |
| 1536 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1537 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1537 "bind", FunctionBind, | 1538 "bind", FunctionBind, |
| 1538 "toString", FunctionToString | 1539 "toString", FunctionToString |
| 1539 )); | 1540 )); |
| 1540 } | 1541 } |
| 1541 | 1542 |
| 1542 SetupFunction(); | 1543 SetupFunction(); |
| OLD | NEW |