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