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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 194 } |
195 }); | 195 }); |
196 | 196 |
197 | 197 |
198 // ---------------------------------------------------------------------------- | 198 // ---------------------------------------------------------------------------- |
199 // Global stuff... | 199 // Global stuff... |
200 | 200 |
201 %AddProperty(global, "eval", function(x) { | 201 %AddProperty(global, "eval", function(x) { |
202 if (!IS_STRING(x)) return x; | 202 if (!IS_STRING(x)) return x; |
203 | 203 |
204 var f = %CompileString(x, true); | 204 var f = %CompileString(x, 0, true); |
205 if (!IS_FUNCTION(f)) return f; | 205 if (!IS_FUNCTION(f)) return f; |
206 | 206 |
207 return f.call(%EvalReceiver(this)); | 207 return f.call(%EvalReceiver(this)); |
208 }, DONT_ENUM); | 208 }, DONT_ENUM); |
209 | 209 |
210 | 210 |
211 // execScript for IE compatibility. | 211 // execScript for IE compatibility. |
212 %AddProperty(global, "execScript", function(expr, lang) { | 212 %AddProperty(global, "execScript", function(expr, lang) { |
213 // NOTE: We don't care about the character casing. | 213 // NOTE: We don't care about the character casing. |
214 if (!lang || /javascript/i.test(lang)) { | 214 if (!lang || /javascript/i.test(lang)) { |
215 var f = %CompileString(ToString(expr), false); | 215 var f = %CompileString(ToString(expr), 0, false); |
216 f.call(global); | 216 f.call(global); |
217 } | 217 } |
218 return null; | 218 return null; |
219 }, DONT_ENUM); | 219 }, DONT_ENUM); |
220 | 220 |
221 | 221 |
222 // ---------------------------------------------------------------------------- | 222 // ---------------------------------------------------------------------------- |
223 // Boolean | 223 // Boolean |
224 | 224 |
225 %AddProperty($Boolean.prototype, "toString", function() { | 225 %AddProperty($Boolean.prototype, "toString", function() { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 // Array.prototype.join replaces null with empty strings which is | 399 // Array.prototype.join replaces null with empty strings which is |
400 // not appropriate. | 400 // not appropriate. |
401 for (var i = 0; i < n - 1; i++) p[i] = ToString(%_Arguments(i)); | 401 for (var i = 0; i < n - 1; i++) p[i] = ToString(%_Arguments(i)); |
402 p = p.join(','); | 402 p = p.join(','); |
403 // If the formal parameters string include ) - an illegal | 403 // If the formal parameters string include ) - an illegal |
404 // character - it may make the combined function expression | 404 // character - it may make the combined function expression |
405 // compile. We avoid this problem by checking for this early on. | 405 // compile. We avoid this problem by checking for this early on. |
406 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); | 406 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); |
407 } | 407 } |
408 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; | 408 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; |
409 var source = '(function anonymous(' + p + ') { ' + body + ' })'; | 409 var source = '(function(' + p + ') {\n' + body + '\n})'; |
410 | 410 |
411 // The call to SetNewFunctionAttributes will ensure the prototype | 411 // The call to SetNewFunctionAttributes will ensure the prototype |
412 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). | 412 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). |
413 return %SetNewFunctionAttributes(%CompileString(source, false)()); | 413 var f = %CompileString(source, -1, false)(); |
| 414 %FunctionSetName(f, "anonymous"); |
| 415 return %SetNewFunctionAttributes(f); |
414 }; | 416 }; |
415 | 417 |
416 %SetCode($Function, NewFunction); | 418 %SetCode($Function, NewFunction); |
OLD | NEW |