| 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) { |
| 171 Isolate* isolate = re->GetIsolate(); | 172 Isolate* isolate = re->GetIsolate(); |
| 172 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); | 173 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); |
| 173 CompilationCache* compilation_cache = isolate->compilation_cache(); | 174 CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 174 Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); | 175 Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); |
| 175 bool in_cache = !cached.is_null(); | 176 bool in_cache = !cached.is_null(); |
| 176 LOG(isolate, RegExpCompileEvent(re, in_cache)); | 177 LOG(isolate, RegExpCompileEvent(re, in_cache)); |
| 177 | 178 |
| 178 Handle<Object> result; | 179 Handle<Object> result; |
| 179 if (in_cache) { | 180 if (in_cache) { |
| 180 re->set_data(*cached); | 181 re->set_data(*cached); |
| 181 return re; | 182 return re; |
| 182 } | 183 } |
| 183 pattern = FlattenGetString(pattern); | 184 pattern = FlattenGetString(pattern); |
| 184 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | |
| 185 PostponeInterruptsScope postpone(isolate); | 185 PostponeInterruptsScope postpone(isolate); |
| 186 RegExpCompileData parse_result; | 186 RegExpCompileData parse_result; |
| 187 FlatStringReader reader(isolate, pattern); | 187 FlatStringReader reader(isolate, pattern); |
| 188 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), | 188 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), |
| 189 &parse_result)) { | 189 &parse_result, zone)) { |
| 190 // Throw an exception if we fail to parse the pattern. | 190 // Throw an exception if we fail to parse the pattern. |
| 191 ThrowRegExpException(re, | 191 ThrowRegExpException(re, |
| 192 pattern, | 192 pattern, |
| 193 parse_result.error, | 193 parse_result.error, |
| 194 "malformed_regexp"); | 194 "malformed_regexp"); |
| 195 return Handle<Object>::null(); | 195 return Handle<Object>::null(); |
| 196 } | 196 } |
| 197 | 197 |
| 198 bool has_been_compiled = false; | 198 bool has_been_compiled = false; |
| 199 | 199 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 return false; | 381 return false; |
| 382 } | 382 } |
| 383 | 383 |
| 384 | 384 |
| 385 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, | 385 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, |
| 386 Handle<String> sample_subject, | 386 Handle<String> sample_subject, |
| 387 bool is_ascii, | 387 bool is_ascii, |
| 388 Zone* zone) { | 388 Zone* zone) { |
| 389 // Compile the RegExp. | 389 // Compile the RegExp. |
| 390 Isolate* isolate = re->GetIsolate(); | 390 Isolate* isolate = re->GetIsolate(); |
| 391 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 391 ZoneScope zone_scope(zone, DELETE_ON_EXIT); |
| 392 PostponeInterruptsScope postpone(isolate); | 392 PostponeInterruptsScope postpone(isolate); |
| 393 // If we had a compilation error the last time this is saved at the | 393 // If we had a compilation error the last time this is saved at the |
| 394 // saved code index. | 394 // saved code index. |
| 395 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); | 395 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); |
| 396 // When arriving here entry can only be a smi, either representing an | 396 // When arriving here entry can only be a smi, either representing an |
| 397 // uncompiled regexp, a previous compilation error, or code that has | 397 // uncompiled regexp, a previous compilation error, or code that has |
| 398 // been flushed. | 398 // been flushed. |
| 399 ASSERT(entry->IsSmi()); | 399 ASSERT(entry->IsSmi()); |
| 400 int entry_value = Smi::cast(entry)->value(); | 400 int entry_value = Smi::cast(entry)->value(); |
| 401 ASSERT(entry_value == JSRegExp::kUninitializedValue || | 401 ASSERT(entry_value == JSRegExp::kUninitializedValue || |
| (...skipping 11 matching lines...) Expand all Loading... |
| 413 return false; | 413 return false; |
| 414 } | 414 } |
| 415 | 415 |
| 416 JSRegExp::Flags flags = re->GetFlags(); | 416 JSRegExp::Flags flags = re->GetFlags(); |
| 417 | 417 |
| 418 Handle<String> pattern(re->Pattern()); | 418 Handle<String> pattern(re->Pattern()); |
| 419 if (!pattern->IsFlat()) FlattenString(pattern); | 419 if (!pattern->IsFlat()) FlattenString(pattern); |
| 420 RegExpCompileData compile_data; | 420 RegExpCompileData compile_data; |
| 421 FlatStringReader reader(isolate, pattern); | 421 FlatStringReader reader(isolate, pattern); |
| 422 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), | 422 if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), |
| 423 &compile_data)) { | 423 &compile_data, |
| 424 zone)) { |
| 424 // Throw an exception if we fail to parse the pattern. | 425 // Throw an exception if we fail to parse the pattern. |
| 425 // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. | 426 // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. |
| 426 ThrowRegExpException(re, | 427 ThrowRegExpException(re, |
| 427 pattern, | 428 pattern, |
| 428 compile_data.error, | 429 compile_data.error, |
| 429 "malformed_regexp"); | 430 "malformed_regexp"); |
| 430 return false; | 431 return false; |
| 431 } | 432 } |
| 432 RegExpEngine::CompilationResult result = | 433 RegExpEngine::CompilationResult result = |
| 433 RegExpEngine::Compile(&compile_data, | 434 RegExpEngine::Compile(&compile_data, |
| (...skipping 5573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6007 } | 6008 } |
| 6008 | 6009 |
| 6009 return compiler.Assemble(¯o_assembler, | 6010 return compiler.Assemble(¯o_assembler, |
| 6010 node, | 6011 node, |
| 6011 data->capture_count, | 6012 data->capture_count, |
| 6012 pattern); | 6013 pattern); |
| 6013 } | 6014 } |
| 6014 | 6015 |
| 6015 | 6016 |
| 6016 }} // namespace v8::internal | 6017 }} // namespace v8::internal |
| OLD | NEW |