| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 Handle<Object> RegExpImpl::Exec(Handle<JSRegExp> regexp, | 168 Handle<Object> RegExpImpl::Exec(Handle<JSRegExp> regexp, |
| 169 Handle<String> subject, | 169 Handle<String> subject, |
| 170 int index, | 170 int index, |
| 171 Handle<JSArray> last_match_info) { | 171 Handle<JSArray> last_match_info) { |
| 172 switch (regexp->TypeTag()) { | 172 switch (regexp->TypeTag()) { |
| 173 case JSRegExp::ATOM: | 173 case JSRegExp::ATOM: |
| 174 return AtomExec(regexp, subject, index, last_match_info); | 174 return AtomExec(regexp, subject, index, last_match_info); |
| 175 case JSRegExp::IRREGEXP: { | 175 case JSRegExp::IRREGEXP: { |
| 176 Handle<Object> result = | 176 Handle<Object> result = |
| 177 IrregexpExec(regexp, subject, index, last_match_info); | 177 IrregexpExec(regexp, subject, index, last_match_info); |
| 178 ASSERT(!result.is_null() || Isolate::Current()->has_pending_exception()); | 178 ASSERT(!result.is_null() || |
| 179 regexp->GetIsolate()->has_pending_exception()); |
| 179 return result; | 180 return result; |
| 180 } | 181 } |
| 181 default: | 182 default: |
| 182 UNREACHABLE(); | 183 UNREACHABLE(); |
| 183 return Handle<Object>::null(); | 184 return Handle<Object>::null(); |
| 184 } | 185 } |
| 185 } | 186 } |
| 186 | 187 |
| 187 | 188 |
| 188 // RegExp Atom implementation: Simple string search using indexOf. | 189 // RegExp Atom implementation: Simple string search using indexOf. |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 } | 521 } |
| 521 return result; | 522 return result; |
| 522 #endif // V8_INTERPRETED_REGEXP | 523 #endif // V8_INTERPRETED_REGEXP |
| 523 } | 524 } |
| 524 | 525 |
| 525 | 526 |
| 526 Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> jsregexp, | 527 Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> jsregexp, |
| 527 Handle<String> subject, | 528 Handle<String> subject, |
| 528 int previous_index, | 529 int previous_index, |
| 529 Handle<JSArray> last_match_info) { | 530 Handle<JSArray> last_match_info) { |
| 531 Isolate* isolate = jsregexp->GetIsolate(); |
| 530 ASSERT_EQ(jsregexp->TypeTag(), JSRegExp::IRREGEXP); | 532 ASSERT_EQ(jsregexp->TypeTag(), JSRegExp::IRREGEXP); |
| 531 | 533 |
| 532 // Prepare space for the return values. | 534 // Prepare space for the return values. |
| 533 #ifdef V8_INTERPRETED_REGEXP | 535 #ifdef V8_INTERPRETED_REGEXP |
| 534 #ifdef DEBUG | 536 #ifdef DEBUG |
| 535 if (FLAG_trace_regexp_bytecodes) { | 537 if (FLAG_trace_regexp_bytecodes) { |
| 536 String* pattern = jsregexp->Pattern(); | 538 String* pattern = jsregexp->Pattern(); |
| 537 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); | 539 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); |
| 538 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); | 540 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); |
| 539 } | 541 } |
| 540 #endif | 542 #endif |
| 541 #endif | 543 #endif |
| 542 int required_registers = RegExpImpl::IrregexpPrepare(jsregexp, subject); | 544 int required_registers = RegExpImpl::IrregexpPrepare(jsregexp, subject); |
| 543 if (required_registers < 0) { | 545 if (required_registers < 0) { |
| 544 // Compiling failed with an exception. | 546 // Compiling failed with an exception. |
| 545 ASSERT(Isolate::Current()->has_pending_exception()); | 547 ASSERT(isolate->has_pending_exception()); |
| 546 return Handle<Object>::null(); | 548 return Handle<Object>::null(); |
| 547 } | 549 } |
| 548 | 550 |
| 549 OffsetsVector registers(required_registers); | 551 OffsetsVector registers(required_registers, isolate); |
| 550 | 552 |
| 551 IrregexpResult res = RegExpImpl::IrregexpExecOnce( | 553 IrregexpResult res = RegExpImpl::IrregexpExecOnce( |
| 552 jsregexp, subject, previous_index, Vector<int>(registers.vector(), | 554 jsregexp, subject, previous_index, Vector<int>(registers.vector(), |
| 553 registers.length())); | 555 registers.length())); |
| 554 if (res == RE_SUCCESS) { | 556 if (res == RE_SUCCESS) { |
| 555 int capture_register_count = | 557 int capture_register_count = |
| 556 (IrregexpNumberOfCaptures(FixedArray::cast(jsregexp->data())) + 1) * 2; | 558 (IrregexpNumberOfCaptures(FixedArray::cast(jsregexp->data())) + 1) * 2; |
| 557 last_match_info->EnsureSize(capture_register_count + kLastMatchOverhead); | 559 last_match_info->EnsureSize(capture_register_count + kLastMatchOverhead); |
| 558 AssertNoAllocation no_gc; | 560 AssertNoAllocation no_gc; |
| 559 int* register_vector = registers.vector(); | 561 int* register_vector = registers.vector(); |
| 560 FixedArray* array = FixedArray::cast(last_match_info->elements()); | 562 FixedArray* array = FixedArray::cast(last_match_info->elements()); |
| 561 for (int i = 0; i < capture_register_count; i += 2) { | 563 for (int i = 0; i < capture_register_count; i += 2) { |
| 562 SetCapture(array, i, register_vector[i]); | 564 SetCapture(array, i, register_vector[i]); |
| 563 SetCapture(array, i + 1, register_vector[i + 1]); | 565 SetCapture(array, i + 1, register_vector[i + 1]); |
| 564 } | 566 } |
| 565 SetLastCaptureCount(array, capture_register_count); | 567 SetLastCaptureCount(array, capture_register_count); |
| 566 SetLastSubject(array, *subject); | 568 SetLastSubject(array, *subject); |
| 567 SetLastInput(array, *subject); | 569 SetLastInput(array, *subject); |
| 568 return last_match_info; | 570 return last_match_info; |
| 569 } | 571 } |
| 570 if (res == RE_EXCEPTION) { | 572 if (res == RE_EXCEPTION) { |
| 571 ASSERT(Isolate::Current()->has_pending_exception()); | 573 ASSERT(isolate->has_pending_exception()); |
| 572 return Handle<Object>::null(); | 574 return Handle<Object>::null(); |
| 573 } | 575 } |
| 574 ASSERT(res == RE_FAILURE); | 576 ASSERT(res == RE_FAILURE); |
| 575 return Isolate::Current()->factory()->null_value(); | 577 return isolate->factory()->null_value(); |
| 576 } | 578 } |
| 577 | 579 |
| 578 | 580 |
| 579 // ------------------------------------------------------------------- | 581 // ------------------------------------------------------------------- |
| 580 // Implementation of the Irregexp regular expression engine. | 582 // Implementation of the Irregexp regular expression engine. |
| 581 // | 583 // |
| 582 // The Irregexp regular expression engine is intended to be a complete | 584 // The Irregexp regular expression engine is intended to be a complete |
| 583 // implementation of ECMAScript regular expressions. It generates either | 585 // implementation of ECMAScript regular expressions. It generates either |
| 584 // bytecodes or native code. | 586 // bytecodes or native code. |
| 585 | 587 |
| (...skipping 4746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5332 } | 5334 } |
| 5333 | 5335 |
| 5334 return compiler.Assemble(¯o_assembler, | 5336 return compiler.Assemble(¯o_assembler, |
| 5335 node, | 5337 node, |
| 5336 data->capture_count, | 5338 data->capture_count, |
| 5337 pattern); | 5339 pattern); |
| 5338 } | 5340 } |
| 5339 | 5341 |
| 5340 | 5342 |
| 5341 }} // namespace v8::internal | 5343 }} // namespace v8::internal |
| OLD | NEW |