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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 | 114 |
115 function GlobalEval(x) { | 115 function GlobalEval(x) { |
116 if (!IS_STRING(x)) return x; | 116 if (!IS_STRING(x)) return x; |
117 | 117 |
118 if (this !== global && this !== %GlobalReceiver(global)) { | 118 if (this !== global && this !== %GlobalReceiver(global)) { |
119 throw new $EvalError('The "this" object passed to eval must ' + | 119 throw new $EvalError('The "this" object passed to eval must ' + |
120 'be the global object from which eval originated'); | 120 'be the global object from which eval originated'); |
121 } | 121 } |
122 | 122 |
123 var f = %CompileString(x, 0, false); | 123 var f = %CompileString(x, false); |
124 if (!IS_FUNCTION(f)) return f; | 124 if (!IS_FUNCTION(f)) return f; |
125 | 125 |
126 return f.call(this); | 126 return f.call(this); |
127 } | 127 } |
128 | 128 |
129 | 129 |
130 // execScript for IE compatibility. | 130 // execScript for IE compatibility. |
131 function GlobalExecScript(expr, lang) { | 131 function GlobalExecScript(expr, lang) { |
132 // NOTE: We don't care about the character casing. | 132 // NOTE: We don't care about the character casing. |
133 if (!lang || /javascript/i.test(lang)) { | 133 if (!lang || /javascript/i.test(lang)) { |
134 var f = %CompileString(ToString(expr), 0, false); | 134 var f = %CompileString(ToString(expr), false); |
135 f.call(%GlobalReceiver(global)); | 135 f.call(%GlobalReceiver(global)); |
136 } | 136 } |
137 return null; | 137 return null; |
138 } | 138 } |
139 | 139 |
140 | 140 |
141 // ---------------------------------------------------------------------------- | 141 // ---------------------------------------------------------------------------- |
142 | 142 |
143 | 143 |
144 function SetupGlobal() { | 144 function SetupGlobal() { |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 // If the formal parameters string include ) - an illegal | 543 // If the formal parameters string include ) - an illegal |
544 // character - it may make the combined function expression | 544 // character - it may make the combined function expression |
545 // compile. We avoid this problem by checking for this early on. | 545 // compile. We avoid this problem by checking for this early on. |
546 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); | 546 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); |
547 } | 547 } |
548 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; | 548 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; |
549 var source = '(function(' + p + ') {\n' + body + '\n})'; | 549 var source = '(function(' + p + ') {\n' + body + '\n})'; |
550 | 550 |
551 // The call to SetNewFunctionAttributes will ensure the prototype | 551 // The call to SetNewFunctionAttributes will ensure the prototype |
552 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). | 552 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). |
553 var f = %CompileString(source, -1, false)(); | 553 var f = %CompileString(source, false)(); |
554 %FunctionSetName(f, "anonymous"); | 554 %FunctionSetName(f, "anonymous"); |
555 return %SetNewFunctionAttributes(f); | 555 return %SetNewFunctionAttributes(f); |
556 } | 556 } |
557 | 557 |
558 %SetCode($Function, NewFunction); | 558 %SetCode($Function, NewFunction); |
559 | 559 |
560 // ---------------------------------------------------------------------------- | 560 // ---------------------------------------------------------------------------- |
561 | 561 |
562 function SetupFunction() { | 562 function SetupFunction() { |
563 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 563 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
564 "toString", FunctionToString | 564 "toString", FunctionToString |
565 )); | 565 )); |
566 } | 566 } |
567 | 567 |
568 SetupFunction(); | 568 SetupFunction(); |
569 | 569 |
OLD | NEW |