| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 CompilationCache* compilation_cache = isolate->compilation_cache(); | 177 CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 178 Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); | 178 Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); |
| 179 bool in_cache = !cached.is_null(); | 179 bool in_cache = !cached.is_null(); |
| 180 LOG(isolate, RegExpCompileEvent(re, in_cache)); | 180 LOG(isolate, RegExpCompileEvent(re, in_cache)); |
| 181 | 181 |
| 182 Handle<Object> result; | 182 Handle<Object> result; |
| 183 if (in_cache) { | 183 if (in_cache) { |
| 184 re->set_data(*cached); | 184 re->set_data(*cached); |
| 185 return re; | 185 return re; |
| 186 } | 186 } |
| 187 pattern = FlattenGetString(pattern); | 187 pattern = String::Flatten(pattern); |
| 188 PostponeInterruptsScope postpone(isolate); | 188 PostponeInterruptsScope postpone(isolate); |
| 189 RegExpCompileData parse_result; | 189 RegExpCompileData parse_result; |
| 190 FlatStringReader reader(isolate, pattern); | 190 FlatStringReader reader(isolate, pattern); |
| 191 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), | 191 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), |
| 192 &parse_result, &zone)) { | 192 &parse_result, &zone)) { |
| 193 // Throw an exception if we fail to parse the pattern. | 193 // Throw an exception if we fail to parse the pattern. |
| 194 ThrowRegExpException(re, | 194 ThrowRegExpException(re, |
| 195 pattern, | 195 pattern, |
| 196 parse_result.error, | 196 parse_result.error, |
| 197 "malformed_regexp"); | 197 "malformed_regexp"); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 int RegExpImpl::AtomExecRaw(Handle<JSRegExp> regexp, | 283 int RegExpImpl::AtomExecRaw(Handle<JSRegExp> regexp, |
| 284 Handle<String> subject, | 284 Handle<String> subject, |
| 285 int index, | 285 int index, |
| 286 int32_t* output, | 286 int32_t* output, |
| 287 int output_size) { | 287 int output_size) { |
| 288 Isolate* isolate = regexp->GetIsolate(); | 288 Isolate* isolate = regexp->GetIsolate(); |
| 289 | 289 |
| 290 ASSERT(0 <= index); | 290 ASSERT(0 <= index); |
| 291 ASSERT(index <= subject->length()); | 291 ASSERT(index <= subject->length()); |
| 292 | 292 |
| 293 if (!subject->IsFlat()) FlattenString(subject); | 293 subject = String::Flatten(subject); |
| 294 DisallowHeapAllocation no_gc; // ensure vectors stay valid | 294 DisallowHeapAllocation no_gc; // ensure vectors stay valid |
| 295 | 295 |
| 296 String* needle = String::cast(regexp->DataAt(JSRegExp::kAtomPatternIndex)); | 296 String* needle = String::cast(regexp->DataAt(JSRegExp::kAtomPatternIndex)); |
| 297 int needle_len = needle->length(); | 297 int needle_len = needle->length(); |
| 298 ASSERT(needle->IsFlat()); | 298 ASSERT(needle->IsFlat()); |
| 299 ASSERT_LT(0, needle_len); | 299 ASSERT_LT(0, needle_len); |
| 300 | 300 |
| 301 if (index + needle_len > subject->length()) { | 301 if (index + needle_len > subject->length()) { |
| 302 return RegExpImpl::RE_FAILURE; | 302 return RegExpImpl::RE_FAILURE; |
| 303 } | 303 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 Object* error_string = re->DataAt(JSRegExp::saved_code_index(is_ascii)); | 432 Object* error_string = re->DataAt(JSRegExp::saved_code_index(is_ascii)); |
| 433 ASSERT(error_string->IsString()); | 433 ASSERT(error_string->IsString()); |
| 434 Handle<String> error_message(String::cast(error_string)); | 434 Handle<String> error_message(String::cast(error_string)); |
| 435 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); | 435 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); |
| 436 return false; | 436 return false; |
| 437 } | 437 } |
| 438 | 438 |
| 439 JSRegExp::Flags flags = re->GetFlags(); | 439 JSRegExp::Flags flags = re->GetFlags(); |
| 440 | 440 |
| 441 Handle<String> pattern(re->Pattern()); | 441 Handle<String> pattern(re->Pattern()); |
| 442 if (!pattern->IsFlat()) FlattenString(pattern); | 442 pattern = String::Flatten(pattern); |
| 443 RegExpCompileData compile_data; | 443 RegExpCompileData compile_data; |
| 444 FlatStringReader reader(isolate, pattern); | 444 FlatStringReader reader(isolate, pattern); |
| 445 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), | 445 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), |
| 446 &compile_data, | 446 &compile_data, |
| 447 &zone)) { | 447 &zone)) { |
| 448 // Throw an exception if we fail to parse the pattern. | 448 // Throw an exception if we fail to parse the pattern. |
| 449 // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. | 449 // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. |
| 450 ThrowRegExpException(re, | 450 ThrowRegExpException(re, |
| 451 pattern, | 451 pattern, |
| 452 compile_data.error, | 452 compile_data.error, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 re->GetIsolate()->factory()->SetRegExpIrregexpData(re, | 521 re->GetIsolate()->factory()->SetRegExpIrregexpData(re, |
| 522 JSRegExp::IRREGEXP, | 522 JSRegExp::IRREGEXP, |
| 523 pattern, | 523 pattern, |
| 524 flags, | 524 flags, |
| 525 capture_count); | 525 capture_count); |
| 526 } | 526 } |
| 527 | 527 |
| 528 | 528 |
| 529 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, | 529 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, |
| 530 Handle<String> subject) { | 530 Handle<String> subject) { |
| 531 if (!subject->IsFlat()) FlattenString(subject); | 531 subject = String::Flatten(subject); |
| 532 | 532 |
| 533 // Check the asciiness of the underlying storage. | 533 // Check the asciiness of the underlying storage. |
| 534 bool is_ascii = subject->IsOneByteRepresentationUnderneath(); | 534 bool is_ascii = subject->IsOneByteRepresentationUnderneath(); |
| 535 if (!EnsureCompiledIrregexp(regexp, subject, is_ascii)) return -1; | 535 if (!EnsureCompiledIrregexp(regexp, subject, is_ascii)) return -1; |
| 536 | 536 |
| 537 #ifdef V8_INTERPRETED_REGEXP | 537 #ifdef V8_INTERPRETED_REGEXP |
| 538 // Byte-code regexp needs space allocated for all its registers. | 538 // Byte-code regexp needs space allocated for all its registers. |
| 539 // The result captures are copied to the start of the registers array | 539 // The result captures are copied to the start of the registers array |
| 540 // if the match succeeds. This way those registers are not clobbered | 540 // if the match succeeds. This way those registers are not clobbered |
| 541 // when we set the last match info from last successful match. | 541 // when we set the last match info from last successful match. |
| (...skipping 5466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6008 bool is_ascii, | 6008 bool is_ascii, |
| 6009 Zone* zone) { | 6009 Zone* zone) { |
| 6010 if ((data->capture_count + 1) * 2 - 1 > RegExpMacroAssembler::kMaxRegister) { | 6010 if ((data->capture_count + 1) * 2 - 1 > RegExpMacroAssembler::kMaxRegister) { |
| 6011 return IrregexpRegExpTooBig(zone->isolate()); | 6011 return IrregexpRegExpTooBig(zone->isolate()); |
| 6012 } | 6012 } |
| 6013 RegExpCompiler compiler(data->capture_count, ignore_case, is_ascii, zone); | 6013 RegExpCompiler compiler(data->capture_count, ignore_case, is_ascii, zone); |
| 6014 | 6014 |
| 6015 // Sample some characters from the middle of the string. | 6015 // Sample some characters from the middle of the string. |
| 6016 static const int kSampleSize = 128; | 6016 static const int kSampleSize = 128; |
| 6017 | 6017 |
| 6018 FlattenString(sample_subject); | 6018 sample_subject = String::Flatten(sample_subject); |
| 6019 int chars_sampled = 0; | 6019 int chars_sampled = 0; |
| 6020 int half_way = (sample_subject->length() - kSampleSize) / 2; | 6020 int half_way = (sample_subject->length() - kSampleSize) / 2; |
| 6021 for (int i = Max(0, half_way); | 6021 for (int i = Max(0, half_way); |
| 6022 i < sample_subject->length() && chars_sampled < kSampleSize; | 6022 i < sample_subject->length() && chars_sampled < kSampleSize; |
| 6023 i++, chars_sampled++) { | 6023 i++, chars_sampled++) { |
| 6024 compiler.frequency_collator()->CountCharacter(sample_subject->Get(i)); | 6024 compiler.frequency_collator()->CountCharacter(sample_subject->Get(i)); |
| 6025 } | 6025 } |
| 6026 | 6026 |
| 6027 // Wrap the body of the regexp in capture #0. | 6027 // Wrap the body of the regexp in capture #0. |
| 6028 RegExpNode* captured_body = RegExpCapture::ToNode(data->tree, | 6028 RegExpNode* captured_body = RegExpCapture::ToNode(data->tree, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6125 } | 6125 } |
| 6126 | 6126 |
| 6127 return compiler.Assemble(¯o_assembler, | 6127 return compiler.Assemble(¯o_assembler, |
| 6128 node, | 6128 node, |
| 6129 data->capture_count, | 6129 data->capture_count, |
| 6130 pattern); | 6130 pattern); |
| 6131 } | 6131 } |
| 6132 | 6132 |
| 6133 | 6133 |
| 6134 }} // namespace v8::internal | 6134 }} // namespace v8::internal |
| OLD | NEW |