| OLD | NEW |
| 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 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // For consistency with JSC we require the global object passed to | 167 // For consistency with JSC we require the global object passed to |
| 168 // eval to be the global object from which 'eval' originated. This | 168 // eval to be the global object from which 'eval' originated. This |
| 169 // is not mandated by the spec. | 169 // is not mandated by the spec. |
| 170 // We only throw if the global has been detached, since we need the | 170 // We only throw if the global has been detached, since we need the |
| 171 // receiver as this-value for the call. | 171 // receiver as this-value for the call. |
| 172 if (global_is_detached) { | 172 if (global_is_detached) { |
| 173 throw new $EvalError('The "this" value passed to eval must ' + | 173 throw new $EvalError('The "this" value passed to eval must ' + |
| 174 'be the global object from which eval originated'); | 174 'be the global object from which eval originated'); |
| 175 } | 175 } |
| 176 | 176 |
| 177 var f = %CompileString(x); | 177 var f = %CompileString(x, false); |
| 178 if (!IS_FUNCTION(f)) return f; | 178 if (!IS_FUNCTION(f)) return f; |
| 179 | 179 |
| 180 return %_CallFunction(global_receiver, f); | 180 return %_CallFunction(global_receiver, f); |
| 181 } | 181 } |
| 182 | 182 |
| 183 | 183 |
| 184 // ---------------------------------------------------------------------------- | 184 // ---------------------------------------------------------------------------- |
| 185 | 185 |
| 186 // Set up global object. | 186 // Set up global object. |
| 187 function SetUpGlobal() { | 187 function SetUpGlobal() { |
| (...skipping 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1697 var n = %_ArgumentsLength(); | 1697 var n = %_ArgumentsLength(); |
| 1698 var p = ''; | 1698 var p = ''; |
| 1699 if (n > 1) { | 1699 if (n > 1) { |
| 1700 p = new InternalArray(n - 1); | 1700 p = new InternalArray(n - 1); |
| 1701 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); | 1701 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); |
| 1702 p = Join(p, n - 1, ',', NonStringToString); | 1702 p = Join(p, n - 1, ',', NonStringToString); |
| 1703 // If the formal parameters string include ) - an illegal | 1703 // If the formal parameters string include ) - an illegal |
| 1704 // character - it may make the combined function expression | 1704 // character - it may make the combined function expression |
| 1705 // compile. We avoid this problem by checking for this early on. | 1705 // compile. We avoid this problem by checking for this early on. |
| 1706 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); | 1706 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); |
| 1707 // If the formal parameters include an unbalanced block comment, the |
| 1708 // function must be rejected. Since JavaScript does not allow nested |
| 1709 // comments we can include a trailing block comment to catch this. |
| 1710 p += '\n/' + '**/'; |
| 1707 } | 1711 } |
| 1708 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; | 1712 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; |
| 1709 var source = '(function(' + p + ') {\n' + body + '\n})'; | 1713 var source = '(function(\n' + p + '\n){\n' + body + '\n})'; |
| 1710 | 1714 |
| 1711 // The call to SetNewFunctionAttributes will ensure the prototype | 1715 // The call to SetNewFunctionAttributes will ensure the prototype |
| 1712 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). | 1716 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). |
| 1713 var global_receiver = %GlobalReceiver(global); | 1717 var global_receiver = %GlobalReceiver(global); |
| 1714 var f = %_CallFunction(global_receiver, %CompileString(source)); | 1718 var f = %_CallFunction(global_receiver, %CompileString(source, true)); |
| 1715 | 1719 |
| 1716 %FunctionMarkNameShouldPrintAsAnonymous(f); | 1720 %FunctionMarkNameShouldPrintAsAnonymous(f); |
| 1717 return %SetNewFunctionAttributes(f); | 1721 return %SetNewFunctionAttributes(f); |
| 1718 } | 1722 } |
| 1719 | 1723 |
| 1720 %SetCode($Function, NewFunction); | 1724 %SetCode($Function, NewFunction); |
| 1721 | 1725 |
| 1722 // ---------------------------------------------------------------------------- | 1726 // ---------------------------------------------------------------------------- |
| 1723 | 1727 |
| 1724 function SetUpFunction() { | 1728 function SetUpFunction() { |
| 1725 %CheckIsBootstrapping(); | 1729 %CheckIsBootstrapping(); |
| 1726 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1730 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1727 "bind", FunctionBind, | 1731 "bind", FunctionBind, |
| 1728 "toString", FunctionToString | 1732 "toString", FunctionToString |
| 1729 )); | 1733 )); |
| 1730 } | 1734 } |
| 1731 | 1735 |
| 1732 SetUpFunction(); | 1736 SetUpFunction(); |
| OLD | NEW |