OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 return result; | 1149 return result; |
1150 } | 1150 } |
1151 | 1151 |
1152 | 1152 |
1153 function NewFunction(arg1) { // length == 1 | 1153 function NewFunction(arg1) { // length == 1 |
1154 var n = %_ArgumentsLength(); | 1154 var n = %_ArgumentsLength(); |
1155 var p = ''; | 1155 var p = ''; |
1156 if (n > 1) { | 1156 if (n > 1) { |
1157 p = new $Array(n - 1); | 1157 p = new $Array(n - 1); |
1158 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); | 1158 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); |
1159 p = Join(p, n - 1, ',', ToString); | 1159 p = Join(p, n - 1, ',', NonStringToString); |
1160 // If the formal parameters string include ) - an illegal | 1160 // If the formal parameters string include ) - an illegal |
1161 // character - it may make the combined function expression | 1161 // character - it may make the combined function expression |
1162 // compile. We avoid this problem by checking for this early on. | 1162 // compile. We avoid this problem by checking for this early on. |
1163 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); | 1163 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); |
1164 } | 1164 } |
1165 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; | 1165 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; |
1166 var source = '(function(' + p + ') {\n' + body + '\n})'; | 1166 var source = '(function(' + p + ') {\n' + body + '\n})'; |
1167 | 1167 |
1168 // The call to SetNewFunctionAttributes will ensure the prototype | 1168 // The call to SetNewFunctionAttributes will ensure the prototype |
1169 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). | 1169 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). |
1170 var f = %CompileString(source)(); | 1170 var f = %CompileString(source)(); |
1171 %FunctionSetName(f, "anonymous"); | 1171 %FunctionSetName(f, "anonymous"); |
1172 return %SetNewFunctionAttributes(f); | 1172 return %SetNewFunctionAttributes(f); |
1173 } | 1173 } |
1174 | 1174 |
1175 %SetCode($Function, NewFunction); | 1175 %SetCode($Function, NewFunction); |
1176 | 1176 |
1177 // ---------------------------------------------------------------------------- | 1177 // ---------------------------------------------------------------------------- |
1178 | 1178 |
1179 function SetupFunction() { | 1179 function SetupFunction() { |
1180 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1180 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1181 "bind", FunctionBind, | 1181 "bind", FunctionBind, |
1182 "toString", FunctionToString | 1182 "toString", FunctionToString |
1183 )); | 1183 )); |
1184 } | 1184 } |
1185 | 1185 |
1186 SetupFunction(); | 1186 SetupFunction(); |
OLD | NEW |