OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 161 } |
162 return true; | 162 return true; |
163 } | 163 } |
164 | 164 |
165 | 165 |
166 // Generic RegExp methods. Dispatches to implementation specific methods. | 166 // Generic RegExp methods. Dispatches to implementation specific methods. |
167 | 167 |
168 | 168 |
169 Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, | 169 Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, |
170 Handle<String> pattern, | 170 Handle<String> pattern, |
171 Handle<String> flag_str, | 171 Handle<String> flag_str) { |
172 Zone* zone) { | |
173 ZoneScope zone_scope(zone); | |
174 Isolate* isolate = re->GetIsolate(); | 172 Isolate* isolate = re->GetIsolate(); |
| 173 Zone zone(isolate); |
175 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); | 174 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); |
176 CompilationCache* compilation_cache = isolate->compilation_cache(); | 175 CompilationCache* compilation_cache = isolate->compilation_cache(); |
177 Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); | 176 Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); |
178 bool in_cache = !cached.is_null(); | 177 bool in_cache = !cached.is_null(); |
179 LOG(isolate, RegExpCompileEvent(re, in_cache)); | 178 LOG(isolate, RegExpCompileEvent(re, in_cache)); |
180 | 179 |
181 Handle<Object> result; | 180 Handle<Object> result; |
182 if (in_cache) { | 181 if (in_cache) { |
183 re->set_data(*cached); | 182 re->set_data(*cached); |
184 return re; | 183 return re; |
185 } | 184 } |
186 pattern = FlattenGetString(pattern); | 185 pattern = FlattenGetString(pattern); |
187 PostponeInterruptsScope postpone(isolate); | 186 PostponeInterruptsScope postpone(isolate); |
188 RegExpCompileData parse_result; | 187 RegExpCompileData parse_result; |
189 FlatStringReader reader(isolate, pattern); | 188 FlatStringReader reader(isolate, pattern); |
190 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), | 189 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), |
191 &parse_result, zone)) { | 190 &parse_result, &zone)) { |
192 // Throw an exception if we fail to parse the pattern. | 191 // Throw an exception if we fail to parse the pattern. |
193 ThrowRegExpException(re, | 192 ThrowRegExpException(re, |
194 pattern, | 193 pattern, |
195 parse_result.error, | 194 parse_result.error, |
196 "malformed_regexp"); | 195 "malformed_regexp"); |
197 return Handle<Object>::null(); | 196 return Handle<Object>::null(); |
198 } | 197 } |
199 | 198 |
200 bool has_been_compiled = false; | 199 bool has_been_compiled = false; |
201 | 200 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 isolate->Throw(*regexp_err); | 402 isolate->Throw(*regexp_err); |
404 return false; | 403 return false; |
405 } | 404 } |
406 | 405 |
407 | 406 |
408 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, | 407 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, |
409 Handle<String> sample_subject, | 408 Handle<String> sample_subject, |
410 bool is_ascii) { | 409 bool is_ascii) { |
411 // Compile the RegExp. | 410 // Compile the RegExp. |
412 Isolate* isolate = re->GetIsolate(); | 411 Isolate* isolate = re->GetIsolate(); |
413 ZoneScope zone_scope(isolate->runtime_zone()); | 412 Zone zone(isolate); |
414 PostponeInterruptsScope postpone(isolate); | 413 PostponeInterruptsScope postpone(isolate); |
415 // If we had a compilation error the last time this is saved at the | 414 // If we had a compilation error the last time this is saved at the |
416 // saved code index. | 415 // saved code index. |
417 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); | 416 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); |
418 // When arriving here entry can only be a smi, either representing an | 417 // When arriving here entry can only be a smi, either representing an |
419 // uncompiled regexp, a previous compilation error, or code that has | 418 // uncompiled regexp, a previous compilation error, or code that has |
420 // been flushed. | 419 // been flushed. |
421 ASSERT(entry->IsSmi()); | 420 ASSERT(entry->IsSmi()); |
422 int entry_value = Smi::cast(entry)->value(); | 421 int entry_value = Smi::cast(entry)->value(); |
423 ASSERT(entry_value == JSRegExp::kUninitializedValue || | 422 ASSERT(entry_value == JSRegExp::kUninitializedValue || |
(...skipping 10 matching lines...) Expand all Loading... |
434 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); | 433 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); |
435 return false; | 434 return false; |
436 } | 435 } |
437 | 436 |
438 JSRegExp::Flags flags = re->GetFlags(); | 437 JSRegExp::Flags flags = re->GetFlags(); |
439 | 438 |
440 Handle<String> pattern(re->Pattern()); | 439 Handle<String> pattern(re->Pattern()); |
441 if (!pattern->IsFlat()) FlattenString(pattern); | 440 if (!pattern->IsFlat()) FlattenString(pattern); |
442 RegExpCompileData compile_data; | 441 RegExpCompileData compile_data; |
443 FlatStringReader reader(isolate, pattern); | 442 FlatStringReader reader(isolate, pattern); |
444 Zone* zone = isolate->runtime_zone(); | |
445 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), | 443 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), |
446 &compile_data, | 444 &compile_data, |
447 zone)) { | 445 &zone)) { |
448 // Throw an exception if we fail to parse the pattern. | 446 // Throw an exception if we fail to parse the pattern. |
449 // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. | 447 // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. |
450 ThrowRegExpException(re, | 448 ThrowRegExpException(re, |
451 pattern, | 449 pattern, |
452 compile_data.error, | 450 compile_data.error, |
453 "malformed_regexp"); | 451 "malformed_regexp"); |
454 return false; | 452 return false; |
455 } | 453 } |
456 RegExpEngine::CompilationResult result = | 454 RegExpEngine::CompilationResult result = |
457 RegExpEngine::Compile(&compile_data, | 455 RegExpEngine::Compile(&compile_data, |
458 flags.is_ignore_case(), | 456 flags.is_ignore_case(), |
459 flags.is_global(), | 457 flags.is_global(), |
460 flags.is_multiline(), | 458 flags.is_multiline(), |
461 pattern, | 459 pattern, |
462 sample_subject, | 460 sample_subject, |
463 is_ascii, | 461 is_ascii, |
464 zone); | 462 &zone); |
465 if (result.error_message != NULL) { | 463 if (result.error_message != NULL) { |
466 // Unable to compile regexp. | 464 // Unable to compile regexp. |
467 Handle<String> error_message = | 465 Handle<String> error_message = |
468 isolate->factory()->NewStringFromUtf8(CStrVector(result.error_message)); | 466 isolate->factory()->NewStringFromUtf8(CStrVector(result.error_message)); |
469 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); | 467 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); |
470 return false; | 468 return false; |
471 } | 469 } |
472 | 470 |
473 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data())); | 471 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data())); |
474 data->set(JSRegExp::code_index(is_ascii), result.code); | 472 data->set(JSRegExp::code_index(is_ascii), result.code); |
(...skipping 5648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6123 } | 6121 } |
6124 | 6122 |
6125 return compiler.Assemble(¯o_assembler, | 6123 return compiler.Assemble(¯o_assembler, |
6126 node, | 6124 node, |
6127 data->capture_count, | 6125 data->capture_count, |
6128 pattern); | 6126 pattern); |
6129 } | 6127 } |
6130 | 6128 |
6131 | 6129 |
6132 }} // namespace v8::internal | 6130 }} // namespace v8::internal |
OLD | NEW |