Chromium Code Reviews| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 ASSERT(re->data()->IsFixedArray()); | 229 ASSERT(re->data()->IsFixedArray()); |
| 230 // Compilation succeeded so the data is set on the regexp | 230 // Compilation succeeded so the data is set on the regexp |
| 231 // and we can store it in the cache. | 231 // and we can store it in the cache. |
| 232 Handle<FixedArray> data(FixedArray::cast(re->data())); | 232 Handle<FixedArray> data(FixedArray::cast(re->data())); |
| 233 compilation_cache->PutRegExp(pattern, flags, data); | 233 compilation_cache->PutRegExp(pattern, flags, data); |
| 234 | 234 |
| 235 return re; | 235 return re; |
| 236 } | 236 } |
| 237 | 237 |
| 238 | 238 |
| 239 Handle<Object> RegExpImpl::Exec(Handle<JSRegExp> regexp, | 239 MaybeHandle<Object> RegExpImpl::Exec(Handle<JSRegExp> regexp, |
| 240 Handle<String> subject, | 240 Handle<String> subject, |
| 241 int index, | 241 int index, |
| 242 Handle<JSArray> last_match_info) { | 242 Handle<JSArray> last_match_info) { |
| 243 switch (regexp->TypeTag()) { | 243 switch (regexp->TypeTag()) { |
| 244 case JSRegExp::ATOM: | 244 case JSRegExp::ATOM: |
| 245 return AtomExec(regexp, subject, index, last_match_info); | 245 return AtomExec(regexp, subject, index, last_match_info); |
| 246 case JSRegExp::IRREGEXP: { | 246 case JSRegExp::IRREGEXP: { |
| 247 Handle<Object> result = | 247 return IrregexpExec(regexp, subject, index, last_match_info); |
| 248 IrregexpExec(regexp, subject, index, last_match_info); | |
| 249 ASSERT(!result.is_null() || | |
| 250 regexp->GetIsolate()->has_pending_exception()); | |
| 251 return result; | |
| 252 } | 248 } |
| 253 default: | 249 default: |
| 254 UNREACHABLE(); | 250 UNREACHABLE(); |
| 255 return Handle<Object>::null(); | 251 return MaybeHandle<Object>(); |
| 256 } | 252 } |
| 257 } | 253 } |
| 258 | 254 |
| 259 | 255 |
| 260 // RegExp Atom implementation: Simple string search using indexOf. | 256 // RegExp Atom implementation: Simple string search using indexOf. |
| 261 | 257 |
| 262 | 258 |
| 263 void RegExpImpl::AtomCompile(Handle<JSRegExp> re, | 259 void RegExpImpl::AtomCompile(Handle<JSRegExp> re, |
| 264 Handle<String> pattern, | 260 Handle<String> pattern, |
| 265 JSRegExp::Flags flags, | 261 JSRegExp::Flags flags, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 } | 337 } |
| 342 } | 338 } |
| 343 return output_size / 2; | 339 return output_size / 2; |
| 344 } | 340 } |
| 345 | 341 |
| 346 | 342 |
| 347 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, | 343 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, |
| 348 Handle<String> subject, | 344 Handle<String> subject, |
| 349 int index, | 345 int index, |
| 350 Handle<JSArray> last_match_info) { | 346 Handle<JSArray> last_match_info) { |
| 347 ASSERT(!last_match_info.is_null()); | |
|
Yang
2014/04/22 09:27:20
Kind of wonder why you have this. (Or at least, wh
mvstanton
2014/04/22 09:30:19
Indeed, it's unnecessary, thx!
| |
| 351 Isolate* isolate = re->GetIsolate(); | 348 Isolate* isolate = re->GetIsolate(); |
| 352 | 349 |
| 353 static const int kNumRegisters = 2; | 350 static const int kNumRegisters = 2; |
| 354 STATIC_ASSERT(kNumRegisters <= Isolate::kJSRegexpStaticOffsetsVectorSize); | 351 STATIC_ASSERT(kNumRegisters <= Isolate::kJSRegexpStaticOffsetsVectorSize); |
| 355 int32_t* output_registers = isolate->jsregexp_static_offsets_vector(); | 352 int32_t* output_registers = isolate->jsregexp_static_offsets_vector(); |
| 356 | 353 |
| 357 int res = AtomExecRaw(re, subject, index, output_registers, kNumRegisters); | 354 int res = AtomExecRaw(re, subject, index, output_registers, kNumRegisters); |
| 358 | 355 |
| 359 if (res == RegExpImpl::RE_FAILURE) return isolate->factory()->null_value(); | 356 if (res == RegExpImpl::RE_FAILURE) return isolate->factory()->null_value(); |
| 360 | 357 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 634 } | 631 } |
| 635 if (result == RE_EXCEPTION) { | 632 if (result == RE_EXCEPTION) { |
| 636 ASSERT(!isolate->has_pending_exception()); | 633 ASSERT(!isolate->has_pending_exception()); |
| 637 isolate->StackOverflow(); | 634 isolate->StackOverflow(); |
| 638 } | 635 } |
| 639 return result; | 636 return result; |
| 640 #endif // V8_INTERPRETED_REGEXP | 637 #endif // V8_INTERPRETED_REGEXP |
| 641 } | 638 } |
| 642 | 639 |
| 643 | 640 |
| 644 Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> regexp, | 641 MaybeHandle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> regexp, |
| 645 Handle<String> subject, | 642 Handle<String> subject, |
| 646 int previous_index, | 643 int previous_index, |
| 647 Handle<JSArray> last_match_info) { | 644 Handle<JSArray> last_match_info) { |
| 648 Isolate* isolate = regexp->GetIsolate(); | 645 Isolate* isolate = regexp->GetIsolate(); |
| 649 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); | 646 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); |
| 650 | 647 |
| 651 // Prepare space for the return values. | 648 // Prepare space for the return values. |
| 652 #if defined(V8_INTERPRETED_REGEXP) && defined(DEBUG) | 649 #if defined(V8_INTERPRETED_REGEXP) && defined(DEBUG) |
| 653 if (FLAG_trace_regexp_bytecodes) { | 650 if (FLAG_trace_regexp_bytecodes) { |
| 654 String* pattern = regexp->Pattern(); | 651 String* pattern = regexp->Pattern(); |
| 655 PrintF("\n\nRegexp match: /%s/\n\n", pattern->ToCString().get()); | 652 PrintF("\n\nRegexp match: /%s/\n\n", pattern->ToCString().get()); |
| 656 PrintF("\n\nSubject string: '%s'\n\n", subject->ToCString().get()); | 653 PrintF("\n\nSubject string: '%s'\n\n", subject->ToCString().get()); |
| 657 } | 654 } |
| 658 #endif | 655 #endif |
| 659 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); | 656 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); |
| 660 if (required_registers < 0) { | 657 if (required_registers < 0) { |
| 661 // Compiling failed with an exception. | 658 // Compiling failed with an exception. |
| 662 ASSERT(isolate->has_pending_exception()); | 659 ASSERT(isolate->has_pending_exception()); |
| 663 return Handle<Object>::null(); | 660 return MaybeHandle<Object>(); |
| 664 } | 661 } |
| 665 | 662 |
| 666 int32_t* output_registers = NULL; | 663 int32_t* output_registers = NULL; |
| 667 if (required_registers > Isolate::kJSRegexpStaticOffsetsVectorSize) { | 664 if (required_registers > Isolate::kJSRegexpStaticOffsetsVectorSize) { |
| 668 output_registers = NewArray<int32_t>(required_registers); | 665 output_registers = NewArray<int32_t>(required_registers); |
| 669 } | 666 } |
| 670 SmartArrayPointer<int32_t> auto_release(output_registers); | 667 SmartArrayPointer<int32_t> auto_release(output_registers); |
| 671 if (output_registers == NULL) { | 668 if (output_registers == NULL) { |
| 672 output_registers = isolate->jsregexp_static_offsets_vector(); | 669 output_registers = isolate->jsregexp_static_offsets_vector(); |
| 673 } | 670 } |
| 674 | 671 |
| 675 int res = RegExpImpl::IrregexpExecRaw( | 672 int res = RegExpImpl::IrregexpExecRaw( |
| 676 regexp, subject, previous_index, output_registers, required_registers); | 673 regexp, subject, previous_index, output_registers, required_registers); |
| 677 if (res == RE_SUCCESS) { | 674 if (res == RE_SUCCESS) { |
| 678 int capture_count = | 675 int capture_count = |
| 679 IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())); | 676 IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())); |
| 680 return SetLastMatchInfo( | 677 return SetLastMatchInfo( |
| 681 last_match_info, subject, capture_count, output_registers); | 678 last_match_info, subject, capture_count, output_registers); |
| 682 } | 679 } |
| 683 if (res == RE_EXCEPTION) { | 680 if (res == RE_EXCEPTION) { |
| 684 ASSERT(isolate->has_pending_exception()); | 681 ASSERT(isolate->has_pending_exception()); |
| 685 return Handle<Object>::null(); | 682 return MaybeHandle<Object>(); |
| 686 } | 683 } |
| 687 ASSERT(res == RE_FAILURE); | 684 ASSERT(res == RE_FAILURE); |
| 688 return isolate->factory()->null_value(); | 685 return isolate->factory()->null_value(); |
| 689 } | 686 } |
| 690 | 687 |
| 691 | 688 |
| 692 Handle<JSArray> RegExpImpl::SetLastMatchInfo(Handle<JSArray> last_match_info, | 689 Handle<JSArray> RegExpImpl::SetLastMatchInfo(Handle<JSArray> last_match_info, |
| 693 Handle<String> subject, | 690 Handle<String> subject, |
| 694 int capture_count, | 691 int capture_count, |
| 695 int32_t* match) { | 692 int32_t* match) { |
| (...skipping 5433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6129 } | 6126 } |
| 6130 | 6127 |
| 6131 return compiler.Assemble(¯o_assembler, | 6128 return compiler.Assemble(¯o_assembler, |
| 6132 node, | 6129 node, |
| 6133 data->capture_count, | 6130 data->capture_count, |
| 6134 pattern); | 6131 pattern); |
| 6135 } | 6132 } |
| 6136 | 6133 |
| 6137 | 6134 |
| 6138 }} // namespace v8::internal | 6135 }} // namespace v8::internal |
| OLD | NEW |