| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 return (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2; | 432 return (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2; |
| 433 #endif // V8_INTERPRETED_REGEXP | 433 #endif // V8_INTERPRETED_REGEXP |
| 434 } | 434 } |
| 435 | 435 |
| 436 | 436 |
| 437 RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce( | 437 RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce( |
| 438 Handle<JSRegExp> regexp, | 438 Handle<JSRegExp> regexp, |
| 439 Handle<String> subject, | 439 Handle<String> subject, |
| 440 int index, | 440 int index, |
| 441 Vector<int32_t> output) { | 441 Vector<int32_t> output) { |
| 442 Handle<FixedArray> irregexp(FixedArray::cast(regexp->data())); | 442 Isolate* isolate = regexp->GetIsolate(); |
| 443 |
| 444 Handle<FixedArray> irregexp(FixedArray::cast(regexp->data()), isolate); |
| 443 | 445 |
| 444 ASSERT(index >= 0); | 446 ASSERT(index >= 0); |
| 445 ASSERT(index <= subject->length()); | 447 ASSERT(index <= subject->length()); |
| 446 ASSERT(subject->IsFlat()); | 448 ASSERT(subject->IsFlat()); |
| 447 | 449 |
| 448 // A flat ASCII string might have a two-byte first part. | 450 // A flat ASCII string might have a two-byte first part. |
| 449 if (subject->IsConsString()) { | 451 if (subject->IsConsString()) { |
| 450 subject = Handle<String>(ConsString::cast(*subject)->first()); | 452 subject = Handle<String>(ConsString::cast(*subject)->first(), isolate); |
| 451 } | 453 } |
| 452 | 454 |
| 453 #ifndef V8_INTERPRETED_REGEXP | 455 #ifndef V8_INTERPRETED_REGEXP |
| 454 ASSERT(output.length() >= | 456 ASSERT(output.length() >= (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); |
| 455 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); | |
| 456 do { | 457 do { |
| 457 bool is_ascii = subject->IsAsciiRepresentation(); | 458 bool is_ascii = subject->IsAsciiRepresentation(); |
| 458 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii)); | 459 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii), isolate); |
| 459 NativeRegExpMacroAssembler::Result res = | 460 NativeRegExpMacroAssembler::Result res = |
| 460 NativeRegExpMacroAssembler::Match(code, | 461 NativeRegExpMacroAssembler::Match(code, |
| 461 subject, | 462 subject, |
| 462 output.start(), | 463 output.start(), |
| 463 output.length(), | 464 output.length(), |
| 464 index, | 465 index, |
| 465 regexp->GetIsolate()); | 466 isolate); |
| 466 if (res != NativeRegExpMacroAssembler::RETRY) { | 467 if (res != NativeRegExpMacroAssembler::RETRY) { |
| 467 ASSERT(res != NativeRegExpMacroAssembler::EXCEPTION || | 468 ASSERT(res != NativeRegExpMacroAssembler::EXCEPTION || |
| 468 Isolate::Current()->has_pending_exception()); | 469 isolate->has_pending_exception()); |
| 469 STATIC_ASSERT( | 470 STATIC_ASSERT( |
| 470 static_cast<int>(NativeRegExpMacroAssembler::SUCCESS) == RE_SUCCESS); | 471 static_cast<int>(NativeRegExpMacroAssembler::SUCCESS) == RE_SUCCESS); |
| 471 STATIC_ASSERT( | 472 STATIC_ASSERT( |
| 472 static_cast<int>(NativeRegExpMacroAssembler::FAILURE) == RE_FAILURE); | 473 static_cast<int>(NativeRegExpMacroAssembler::FAILURE) == RE_FAILURE); |
| 473 STATIC_ASSERT(static_cast<int>(NativeRegExpMacroAssembler::EXCEPTION) | 474 STATIC_ASSERT(static_cast<int>(NativeRegExpMacroAssembler::EXCEPTION) |
| 474 == RE_EXCEPTION); | 475 == RE_EXCEPTION); |
| 475 return static_cast<IrregexpResult>(res); | 476 return static_cast<IrregexpResult>(res); |
| 476 } | 477 } |
| 477 // If result is RETRY, the string has changed representation, and we | 478 // If result is RETRY, the string has changed representation, and we |
| 478 // must restart from scratch. | 479 // must restart from scratch. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 489 ASSERT(output.length() >= IrregexpNumberOfRegisters(*irregexp)); | 490 ASSERT(output.length() >= IrregexpNumberOfRegisters(*irregexp)); |
| 490 bool is_ascii = subject->IsAsciiRepresentation(); | 491 bool is_ascii = subject->IsAsciiRepresentation(); |
| 491 // We must have done EnsureCompiledIrregexp, so we can get the number of | 492 // We must have done EnsureCompiledIrregexp, so we can get the number of |
| 492 // registers. | 493 // registers. |
| 493 int* register_vector = output.start(); | 494 int* register_vector = output.start(); |
| 494 int number_of_capture_registers = | 495 int number_of_capture_registers = |
| 495 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2; | 496 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2; |
| 496 for (int i = number_of_capture_registers - 1; i >= 0; i--) { | 497 for (int i = number_of_capture_registers - 1; i >= 0; i--) { |
| 497 register_vector[i] = -1; | 498 register_vector[i] = -1; |
| 498 } | 499 } |
| 499 Handle<ByteArray> byte_codes(IrregexpByteCode(*irregexp, is_ascii)); | 500 Handle<ByteArray> byte_codes(IrregexpByteCode(*irregexp, is_ascii), isolate); |
| 500 | 501 |
| 501 if (IrregexpInterpreter::Match(byte_codes, | 502 if (IrregexpInterpreter::Match(byte_codes, |
| 502 subject, | 503 subject, |
| 503 register_vector, | 504 register_vector, |
| 504 index)) { | 505 index)) { |
| 505 return RE_SUCCESS; | 506 return RE_SUCCESS; |
| 506 } | 507 } |
| 507 return RE_FAILURE; | 508 return RE_FAILURE; |
| 508 #endif // V8_INTERPRETED_REGEXP | 509 #endif // V8_INTERPRETED_REGEXP |
| 509 } | 510 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 SetLastCaptureCount(array, capture_register_count); | 552 SetLastCaptureCount(array, capture_register_count); |
| 552 SetLastSubject(array, *subject); | 553 SetLastSubject(array, *subject); |
| 553 SetLastInput(array, *subject); | 554 SetLastInput(array, *subject); |
| 554 return last_match_info; | 555 return last_match_info; |
| 555 } | 556 } |
| 556 if (res == RE_EXCEPTION) { | 557 if (res == RE_EXCEPTION) { |
| 557 ASSERT(Isolate::Current()->has_pending_exception()); | 558 ASSERT(Isolate::Current()->has_pending_exception()); |
| 558 return Handle<Object>::null(); | 559 return Handle<Object>::null(); |
| 559 } | 560 } |
| 560 ASSERT(res == RE_FAILURE); | 561 ASSERT(res == RE_FAILURE); |
| 561 return FACTORY->null_value(); | 562 return Isolate::Current()->factory()->null_value(); |
| 562 } | 563 } |
| 563 | 564 |
| 564 | 565 |
| 565 // ------------------------------------------------------------------- | 566 // ------------------------------------------------------------------- |
| 566 // Implementation of the Irregexp regular expression engine. | 567 // Implementation of the Irregexp regular expression engine. |
| 567 // | 568 // |
| 568 // The Irregexp regular expression engine is intended to be a complete | 569 // The Irregexp regular expression engine is intended to be a complete |
| 569 // implementation of ECMAScript regular expressions. It generates either | 570 // implementation of ECMAScript regular expressions. It generates either |
| 570 // bytecodes or native code. | 571 // bytecodes or native code. |
| 571 | 572 |
| (...skipping 4780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5352 } | 5353 } |
| 5353 | 5354 |
| 5354 return compiler.Assemble(¯o_assembler, | 5355 return compiler.Assemble(¯o_assembler, |
| 5355 node, | 5356 node, |
| 5356 data->capture_count, | 5357 data->capture_count, |
| 5357 pattern); | 5358 pattern); |
| 5358 } | 5359 } |
| 5359 | 5360 |
| 5360 | 5361 |
| 5361 }} // namespace v8::internal | 5362 }} // namespace v8::internal |
| OLD | NEW |