| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #error Unsupported target architecture. | 53 #error Unsupported target architecture. |
| 54 #endif | 54 #endif |
| 55 #endif | 55 #endif |
| 56 | 56 |
| 57 #include "interpreter-irregexp.h" | 57 #include "interpreter-irregexp.h" |
| 58 | 58 |
| 59 | 59 |
| 60 namespace v8 { | 60 namespace v8 { |
| 61 namespace internal { | 61 namespace internal { |
| 62 | 62 |
| 63 | |
| 64 Handle<Object> RegExpImpl::CreateRegExpLiteral(Handle<JSFunction> constructor, | 63 Handle<Object> RegExpImpl::CreateRegExpLiteral(Handle<JSFunction> constructor, |
| 65 Handle<String> pattern, | 64 Handle<String> pattern, |
| 66 Handle<String> flags, | 65 Handle<String> flags, |
| 67 bool* has_pending_exception) { | 66 bool* has_pending_exception) { |
| 68 // Call the construct code with 2 arguments. | 67 // Call the construct code with 2 arguments. |
| 69 Object** argv[2] = { Handle<Object>::cast(pattern).location(), | 68 Object** argv[2] = { Handle<Object>::cast(pattern).location(), |
| 70 Handle<Object>::cast(flags).location() }; | 69 Handle<Object>::cast(flags).location() }; |
| 71 return Execution::New(constructor, 2, argv, has_pending_exception); | 70 return Execution::New(constructor, 2, argv, has_pending_exception); |
| 72 } | 71 } |
| 73 | 72 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 92 | 91 |
| 93 | 92 |
| 94 static inline void ThrowRegExpException(Handle<JSRegExp> re, | 93 static inline void ThrowRegExpException(Handle<JSRegExp> re, |
| 95 Handle<String> pattern, | 94 Handle<String> pattern, |
| 96 Handle<String> error_text, | 95 Handle<String> error_text, |
| 97 const char* message) { | 96 const char* message) { |
| 98 Handle<JSArray> array = Factory::NewJSArray(2); | 97 Handle<JSArray> array = Factory::NewJSArray(2); |
| 99 SetElement(array, 0, pattern); | 98 SetElement(array, 0, pattern); |
| 100 SetElement(array, 1, error_text); | 99 SetElement(array, 1, error_text); |
| 101 Handle<Object> regexp_err = Factory::NewSyntaxError(message, array); | 100 Handle<Object> regexp_err = Factory::NewSyntaxError(message, array); |
| 102 Isolate::Current()->Throw(*regexp_err); | 101 re->GetIsolate()->Throw(*regexp_err); |
| 103 } | 102 } |
| 104 | 103 |
| 105 | 104 |
| 106 // Generic RegExp methods. Dispatches to implementation specific methods. | 105 // Generic RegExp methods. Dispatches to implementation specific methods. |
| 107 | 106 |
| 108 | 107 |
| 109 Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, | 108 Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, |
| 110 Handle<String> pattern, | 109 Handle<String> pattern, |
| 111 Handle<String> flag_str) { | 110 Handle<String> flag_str) { |
| 112 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); | 111 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); |
| 113 CompilationCache* compilation_cache = Isolate::Current()->compilation_cache(); | 112 CompilationCache* compilation_cache = re->GetIsolate()->compilation_cache(); |
| 114 Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); | 113 Handle<FixedArray> cached = compilation_cache->LookupRegExp(pattern, flags); |
| 115 bool in_cache = !cached.is_null(); | 114 bool in_cache = !cached.is_null(); |
| 116 LOG(RegExpCompileEvent(re, in_cache)); | 115 LOG(RegExpCompileEvent(re, in_cache)); |
| 117 | 116 |
| 118 Handle<Object> result; | 117 Handle<Object> result; |
| 119 if (in_cache) { | 118 if (in_cache) { |
| 120 re->set_data(*cached); | 119 re->set_data(*cached); |
| 121 return re; | 120 return re; |
| 122 } | 121 } |
| 123 FlattenString(pattern); | 122 FlattenString(pattern); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 RegExpImpl::SetLastInput(array, subject); | 201 RegExpImpl::SetLastInput(array, subject); |
| 203 RegExpImpl::SetCapture(array, 0, from); | 202 RegExpImpl::SetCapture(array, 0, from); |
| 204 RegExpImpl::SetCapture(array, 1, to); | 203 RegExpImpl::SetCapture(array, 1, to); |
| 205 } | 204 } |
| 206 | 205 |
| 207 | 206 |
| 208 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, | 207 Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, |
| 209 Handle<String> subject, | 208 Handle<String> subject, |
| 210 int index, | 209 int index, |
| 211 Handle<JSArray> last_match_info) { | 210 Handle<JSArray> last_match_info) { |
| 212 RuntimeState* runtime_state = Isolate::Current()->runtime_state(); | 211 RuntimeState* runtime_state = re->GetIsolate()->runtime_state(); |
| 213 | 212 |
| 214 Handle<String> needle(String::cast(re->DataAt(JSRegExp::kAtomPatternIndex))); | 213 Handle<String> needle(String::cast(re->DataAt(JSRegExp::kAtomPatternIndex))); |
| 215 | 214 |
| 216 uint32_t start_index = index; | 215 uint32_t start_index = index; |
| 217 | 216 |
| 218 int value = Runtime::StringMatch(runtime_state, subject, needle, start_index); | 217 int value = Runtime::StringMatch(runtime_state, subject, needle, start_index); |
| 219 if (value == -1) return Factory::null_value(); | 218 if (value == -1) return Factory::null_value(); |
| 220 ASSERT(last_match_info->HasFastElements()); | 219 ASSERT(last_match_info->HasFastElements()); |
| 221 | 220 |
| 222 { | 221 { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 248 | 247 |
| 249 | 248 |
| 250 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_ascii) { | 249 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_ascii) { |
| 251 // Compile the RegExp. | 250 // Compile the RegExp. |
| 252 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 251 CompilationZoneScope zone_scope(DELETE_ON_EXIT); |
| 253 PostponeInterruptsScope postpone; | 252 PostponeInterruptsScope postpone; |
| 254 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); | 253 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); |
| 255 if (entry->IsJSObject()) { | 254 if (entry->IsJSObject()) { |
| 256 // If it's a JSObject, a previous compilation failed and threw this object. | 255 // If it's a JSObject, a previous compilation failed and threw this object. |
| 257 // Re-throw the object without trying again. | 256 // Re-throw the object without trying again. |
| 258 Isolate::Current()->Throw(entry); | 257 re->GetIsolate()->Throw(entry); |
| 259 return false; | 258 return false; |
| 260 } | 259 } |
| 261 ASSERT(entry->IsTheHole()); | 260 ASSERT(entry->IsTheHole()); |
| 262 | 261 |
| 263 JSRegExp::Flags flags = re->GetFlags(); | 262 JSRegExp::Flags flags = re->GetFlags(); |
| 264 | 263 |
| 265 Handle<String> pattern(re->Pattern()); | 264 Handle<String> pattern(re->Pattern()); |
| 266 if (!pattern->IsFlat()) { | 265 if (!pattern->IsFlat()) { |
| 267 FlattenString(pattern); | 266 FlattenString(pattern); |
| 268 } | 267 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 286 is_ascii); | 285 is_ascii); |
| 287 if (result.error_message != NULL) { | 286 if (result.error_message != NULL) { |
| 288 // Unable to compile regexp. | 287 // Unable to compile regexp. |
| 289 Handle<JSArray> array = Factory::NewJSArray(2); | 288 Handle<JSArray> array = Factory::NewJSArray(2); |
| 290 SetElement(array, 0, pattern); | 289 SetElement(array, 0, pattern); |
| 291 SetElement(array, | 290 SetElement(array, |
| 292 1, | 291 1, |
| 293 Factory::NewStringFromUtf8(CStrVector(result.error_message))); | 292 Factory::NewStringFromUtf8(CStrVector(result.error_message))); |
| 294 Handle<Object> regexp_err = | 293 Handle<Object> regexp_err = |
| 295 Factory::NewSyntaxError("malformed_regexp", array); | 294 Factory::NewSyntaxError("malformed_regexp", array); |
| 296 Isolate::Current()->Throw(*regexp_err); | 295 re->GetIsolate()->Throw(*regexp_err); |
| 297 re->SetDataAt(JSRegExp::code_index(is_ascii), *regexp_err); | 296 re->SetDataAt(JSRegExp::code_index(is_ascii), *regexp_err); |
| 298 return false; | 297 return false; |
| 299 } | 298 } |
| 300 | 299 |
| 301 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data())); | 300 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data())); |
| 302 data->set(JSRegExp::code_index(is_ascii), result.code); | 301 data->set(JSRegExp::code_index(is_ascii), result.code); |
| 303 int register_max = IrregexpMaxRegisterCount(*data); | 302 int register_max = IrregexpMaxRegisterCount(*data); |
| 304 if (result.num_registers > register_max) { | 303 if (result.num_registers > register_max) { |
| 305 SetIrregexpMaxRegisterCount(*data, result.num_registers); | 304 SetIrregexpMaxRegisterCount(*data, result.num_registers); |
| 306 } | 305 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 ASSERT(output.length() >= | 401 ASSERT(output.length() >= |
| 403 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); | 402 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); |
| 404 do { | 403 do { |
| 405 bool is_ascii = subject->IsAsciiRepresentation(); | 404 bool is_ascii = subject->IsAsciiRepresentation(); |
| 406 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii)); | 405 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii)); |
| 407 NativeRegExpMacroAssembler::Result res = | 406 NativeRegExpMacroAssembler::Result res = |
| 408 NativeRegExpMacroAssembler::Match(code, | 407 NativeRegExpMacroAssembler::Match(code, |
| 409 subject, | 408 subject, |
| 410 output.start(), | 409 output.start(), |
| 411 output.length(), | 410 output.length(), |
| 412 index); | 411 index, |
| 412 regexp->GetIsolate()); |
| 413 if (res != NativeRegExpMacroAssembler::RETRY) { | 413 if (res != NativeRegExpMacroAssembler::RETRY) { |
| 414 ASSERT(res != NativeRegExpMacroAssembler::EXCEPTION || | 414 ASSERT(res != NativeRegExpMacroAssembler::EXCEPTION || |
| 415 Isolate::Current()->has_pending_exception()); | 415 Isolate::Current()->has_pending_exception()); |
| 416 STATIC_ASSERT( | 416 STATIC_ASSERT( |
| 417 static_cast<int>(NativeRegExpMacroAssembler::SUCCESS) == RE_SUCCESS); | 417 static_cast<int>(NativeRegExpMacroAssembler::SUCCESS) == RE_SUCCESS); |
| 418 STATIC_ASSERT( | 418 STATIC_ASSERT( |
| 419 static_cast<int>(NativeRegExpMacroAssembler::FAILURE) == RE_FAILURE); | 419 static_cast<int>(NativeRegExpMacroAssembler::FAILURE) == RE_FAILURE); |
| 420 STATIC_ASSERT(static_cast<int>(NativeRegExpMacroAssembler::EXCEPTION) | 420 STATIC_ASSERT(static_cast<int>(NativeRegExpMacroAssembler::EXCEPTION) |
| 421 == RE_EXCEPTION); | 421 == RE_EXCEPTION); |
| 422 return static_cast<IrregexpResult>(res); | 422 return static_cast<IrregexpResult>(res); |
| (...skipping 4826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5249 #endif // V8_INTERPRETED_REGEXP | 5249 #endif // V8_INTERPRETED_REGEXP |
| 5250 | 5250 |
| 5251 return compiler.Assemble(¯o_assembler, | 5251 return compiler.Assemble(¯o_assembler, |
| 5252 node, | 5252 node, |
| 5253 data->capture_count, | 5253 data->capture_count, |
| 5254 pattern); | 5254 pattern); |
| 5255 } | 5255 } |
| 5256 | 5256 |
| 5257 | 5257 |
| 5258 }} // namespace v8::internal | 5258 }} // namespace v8::internal |
| OLD | NEW |