| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 var global_is_detached = (global === global_receiver); | 136 var global_is_detached = (global === global_receiver); |
| 137 | 137 |
| 138 if (!this_is_global_receiver || global_is_detached) { | 138 if (!this_is_global_receiver || global_is_detached) { |
| 139 throw new $EvalError('The "this" object passed to eval must ' + | 139 throw new $EvalError('The "this" object passed to eval must ' + |
| 140 'be the global object from which eval originated'); | 140 'be the global object from which eval originated'); |
| 141 } | 141 } |
| 142 | 142 |
| 143 var f = %CompileString(x); | 143 var f = %CompileString(x); |
| 144 if (!IS_FUNCTION(f)) return f; | 144 if (!IS_FUNCTION(f)) return f; |
| 145 | 145 |
| 146 return f.call(this); | 146 return %_CallFunction(this, f); |
| 147 } | 147 } |
| 148 | 148 |
| 149 | 149 |
| 150 // execScript for IE compatibility. | 150 // execScript for IE compatibility. |
| 151 function GlobalExecScript(expr, lang) { | 151 function GlobalExecScript(expr, lang) { |
| 152 // NOTE: We don't care about the character casing. | 152 // NOTE: We don't care about the character casing. |
| 153 if (!lang || /javascript/i.test(lang)) { | 153 if (!lang || /javascript/i.test(lang)) { |
| 154 var f = %CompileString(ToString(expr)); | 154 var f = %CompileString(ToString(expr)); |
| 155 f.call(%GlobalReceiver(global)); | 155 %_CallFunction(%GlobalReceiver(global), f); |
| 156 } | 156 } |
| 157 return null; | 157 return null; |
| 158 } | 158 } |
| 159 | 159 |
| 160 | 160 |
| 161 // ---------------------------------------------------------------------------- | 161 // ---------------------------------------------------------------------------- |
| 162 | 162 |
| 163 | 163 |
| 164 function SetupGlobal() { | 164 function SetupGlobal() { |
| 165 // ECMA 262 - 15.1.1.1. | 165 // ECMA 262 - 15.1.1.1. |
| (...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 if (%_IsConstructCall()) { | 1163 if (%_IsConstructCall()) { |
| 1164 // %NewObjectFromBound implicitly uses arguments passed to this | 1164 // %NewObjectFromBound implicitly uses arguments passed to this |
| 1165 // function. We do not pass the arguments object explicitly to avoid | 1165 // function. We do not pass the arguments object explicitly to avoid |
| 1166 // materializing it and guarantee that this function will be optimized. | 1166 // materializing it and guarantee that this function will be optimized. |
| 1167 return %NewObjectFromBound(fn, null); | 1167 return %NewObjectFromBound(fn, null); |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 return fn.apply(this_arg, arguments); | 1170 return fn.apply(this_arg, arguments); |
| 1171 }; | 1171 }; |
| 1172 } else { | 1172 } else { |
| 1173 var bound_args = new $Array(argc_bound); | 1173 var bound_args = new InternalArray(argc_bound); |
| 1174 for(var i = 0; i < argc_bound; i++) { | 1174 for(var i = 0; i < argc_bound; i++) { |
| 1175 bound_args[i] = %_Arguments(i+1); | 1175 bound_args[i] = %_Arguments(i+1); |
| 1176 } | 1176 } |
| 1177 | 1177 |
| 1178 var result = function() { | 1178 var result = function() { |
| 1179 // If this is a construct call we use a special runtime method | 1179 // If this is a construct call we use a special runtime method |
| 1180 // to generate the actual object using the bound function. | 1180 // to generate the actual object using the bound function. |
| 1181 if (%_IsConstructCall()) { | 1181 if (%_IsConstructCall()) { |
| 1182 // %NewObjectFromBound implicitly uses arguments passed to this | 1182 // %NewObjectFromBound implicitly uses arguments passed to this |
| 1183 // function. We do not pass the arguments object explicitly to avoid | 1183 // function. We do not pass the arguments object explicitly to avoid |
| 1184 // materializing it and guarantee that this function will be optimized. | 1184 // materializing it and guarantee that this function will be optimized. |
| 1185 return %NewObjectFromBound(fn, bound_args); | 1185 return %NewObjectFromBound(fn, bound_args); |
| 1186 } | 1186 } |
| 1187 | 1187 |
| 1188 // Combine the args we got from the bind call with the args | 1188 // Combine the args we got from the bind call with the args |
| 1189 // given as argument to the invocation. | 1189 // given as argument to the invocation. |
| 1190 var argc = %_ArgumentsLength(); | 1190 var argc = %_ArgumentsLength(); |
| 1191 var args = new $Array(argc + argc_bound); | 1191 var args = new InternalArray(argc + argc_bound); |
| 1192 // Add bound arguments. | 1192 // Add bound arguments. |
| 1193 for (var i = 0; i < argc_bound; i++) { | 1193 for (var i = 0; i < argc_bound; i++) { |
| 1194 args[i] = bound_args[i]; | 1194 args[i] = bound_args[i]; |
| 1195 } | 1195 } |
| 1196 // Add arguments from call. | 1196 // Add arguments from call. |
| 1197 for (var i = 0; i < argc; i++) { | 1197 for (var i = 0; i < argc; i++) { |
| 1198 args[argc_bound + i] = %_Arguments(i); | 1198 args[argc_bound + i] = %_Arguments(i); |
| 1199 } | 1199 } |
| 1200 return fn.apply(this_arg, args); | 1200 return fn.apply(this_arg, args); |
| 1201 }; | 1201 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1213 %FunctionSetLength(result, length); | 1213 %FunctionSetLength(result, length); |
| 1214 | 1214 |
| 1215 return result; | 1215 return result; |
| 1216 } | 1216 } |
| 1217 | 1217 |
| 1218 | 1218 |
| 1219 function NewFunction(arg1) { // length == 1 | 1219 function NewFunction(arg1) { // length == 1 |
| 1220 var n = %_ArgumentsLength(); | 1220 var n = %_ArgumentsLength(); |
| 1221 var p = ''; | 1221 var p = ''; |
| 1222 if (n > 1) { | 1222 if (n > 1) { |
| 1223 p = new $Array(n - 1); | 1223 p = new InternalArray(n - 1); |
| 1224 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); | 1224 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); |
| 1225 p = Join(p, n - 1, ',', NonStringToString); | 1225 p = Join(p, n - 1, ',', NonStringToString); |
| 1226 // If the formal parameters string include ) - an illegal | 1226 // If the formal parameters string include ) - an illegal |
| 1227 // character - it may make the combined function expression | 1227 // character - it may make the combined function expression |
| 1228 // compile. We avoid this problem by checking for this early on. | 1228 // compile. We avoid this problem by checking for this early on. |
| 1229 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); | 1229 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); |
| 1230 } | 1230 } |
| 1231 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; | 1231 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; |
| 1232 var source = '(function(' + p + ') {\n' + body + '\n})'; | 1232 var source = '(function(' + p + ') {\n' + body + '\n})'; |
| 1233 | 1233 |
| 1234 // The call to SetNewFunctionAttributes will ensure the prototype | 1234 // The call to SetNewFunctionAttributes will ensure the prototype |
| 1235 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). | 1235 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). |
| 1236 var f = %CompileString(source)(); | 1236 var f = %CompileString(source)(); |
| 1237 %FunctionSetName(f, "anonymous"); | 1237 %FunctionSetName(f, "anonymous"); |
| 1238 return %SetNewFunctionAttributes(f); | 1238 return %SetNewFunctionAttributes(f); |
| 1239 } | 1239 } |
| 1240 | 1240 |
| 1241 %SetCode($Function, NewFunction); | 1241 %SetCode($Function, NewFunction); |
| 1242 | 1242 |
| 1243 // ---------------------------------------------------------------------------- | 1243 // ---------------------------------------------------------------------------- |
| 1244 | 1244 |
| 1245 function SetupFunction() { | 1245 function SetupFunction() { |
| 1246 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1246 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1247 "bind", FunctionBind, | 1247 "bind", FunctionBind, |
| 1248 "toString", FunctionToString | 1248 "toString", FunctionToString |
| 1249 )); | 1249 )); |
| 1250 } | 1250 } |
| 1251 | 1251 |
| 1252 SetupFunction(); | 1252 SetupFunction(); |
| OLD | NEW |