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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 if (%_HasCachedArrayIndex(string)) return %_GetCachedArrayIndex(string); | 169 if (%_HasCachedArrayIndex(string)) return %_GetCachedArrayIndex(string); |
170 return %StringParseFloat(string); | 170 return %StringParseFloat(string); |
171 } | 171 } |
172 | 172 |
173 | 173 |
174 function GlobalEval(x) { | 174 function GlobalEval(x) { |
175 if (!IS_STRING(x)) return x; | 175 if (!IS_STRING(x)) return x; |
176 | 176 |
177 var global_proxy = %GlobalProxy(global); | 177 var global_proxy = %GlobalProxy(global); |
178 | 178 |
179 var f = %CompileString(x, false, 0); | 179 var f = %CompileString(x, false); |
180 if (!IS_FUNCTION(f)) return f; | 180 if (!IS_FUNCTION(f)) return f; |
181 | 181 |
182 return %_CallFunction(global_proxy, f); | 182 return %_CallFunction(global_proxy, f); |
183 } | 183 } |
184 | 184 |
185 | 185 |
186 // ---------------------------------------------------------------------------- | 186 // ---------------------------------------------------------------------------- |
187 | 187 |
188 // Set up global object. | 188 // Set up global object. |
189 function SetUpGlobal() { | 189 function SetUpGlobal() { |
(...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1825 // which are non-configurable. It therefore makes no sence to | 1825 // which are non-configurable. It therefore makes no sence to |
1826 // try to redefine these as defined by the spec. The spec says | 1826 // try to redefine these as defined by the spec. The spec says |
1827 // that bind should make these throw a TypeError if get or set | 1827 // that bind should make these throw a TypeError if get or set |
1828 // is called and make them non-enumerable and non-configurable. | 1828 // is called and make them non-enumerable and non-configurable. |
1829 // To be consistent with our normal functions we leave this as it is. | 1829 // To be consistent with our normal functions we leave this as it is. |
1830 // TODO(lrn): Do set these to be thrower. | 1830 // TODO(lrn): Do set these to be thrower. |
1831 return result; | 1831 return result; |
1832 } | 1832 } |
1833 | 1833 |
1834 | 1834 |
1835 function NewFunctionFromString(arguments, function_token) { | 1835 function NewFunctionString(arguments, function_token) { |
1836 var n = arguments.length; | 1836 var n = arguments.length; |
1837 var p = ''; | 1837 var p = ''; |
1838 if (n > 1) { | 1838 if (n > 1) { |
1839 p = ToString(arguments[0]); | 1839 p = ToString(arguments[0]); |
1840 for (var i = 1; i < n - 1; i++) { | 1840 for (var i = 1; i < n - 1; i++) { |
1841 p += ',' + ToString(arguments[i]); | 1841 p += ',' + ToString(arguments[i]); |
1842 } | 1842 } |
1843 // If the formal parameters string include ) - an illegal | 1843 // If the formal parameters string include ) - an illegal |
1844 // character - it may make the combined function expression | 1844 // character - it may make the combined function expression |
1845 // compile. We avoid this problem by checking for this early on. | 1845 // compile. We avoid this problem by checking for this early on. |
1846 if (%_CallFunction(p, ')', $stringIndexOf) != -1) { | 1846 if (%_CallFunction(p, ')', $stringIndexOf) != -1) { |
1847 throw MakeSyntaxError('paren_in_arg_string', []); | 1847 throw MakeSyntaxError('paren_in_arg_string', []); |
1848 } | 1848 } |
1849 // If the formal parameters include an unbalanced block comment, the | 1849 // If the formal parameters include an unbalanced block comment, the |
1850 // function must be rejected. Since JavaScript does not allow nested | 1850 // function must be rejected. Since JavaScript does not allow nested |
1851 // comments we can include a trailing block comment to catch this. | 1851 // comments we can include a trailing block comment to catch this. |
1852 p += '\n\x2f**\x2f'; | 1852 p += '\n/' + '**/'; |
1853 } | 1853 } |
1854 var body = (n > 0) ? ToString(arguments[n - 1]) : ''; | 1854 var body = (n > 0) ? ToString(arguments[n - 1]) : ''; |
1855 var head = '(' + function_token + '(' + p + ') {\n'; | 1855 return '(' + function_token + '(' + p + ') {\n' + body + '\n})'; |
1856 var src = head + body + '\n})'; | 1856 } |
| 1857 |
| 1858 |
| 1859 function FunctionConstructor(arg1) { // length == 1 |
| 1860 var source = NewFunctionString(arguments, 'function'); |
1857 var global_proxy = %GlobalProxy(global); | 1861 var global_proxy = %GlobalProxy(global); |
1858 var f = %_CallFunction(global_proxy, %CompileString(src, true, head.length)); | 1862 // Compile the string in the constructor and not a helper so that errors |
| 1863 // appear to come from here. |
| 1864 var f = %_CallFunction(global_proxy, %CompileString(source, true)); |
1859 %FunctionMarkNameShouldPrintAsAnonymous(f); | 1865 %FunctionMarkNameShouldPrintAsAnonymous(f); |
1860 return f; | 1866 return f; |
1861 } | 1867 } |
1862 | 1868 |
1863 | 1869 |
1864 function FunctionConstructor(arg1) { // length == 1 | |
1865 return NewFunctionFromString(arguments, 'function'); | |
1866 } | |
1867 | |
1868 | |
1869 // ---------------------------------------------------------------------------- | 1870 // ---------------------------------------------------------------------------- |
1870 | 1871 |
1871 function SetUpFunction() { | 1872 function SetUpFunction() { |
1872 %CheckIsBootstrapping(); | 1873 %CheckIsBootstrapping(); |
1873 | 1874 |
1874 %SetCode($Function, FunctionConstructor); | 1875 %SetCode($Function, FunctionConstructor); |
1875 %AddNamedProperty($Function.prototype, "constructor", $Function, DONT_ENUM); | 1876 %AddNamedProperty($Function.prototype, "constructor", $Function, DONT_ENUM); |
1876 | 1877 |
1877 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1878 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1878 "bind", FunctionBind, | 1879 "bind", FunctionBind, |
(...skipping 15 matching lines...) Expand all Loading... |
1894 } | 1895 } |
1895 if (!IS_SPEC_FUNCTION(method)) { | 1896 if (!IS_SPEC_FUNCTION(method)) { |
1896 throw MakeTypeError('not_iterable', [obj]); | 1897 throw MakeTypeError('not_iterable', [obj]); |
1897 } | 1898 } |
1898 var iterator = %_CallFunction(obj, method); | 1899 var iterator = %_CallFunction(obj, method); |
1899 if (!IS_SPEC_OBJECT(iterator)) { | 1900 if (!IS_SPEC_OBJECT(iterator)) { |
1900 throw MakeTypeError('not_an_iterator', [iterator]); | 1901 throw MakeTypeError('not_an_iterator', [iterator]); |
1901 } | 1902 } |
1902 return iterator; | 1903 return iterator; |
1903 } | 1904 } |
OLD | NEW |