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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 94 } |
95 return %StringParseInt(ToString(string), radix); | 95 return %StringParseInt(ToString(string), radix); |
96 } | 96 } |
97 | 97 |
98 | 98 |
99 // ECMA-262 - 15.1.2.3 | 99 // ECMA-262 - 15.1.2.3 |
100 function GlobalParseFloat(string) { | 100 function GlobalParseFloat(string) { |
101 return %StringParseFloat(ToString(string)); | 101 return %StringParseFloat(ToString(string)); |
102 } | 102 } |
103 | 103 |
104 | |
105 function GlobalEval(x) { | 104 function GlobalEval(x) { |
106 if (!IS_STRING(x)) return x; | 105 if (!IS_STRING(x)) return x; |
107 | 106 |
108 if (this !== %GlobalReceiver(global)) { | 107 if (this !== %GlobalReceiver(global)) { |
109 throw new $EvalError('The "this" object passed to eval must ' + | 108 throw new $EvalError('The "this" object passed to eval must ' + |
110 'be the global object from which eval originated'); | 109 'be the global object from which eval originated'); |
111 } | 110 } |
112 | 111 |
113 var f = %CompileString(x, 0, true); | 112 if (%InDirectEval()) { |
| 113 return %ExecDirectEval(x); |
| 114 } |
| 115 |
| 116 var f = %CompileString(x, 0); |
114 if (!IS_FUNCTION(f)) return f; | 117 if (!IS_FUNCTION(f)) return f; |
115 | 118 |
116 return f.call(%EvalReceiver(this)); | 119 return f.call(this); |
117 } | 120 } |
118 | 121 |
119 | 122 |
120 // execScript for IE compatibility. | 123 // execScript for IE compatibility. |
121 function GlobalExecScript(expr, lang) { | 124 function GlobalExecScript(expr, lang) { |
122 // NOTE: We don't care about the character casing. | 125 // NOTE: We don't care about the character casing. |
123 if (!lang || /javascript/i.test(lang)) { | 126 if (!lang || /javascript/i.test(lang)) { |
124 var f = %CompileString(ToString(expr), 0, false); | 127 var f = %CompileString(ToString(expr), 0); |
125 f.call(%GlobalReceiver(global)); | 128 f.call(%GlobalReceiver(global)); |
126 } | 129 } |
127 return null; | 130 return null; |
128 } | 131 } |
129 | 132 |
130 | 133 |
131 // ---------------------------------------------------------------------------- | 134 // ---------------------------------------------------------------------------- |
132 | 135 |
133 | 136 |
134 function SetupGlobal() { | 137 function SetupGlobal() { |
135 // ECMA 262 - 15.1.1.1. | 138 // ECMA 262 - 15.1.1.1. |
136 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); | 139 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); |
137 | 140 |
138 // ECMA-262 - 15.1.1.2. | 141 // ECMA-262 - 15.1.1.2. |
139 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE); | 142 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE); |
140 | 143 |
141 // ECMA-262 - 15.1.1.3. | 144 // ECMA-262 - 15.1.1.3. |
142 %SetProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE); | 145 %SetProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE); |
143 | 146 |
144 // Setup non-enumerable function on the global object. | 147 // Setup non-enumerable function on the global object. |
145 InstallFunctions(global, DONT_ENUM, $Array( | 148 InstallFunctions(global, DONT_ENUM, $Array( |
146 "isNaN", GlobalIsNaN, | 149 "isNaN", GlobalIsNaN, |
147 "isFinite", GlobalIsFinite, | 150 "isFinite", GlobalIsFinite, |
148 "parseInt", GlobalParseInt, | 151 "parseInt", GlobalParseInt, |
149 "parseFloat", GlobalParseFloat, | 152 "parseFloat", GlobalParseFloat, |
150 "eval", GlobalEval, | 153 "eval", GlobalEval, |
151 "execScript", GlobalExecScript | 154 "execScript", GlobalExecScript |
152 )); | 155 )); |
153 } | 156 } |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 // If the formal parameters string include ) - an illegal | 517 // If the formal parameters string include ) - an illegal |
515 // character - it may make the combined function expression | 518 // character - it may make the combined function expression |
516 // compile. We avoid this problem by checking for this early on. | 519 // compile. We avoid this problem by checking for this early on. |
517 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); | 520 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); |
518 } | 521 } |
519 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; | 522 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; |
520 var source = '(function(' + p + ') {\n' + body + '\n})'; | 523 var source = '(function(' + p + ') {\n' + body + '\n})'; |
521 | 524 |
522 // The call to SetNewFunctionAttributes will ensure the prototype | 525 // The call to SetNewFunctionAttributes will ensure the prototype |
523 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). | 526 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). |
524 var f = %CompileString(source, -1, false)(); | 527 var f = %CompileString(source, -1)(); |
525 %FunctionSetName(f, "anonymous"); | 528 %FunctionSetName(f, "anonymous"); |
526 return %SetNewFunctionAttributes(f); | 529 return %SetNewFunctionAttributes(f); |
527 } | 530 } |
528 | 531 |
529 %SetCode($Function, NewFunction); | 532 %SetCode($Function, NewFunction); |
530 | 533 |
531 // ---------------------------------------------------------------------------- | 534 // ---------------------------------------------------------------------------- |
532 | 535 |
533 function SetupFunction() { | 536 function SetupFunction() { |
534 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 537 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
535 "toString", FunctionToString | 538 "toString", FunctionToString |
536 )); | 539 )); |
537 } | 540 } |
538 | 541 |
539 SetupFunction(); | 542 SetupFunction(); |
540 | 543 |
OLD | NEW |