| 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 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1421 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { | 1421 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { |
| 1422 var name = %FunctionGetName(func); | 1422 var name = %FunctionGetName(func); |
| 1423 if (name) { | 1423 if (name) { |
| 1424 // Mimic what KJS does. | 1424 // Mimic what KJS does. |
| 1425 return 'function ' + name + '() { [native code] }'; | 1425 return 'function ' + name + '() { [native code] }'; |
| 1426 } else { | 1426 } else { |
| 1427 return 'function () { [native code] }'; | 1427 return 'function () { [native code] }'; |
| 1428 } | 1428 } |
| 1429 } | 1429 } |
| 1430 | 1430 |
| 1431 var name = %FunctionGetName(func); | 1431 var name = %FunctionNameShouldPrintAsAnonymous(func) |
| 1432 ? 'anonymous' |
| 1433 : %FunctionGetName(func); |
| 1432 return 'function ' + name + source; | 1434 return 'function ' + name + source; |
| 1433 } | 1435 } |
| 1434 | 1436 |
| 1435 | 1437 |
| 1436 function FunctionToString() { | 1438 function FunctionToString() { |
| 1437 return FunctionSourceString(this); | 1439 return FunctionSourceString(this); |
| 1438 } | 1440 } |
| 1439 | 1441 |
| 1440 | 1442 |
| 1441 // ES5 15.3.4.5 | 1443 // ES5 15.3.4.5 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 // character - it may make the combined function expression | 1518 // character - it may make the combined function expression |
| 1517 // compile. We avoid this problem by checking for this early on. | 1519 // compile. We avoid this problem by checking for this early on. |
| 1518 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); | 1520 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); |
| 1519 } | 1521 } |
| 1520 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; | 1522 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; |
| 1521 var source = '(function(' + p + ') {\n' + body + '\n})'; | 1523 var source = '(function(' + p + ') {\n' + body + '\n})'; |
| 1522 | 1524 |
| 1523 // The call to SetNewFunctionAttributes will ensure the prototype | 1525 // The call to SetNewFunctionAttributes will ensure the prototype |
| 1524 // 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). |
| 1525 var f = %CompileString(source)(); | 1527 var f = %CompileString(source)(); |
| 1526 %FunctionSetName(f, "anonymous"); | 1528 %FunctionMarkNameShouldPrintAsAnonymous(f); |
| 1527 return %SetNewFunctionAttributes(f); | 1529 return %SetNewFunctionAttributes(f); |
| 1528 } | 1530 } |
| 1529 | 1531 |
| 1530 %SetCode($Function, NewFunction); | 1532 %SetCode($Function, NewFunction); |
| 1531 | 1533 |
| 1532 // ---------------------------------------------------------------------------- | 1534 // ---------------------------------------------------------------------------- |
| 1533 | 1535 |
| 1534 function SetupFunction() { | 1536 function SetupFunction() { |
| 1535 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1537 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1536 "bind", FunctionBind, | 1538 "bind", FunctionBind, |
| 1537 "toString", FunctionToString | 1539 "toString", FunctionToString |
| 1538 )); | 1540 )); |
| 1539 } | 1541 } |
| 1540 | 1542 |
| 1541 SetupFunction(); | 1543 SetupFunction(); |
| OLD | NEW |