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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 */ | 227 */ |
228 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, | 228 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, |
229 Handle<String> subject, | 229 Handle<String> subject, |
230 int index, | 230 int index, |
231 Handle<JSArray> last_match_info) { | 231 Handle<JSArray> last_match_info) { |
232 Isolate* isolate = re->GetIsolate(); | 232 Isolate* isolate = re->GetIsolate(); |
233 | 233 |
234 ASSERT(0 <= index); | 234 ASSERT(0 <= index); |
235 ASSERT(index <= subject->length()); | 235 ASSERT(index <= subject->length()); |
236 | 236 |
237 if (!subject->IsFlat()) FlattenString(subject); | 237 if (!subject->IsFlatAndTruncated()) FlattenOrTruncateString(subject); |
Vitaly Repeshko
2011/08/05 12:14:14
This doesn't seem necessary. This code can be modi
| |
238 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid | 238 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid |
239 // Extract flattened substrings of cons strings before determining asciiness. | 239 // Extract flattened substrings of cons strings before determining asciiness. |
240 String* seq_sub = *subject; | 240 String* seq_sub = StringShape(*subject).IsIndirect() |
241 if (seq_sub->IsConsString()) seq_sub = ConsString::cast(seq_sub)->first(); | 241 ? subject->GetIndirect() |
242 : *subject; | |
242 | 243 |
243 String* needle = String::cast(re->DataAt(JSRegExp::kAtomPatternIndex)); | 244 String* needle = String::cast(re->DataAt(JSRegExp::kAtomPatternIndex)); |
244 int needle_len = needle->length(); | 245 int needle_len = needle->length(); |
245 | 246 |
246 if (needle_len != 0) { | 247 if (needle_len != 0) { |
247 if (index + needle_len > subject->length()) | 248 if (index + needle_len > subject->length()) |
248 return isolate->factory()->null_value(); | 249 return isolate->factory()->null_value(); |
249 | 250 |
250 // dispatch on type of strings | 251 // dispatch on type of strings |
251 index = (needle->IsAsciiRepresentation() | 252 index = (needle->IsAsciiRepresentation() |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 Object* error_string = re->DataAt(JSRegExp::saved_code_index(is_ascii)); | 349 Object* error_string = re->DataAt(JSRegExp::saved_code_index(is_ascii)); |
349 ASSERT(error_string->IsString()); | 350 ASSERT(error_string->IsString()); |
350 Handle<String> error_message(String::cast(error_string)); | 351 Handle<String> error_message(String::cast(error_string)); |
351 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); | 352 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); |
352 return false; | 353 return false; |
353 } | 354 } |
354 | 355 |
355 JSRegExp::Flags flags = re->GetFlags(); | 356 JSRegExp::Flags flags = re->GetFlags(); |
356 | 357 |
357 Handle<String> pattern(re->Pattern()); | 358 Handle<String> pattern(re->Pattern()); |
358 if (!pattern->IsFlat()) { | 359 if (!pattern->IsFlat()) FlattenString(pattern); |
359 FlattenString(pattern); | |
360 } | |
361 | |
362 RegExpCompileData compile_data; | 360 RegExpCompileData compile_data; |
363 FlatStringReader reader(isolate, pattern); | 361 FlatStringReader reader(isolate, pattern); |
364 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), | 362 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), |
365 &compile_data)) { | 363 &compile_data)) { |
366 // Throw an exception if we fail to parse the pattern. | 364 // Throw an exception if we fail to parse the pattern. |
367 // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. | 365 // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. |
368 ThrowRegExpException(re, | 366 ThrowRegExpException(re, |
369 pattern, | 367 pattern, |
370 compile_data.error, | 368 compile_data.error, |
371 "malformed_regexp"); | 369 "malformed_regexp"); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 re->GetIsolate()->factory()->SetRegExpIrregexpData(re, | 433 re->GetIsolate()->factory()->SetRegExpIrregexpData(re, |
436 JSRegExp::IRREGEXP, | 434 JSRegExp::IRREGEXP, |
437 pattern, | 435 pattern, |
438 flags, | 436 flags, |
439 capture_count); | 437 capture_count); |
440 } | 438 } |
441 | 439 |
442 | 440 |
443 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, | 441 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, |
444 Handle<String> subject) { | 442 Handle<String> subject) { |
445 if (!subject->IsFlat()) { | 443 if (!subject->IsFlatAndTruncated()) FlattenOrTruncateString(subject); |
446 FlattenString(subject); | 444 |
447 } | |
448 // Check the asciiness of the underlying storage. | 445 // Check the asciiness of the underlying storage. |
449 bool is_ascii; | 446 bool is_ascii; |
450 { | 447 { |
451 AssertNoAllocation no_gc; | 448 AssertNoAllocation no_gc; |
452 String* sequential_string = *subject; | 449 String* sequential_string = StringShape(*subject).IsIndirect() |
453 if (subject->IsConsString()) { | 450 ? subject->GetIndirect() |
454 sequential_string = ConsString::cast(*subject)->first(); | 451 : *subject; |
455 } | |
456 is_ascii = sequential_string->IsAsciiRepresentation(); | 452 is_ascii = sequential_string->IsAsciiRepresentation(); |
457 } | 453 } |
458 if (!EnsureCompiledIrregexp(regexp, is_ascii)) { | 454 if (!EnsureCompiledIrregexp(regexp, is_ascii)) { |
459 return -1; | 455 return -1; |
460 } | 456 } |
461 #ifdef V8_INTERPRETED_REGEXP | 457 #ifdef V8_INTERPRETED_REGEXP |
462 // Byte-code regexp needs space allocated for all its registers. | 458 // Byte-code regexp needs space allocated for all its registers. |
463 return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data())); | 459 return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data())); |
464 #else // V8_INTERPRETED_REGEXP | 460 #else // V8_INTERPRETED_REGEXP |
465 // Native regexp only needs room to output captures. Registers are handled | 461 // Native regexp only needs room to output captures. Registers are handled |
466 // internally. | 462 // internally. |
467 return (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2; | 463 return (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2; |
468 #endif // V8_INTERPRETED_REGEXP | 464 #endif // V8_INTERPRETED_REGEXP |
469 } | 465 } |
470 | 466 |
471 | 467 |
472 RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce( | 468 RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce( |
473 Handle<JSRegExp> regexp, | 469 Handle<JSRegExp> regexp, |
474 Handle<String> subject, | 470 Handle<String> subject, |
475 int index, | 471 int index, |
476 Vector<int> output) { | 472 Vector<int> output) { |
477 Isolate* isolate = regexp->GetIsolate(); | 473 Isolate* isolate = regexp->GetIsolate(); |
478 | 474 |
479 Handle<FixedArray> irregexp(FixedArray::cast(regexp->data()), isolate); | 475 Handle<FixedArray> irregexp(FixedArray::cast(regexp->data()), isolate); |
480 | 476 |
481 ASSERT(index >= 0); | 477 ASSERT(index >= 0); |
482 ASSERT(index <= subject->length()); | 478 ASSERT(index <= subject->length()); |
483 ASSERT(subject->IsFlat()); | 479 ASSERT(subject->IsFlat()); |
484 | 480 |
485 // A flat ASCII string might have a two-byte first part. | 481 // A flat ASCII indirect string might actually be two-byte. |
486 if (subject->IsConsString()) { | 482 if (StringShape(*subject).IsIndirect()) { |
487 subject = Handle<String>(ConsString::cast(*subject)->first(), isolate); | 483 subject = Handle<String>(subject->GetIndirect(), isolate); |
488 } | 484 } |
489 | 485 |
490 #ifndef V8_INTERPRETED_REGEXP | 486 #ifndef V8_INTERPRETED_REGEXP |
491 ASSERT(output.length() >= (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); | 487 ASSERT(output.length() >= (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); |
492 do { | 488 do { |
493 bool is_ascii = subject->IsAsciiRepresentation(); | 489 bool is_ascii = subject->IsAsciiRepresentation(); |
494 EnsureCompiledIrregexp(regexp, is_ascii); | 490 EnsureCompiledIrregexp(regexp, is_ascii); |
495 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii), isolate); | 491 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii), isolate); |
496 NativeRegExpMacroAssembler::Result res = | 492 NativeRegExpMacroAssembler::Result res = |
497 NativeRegExpMacroAssembler::Match(code, | 493 NativeRegExpMacroAssembler::Match(code, |
(...skipping 4859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5357 } | 5353 } |
5358 | 5354 |
5359 return compiler.Assemble(¯o_assembler, | 5355 return compiler.Assemble(¯o_assembler, |
5360 node, | 5356 node, |
5361 data->capture_count, | 5357 data->capture_count, |
5362 pattern); | 5358 pattern); |
5363 } | 5359 } |
5364 | 5360 |
5365 | 5361 |
5366 }} // namespace v8::internal | 5362 }} // namespace v8::internal |
OLD | NEW |