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 // Only allow non-global compiles for eval. | 95 // Only allow non-global compiles for eval. |
96 ASSERT(is_eval || is_global); | 96 ASSERT(is_eval || is_global); |
97 | 97 |
98 // Build AST. | 98 // Build AST. |
99 FunctionLiteral* lit = MakeAST(is_global, script, extension, pre_data); | 99 FunctionLiteral* lit = MakeAST(is_global, script, extension, pre_data); |
100 | 100 |
101 // Check for parse errors. | 101 // Check for parse errors. |
102 if (lit == NULL) { | 102 if (lit == NULL) { |
103 ASSERT(Top::has_pending_exception()); | 103 ASSERT(Top::has_pending_exception()); |
104 Top::ReportPendingMessages(); | |
105 return Handle<JSFunction>::null(); | 104 return Handle<JSFunction>::null(); |
106 } | 105 } |
107 | 106 |
108 // Measure how long it takes to do the compilation; only take the | 107 // Measure how long it takes to do the compilation; only take the |
109 // rest of the function into account to avoid overlap with the | 108 // rest of the function into account to avoid overlap with the |
110 // parsing statistics. | 109 // parsing statistics. |
111 StatsRate* rate = is_eval | 110 StatsRate* rate = is_eval |
112 ? &Counters::compile_eval | 111 ? &Counters::compile_eval |
113 : &Counters::compile; | 112 : &Counters::compile; |
114 StatsRateScope timer(rate); | 113 StatsRateScope timer(rate); |
115 | 114 |
116 // Compile the code. | 115 // Compile the code. |
117 Handle<Code> code = MakeCode(lit, script, is_eval); | 116 Handle<Code> code = MakeCode(lit, script, is_eval); |
118 | 117 |
119 // Check for stack-overflow exceptions. | 118 // Check for stack-overflow exceptions. |
120 if (code.is_null()) { | 119 if (code.is_null()) { |
121 Top::StackOverflow(); | 120 Top::StackOverflow(); |
122 Top::ReportPendingMessages(); | |
123 return Handle<JSFunction>::null(); | 121 return Handle<JSFunction>::null(); |
124 } | 122 } |
125 | 123 |
126 if (script->name()->IsString()) { | 124 if (script->name()->IsString()) { |
127 SmartPointer<char> data = | 125 SmartPointer<char> data = |
128 String::cast(script->name())->ToCString(DISALLOW_NULLS); | 126 String::cast(script->name())->ToCString(DISALLOW_NULLS); |
129 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, *data)); | 127 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, *data)); |
130 } else { | 128 } else { |
131 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, "")); | 129 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, "")); |
132 } | 130 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if (extension == NULL && !result.is_null()) { | 199 if (extension == NULL && !result.is_null()) { |
202 CompilationCache::PutFunction(source, CompilationCache::SCRIPT, result); | 200 CompilationCache::PutFunction(source, CompilationCache::SCRIPT, result); |
203 } | 201 } |
204 | 202 |
205 // Get rid of the pre-parsing data (if necessary). | 203 // Get rid of the pre-parsing data (if necessary). |
206 if (input_pre_data == NULL && pre_data != NULL) { | 204 if (input_pre_data == NULL && pre_data != NULL) { |
207 delete pre_data; | 205 delete pre_data; |
208 } | 206 } |
209 } | 207 } |
210 | 208 |
| 209 if (result.is_null()) Top::ReportPendingMessages(); |
| 210 |
211 return result; | 211 return result; |
212 } | 212 } |
213 | 213 |
214 | 214 |
215 Handle<JSFunction> Compiler::CompileEval(Handle<String> source, | 215 Handle<JSFunction> Compiler::CompileEval(Handle<String> source, |
216 int line_offset, | 216 int line_offset, |
217 bool is_global) { | 217 bool is_global) { |
218 int source_length = source->length(); | 218 int source_length = source->length(); |
219 Counters::total_eval_size.Increment(source_length); | 219 Counters::total_eval_size.Increment(source_length); |
220 Counters::total_compile_size.Increment(source_length); | 220 Counters::total_compile_size.Increment(source_length); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 // Generate the AST for the lazily compiled function. The AST may be | 265 // Generate the AST for the lazily compiled function. The AST may be |
266 // NULL in case of parser stack overflow. | 266 // NULL in case of parser stack overflow. |
267 FunctionLiteral* lit = MakeLazyAST(script, name, | 267 FunctionLiteral* lit = MakeLazyAST(script, name, |
268 start_position, | 268 start_position, |
269 end_position, | 269 end_position, |
270 is_expression); | 270 is_expression); |
271 | 271 |
272 // Check for parse errors. | 272 // Check for parse errors. |
273 if (lit == NULL) { | 273 if (lit == NULL) { |
274 ASSERT(Top::has_pending_exception()); | 274 ASSERT(Top::has_pending_exception()); |
275 Top::ReportPendingMessages(); | |
276 return false; | 275 return false; |
277 } | 276 } |
278 | 277 |
279 // Update the loop nesting in the function literal. | 278 // Update the loop nesting in the function literal. |
280 lit->set_loop_nesting(loop_nesting); | 279 lit->set_loop_nesting(loop_nesting); |
281 | 280 |
282 // Measure how long it takes to do the lazy compilation; only take | 281 // Measure how long it takes to do the lazy compilation; only take |
283 // the rest of the function into account to avoid overlap with the | 282 // the rest of the function into account to avoid overlap with the |
284 // lazy parsing statistics. | 283 // lazy parsing statistics. |
285 StatsRateScope timer(&Counters::compile_lazy); | 284 StatsRateScope timer(&Counters::compile_lazy); |
286 | 285 |
287 // Compile the code. | 286 // Compile the code. |
288 Handle<Code> code = MakeCode(lit, script, false); | 287 Handle<Code> code = MakeCode(lit, script, false); |
289 | 288 |
290 // Check for stack-overflow exception. | 289 // Check for stack-overflow exception. |
291 if (code.is_null()) { | 290 if (code.is_null()) { |
292 Top::StackOverflow(); | 291 Top::StackOverflow(); |
293 Top::ReportPendingMessages(); | |
294 return false; | 292 return false; |
295 } | 293 } |
296 | 294 |
297 // Generate the code, update the function info, and return the code. | 295 // Generate the code, update the function info, and return the code. |
298 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name())); | 296 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name())); |
299 | 297 |
300 // Update the shared function info with the compiled code. | 298 // Update the shared function info with the compiled code. |
301 shared->set_code(*code); | 299 shared->set_code(*code); |
302 | 300 |
303 // Set the expected number of properties for instances. | 301 // Set the expected number of properties for instances. |
304 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 302 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
305 | 303 |
306 // Check the function has compiled code. | 304 // Check the function has compiled code. |
307 ASSERT(shared->is_compiled()); | 305 ASSERT(shared->is_compiled()); |
308 return true; | 306 return true; |
309 } | 307 } |
310 | 308 |
311 | 309 |
312 } } // namespace v8::internal | 310 } } // namespace v8::internal |
OLD | NEW |