| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 160 } |
| 161 return true; | 161 return true; |
| 162 } | 162 } |
| 163 | 163 |
| 164 | 164 |
| 165 // Generic RegExp methods. Dispatches to implementation specific methods. | 165 // Generic RegExp methods. Dispatches to implementation specific methods. |
| 166 | 166 |
| 167 | 167 |
| 168 Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, | 168 Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, |
| 169 Handle<String> pattern, | 169 Handle<String> pattern, |
| 170 Handle<String> flag_str) { | 170 Handle<String> flag_str, |
| 171 Zone* zone) { |
| 172 ZoneScope zone_scope(zone, DELETE_ON_EXIT); |
| 171 Isolate* isolate = re->GetIsolate(); | 173 Isolate* isolate = re->GetIsolate(); |
| 172 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); | 174 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); |
| 173 CompilationCache* compilation_cache = isolate->compilation_cache(); | 175 CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 174 Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); | 176 Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); |
| 175 bool in_cache = !cached.is_null(); | 177 bool in_cache = !cached.is_null(); |
| 176 LOG(isolate, RegExpCompileEvent(re, in_cache)); | 178 LOG(isolate, RegExpCompileEvent(re, in_cache)); |
| 177 | 179 |
| 178 Handle<Object> result; | 180 Handle<Object> result; |
| 179 if (in_cache) { | 181 if (in_cache) { |
| 180 re->set_data(*cached); | 182 re->set_data(*cached); |
| 181 return re; | 183 return re; |
| 182 } | 184 } |
| 183 pattern = FlattenGetString(pattern); | 185 pattern = FlattenGetString(pattern); |
| 184 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | |
| 185 PostponeInterruptsScope postpone(isolate); | 186 PostponeInterruptsScope postpone(isolate); |
| 186 RegExpCompileData parse_result; | 187 RegExpCompileData parse_result; |
| 187 FlatStringReader reader(isolate, pattern); | 188 FlatStringReader reader(isolate, pattern); |
| 188 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), | 189 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), |
| 189 &parse_result)) { | 190 &parse_result, zone)) { |
| 190 // Throw an exception if we fail to parse the pattern. | 191 // Throw an exception if we fail to parse the pattern. |
| 191 ThrowRegExpException(re, | 192 ThrowRegExpException(re, |
| 192 pattern, | 193 pattern, |
| 193 parse_result.error, | 194 parse_result.error, |
| 194 "malformed_regexp"); | 195 "malformed_regexp"); |
| 195 return Handle<Object>::null(); | 196 return Handle<Object>::null(); |
| 196 } | 197 } |
| 197 | 198 |
| 198 bool has_been_compiled = false; | 199 bool has_been_compiled = false; |
| 199 | 200 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 isolate->Throw(*regexp_err); | 379 isolate->Throw(*regexp_err); |
| 379 return false; | 380 return false; |
| 380 } | 381 } |
| 381 | 382 |
| 382 | 383 |
| 383 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, | 384 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, |
| 384 Handle<String> sample_subject, | 385 Handle<String> sample_subject, |
| 385 bool is_ascii) { | 386 bool is_ascii) { |
| 386 // Compile the RegExp. | 387 // Compile the RegExp. |
| 387 Isolate* isolate = re->GetIsolate(); | 388 Isolate* isolate = re->GetIsolate(); |
| 388 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 389 ZoneScope zone_scope(isolate->runtime_zone(), DELETE_ON_EXIT); |
| 389 PostponeInterruptsScope postpone(isolate); | 390 PostponeInterruptsScope postpone(isolate); |
| 390 // If we had a compilation error the last time this is saved at the | 391 // If we had a compilation error the last time this is saved at the |
| 391 // saved code index. | 392 // saved code index. |
| 392 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); | 393 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); |
| 393 // When arriving here entry can only be a smi, either representing an | 394 // When arriving here entry can only be a smi, either representing an |
| 394 // uncompiled regexp, a previous compilation error, or code that has | 395 // uncompiled regexp, a previous compilation error, or code that has |
| 395 // been flushed. | 396 // been flushed. |
| 396 ASSERT(entry->IsSmi()); | 397 ASSERT(entry->IsSmi()); |
| 397 int entry_value = Smi::cast(entry)->value(); | 398 int entry_value = Smi::cast(entry)->value(); |
| 398 ASSERT(entry_value == JSRegExp::kUninitializedValue || | 399 ASSERT(entry_value == JSRegExp::kUninitializedValue || |
| (...skipping 10 matching lines...) Expand all Loading... |
| 409 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); | 410 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); |
| 410 return false; | 411 return false; |
| 411 } | 412 } |
| 412 | 413 |
| 413 JSRegExp::Flags flags = re->GetFlags(); | 414 JSRegExp::Flags flags = re->GetFlags(); |
| 414 | 415 |
| 415 Handle<String> pattern(re->Pattern()); | 416 Handle<String> pattern(re->Pattern()); |
| 416 if (!pattern->IsFlat()) FlattenString(pattern); | 417 if (!pattern->IsFlat()) FlattenString(pattern); |
| 417 RegExpCompileData compile_data; | 418 RegExpCompileData compile_data; |
| 418 FlatStringReader reader(isolate, pattern); | 419 FlatStringReader reader(isolate, pattern); |
| 420 Zone* zone = isolate->runtime_zone(); |
| 419 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), | 421 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), |
| 420 &compile_data)) { | 422 &compile_data, |
| 423 zone)) { |
| 421 // Throw an exception if we fail to parse the pattern. | 424 // Throw an exception if we fail to parse the pattern. |
| 422 // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. | 425 // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. |
| 423 ThrowRegExpException(re, | 426 ThrowRegExpException(re, |
| 424 pattern, | 427 pattern, |
| 425 compile_data.error, | 428 compile_data.error, |
| 426 "malformed_regexp"); | 429 "malformed_regexp"); |
| 427 return false; | 430 return false; |
| 428 } | 431 } |
| 429 RegExpEngine::CompilationResult result = | 432 RegExpEngine::CompilationResult result = |
| 430 RegExpEngine::Compile(&compile_data, | 433 RegExpEngine::Compile(&compile_data, |
| 431 flags.is_ignore_case(), | 434 flags.is_ignore_case(), |
| 432 flags.is_global(), | 435 flags.is_global(), |
| 433 flags.is_multiline(), | 436 flags.is_multiline(), |
| 434 pattern, | 437 pattern, |
| 435 sample_subject, | 438 sample_subject, |
| 436 is_ascii, | 439 is_ascii, |
| 437 isolate->zone()); | 440 zone); |
| 438 if (result.error_message != NULL) { | 441 if (result.error_message != NULL) { |
| 439 // Unable to compile regexp. | 442 // Unable to compile regexp. |
| 440 Handle<String> error_message = | 443 Handle<String> error_message = |
| 441 isolate->factory()->NewStringFromUtf8(CStrVector(result.error_message)); | 444 isolate->factory()->NewStringFromUtf8(CStrVector(result.error_message)); |
| 442 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); | 445 CreateRegExpErrorObjectAndThrow(re, is_ascii, error_message, isolate); |
| 443 return false; | 446 return false; |
| 444 } | 447 } |
| 445 | 448 |
| 446 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data())); | 449 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data())); |
| 447 data->set(JSRegExp::code_index(is_ascii), result.code); | 450 data->set(JSRegExp::code_index(is_ascii), result.code); |
| (...skipping 5552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6000 } | 6003 } |
| 6001 | 6004 |
| 6002 return compiler.Assemble(¯o_assembler, | 6005 return compiler.Assemble(¯o_assembler, |
| 6003 node, | 6006 node, |
| 6004 data->capture_count, | 6007 data->capture_count, |
| 6005 pattern); | 6008 pattern); |
| 6006 } | 6009 } |
| 6007 | 6010 |
| 6008 | 6011 |
| 6009 }} // namespace v8::internal | 6012 }} // namespace v8::internal |
| OLD | NEW |