Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 Handle<JSArray> pair = Factory::NewJSArrayWithElements(array); | 300 Handle<JSArray> pair = Factory::NewJSArrayWithElements(array); |
| 301 SetElement(result, match_count, pair); | 301 SetElement(result, match_count, pair); |
| 302 match_count++; | 302 match_count++; |
| 303 index = end; | 303 index = end; |
| 304 if (needle_length == 0) index++; | 304 if (needle_length == 0) index++; |
| 305 } | 305 } |
| 306 return result; | 306 return result; |
| 307 } | 307 } |
| 308 | 308 |
| 309 | 309 |
| 310 static inline Object* DoCompile(String* pattern, | |
| 311 JSRegExp::Flags flags, | |
| 312 unsigned* number_of_captures, | |
| 313 const char** error_message, | |
| 314 JscreRegExp** code) { | |
| 315 JSRegExpIgnoreCaseOption case_option = flags.is_ignore_case() | |
| 316 ? JSRegExpIgnoreCase | |
| 317 : JSRegExpDoNotIgnoreCase; | |
| 318 JSRegExpMultilineOption multiline_option = flags.is_multiline() | |
| 319 ? JSRegExpMultiline | |
| 320 : JSRegExpSingleLine; | |
| 321 *code = NULL; | |
|
Kevin Millikin (Chromium)
2008/10/30 11:10:11
Do you need this?
| |
| 322 *error_message = NULL; | |
| 323 malloc_failure = Failure::Exception(); | |
| 324 *code = jsRegExpCompile(pattern->GetTwoByteData(), | |
| 325 pattern->length(), | |
| 326 case_option, | |
| 327 multiline_option, | |
| 328 number_of_captures, | |
| 329 error_message, | |
| 330 &JSREMalloc, | |
| 331 &JSREFree); | |
| 332 if (code == NULL && (malloc_failure->IsRetryAfterGC() || | |
| 333 malloc_failure->IsOutOfMemoryFailure())) { | |
| 334 return malloc_failure; | |
| 335 } else { | |
| 336 // It doesn't matter which object we return here, we just need to return | |
| 337 // a non-failure to indicate to the GC-retry code that there was no | |
| 338 // allocation failure. | |
| 339 return pattern; | |
| 340 } | |
| 341 } | |
| 342 | |
| 343 | |
| 344 void CompileWithRetryAfterGC(Handle<String> pattern, | |
| 345 JSRegExp::Flags flags, | |
| 346 unsigned* number_of_captures, | |
| 347 const char** error_message, | |
| 348 JscreRegExp** code) { | |
| 349 CALL_HEAP_FUNCTION_VOID(DoCompile(*pattern, | |
| 350 flags, | |
| 351 number_of_captures, | |
| 352 error_message, | |
| 353 code)); | |
| 354 } | |
| 355 | |
| 356 | |
| 310 Handle<Object> RegExpImpl::JsreCompile(Handle<JSRegExp> re, | 357 Handle<Object> RegExpImpl::JsreCompile(Handle<JSRegExp> re, |
| 311 Handle<String> pattern, | 358 Handle<String> pattern, |
| 312 JSRegExp::Flags flags) { | 359 JSRegExp::Flags flags) { |
| 313 JSRegExpIgnoreCaseOption case_option = flags.is_ignore_case() | |
| 314 ? JSRegExpIgnoreCase | |
| 315 : JSRegExpDoNotIgnoreCase; | |
| 316 JSRegExpMultilineOption multiline_option = flags.is_multiline() | |
| 317 ? JSRegExpMultiline | |
| 318 : JSRegExpSingleLine; | |
| 319 | 360 |
| 320 Handle<String> two_byte_pattern = StringToTwoByte(pattern); | 361 Handle<String> two_byte_pattern = StringToTwoByte(pattern); |
| 321 | 362 |
| 322 unsigned number_of_captures; | 363 unsigned number_of_captures; |
| 323 const char* error_message = NULL; | 364 const char* error_message = NULL; |
| 324 | 365 |
| 325 JscreRegExp* code = NULL; | 366 JscreRegExp* code = NULL; |
| 326 FlattenString(pattern); | 367 FlattenString(pattern); |
| 327 | 368 |
| 328 bool first_time = true; | 369 CompileWithRetryAfterGC(two_byte_pattern, |
| 370 flags, | |
| 371 &number_of_captures, | |
| 372 &error_message, | |
| 373 &code); | |
| 329 | 374 |
| 330 while (true) { | 375 if (code == NULL) { |
| 331 malloc_failure = Failure::Exception(); | 376 // Throw an exception. |
| 332 code = jsRegExpCompile(two_byte_pattern->GetTwoByteData(), | 377 Handle<JSArray> array = Factory::NewJSArray(2); |
| 333 pattern->length(), case_option, | 378 SetElement(array, 0, pattern); |
| 334 multiline_option, &number_of_captures, | 379 SetElement(array, 1, Factory::NewStringFromUtf8(CStrVector( |
| 335 &error_message, &JSREMalloc, &JSREFree); | 380 (error_message == NULL) ? "Unknown regexp error" : error_message))); |
| 336 if (code == NULL) { | 381 Handle<Object> regexp_err = |
| 337 if (first_time && malloc_failure->IsRetryAfterGC()) { | 382 Factory::NewSyntaxError("malformed_regexp", array); |
| 338 first_time = false; | 383 return Handle<Object>(Top::Throw(*regexp_err)); |
| 339 if (!Heap::CollectGarbage(malloc_failure->requested(), | 384 } |
| 340 malloc_failure->allocation_space())) { | |
| 341 // TODO(1181417): Fix this. | |
| 342 V8::FatalProcessOutOfMemory("RegExpImpl::JsreCompile"); | |
| 343 } | |
| 344 continue; | |
| 345 } | |
| 346 if (malloc_failure->IsRetryAfterGC() || | |
| 347 malloc_failure->IsOutOfMemoryFailure()) { | |
| 348 // TODO(1181417): Fix this. | |
| 349 V8::FatalProcessOutOfMemory("RegExpImpl::JsreCompile"); | |
| 350 } else { | |
| 351 // Throw an exception. | |
| 352 Handle<JSArray> array = Factory::NewJSArray(2); | |
| 353 SetElement(array, 0, pattern); | |
| 354 SetElement(array, 1, Factory::NewStringFromUtf8(CStrVector( | |
| 355 (error_message == NULL) ? "Unknown regexp error" : error_message))); | |
| 356 Handle<Object> regexp_err = | |
| 357 Factory::NewSyntaxError("malformed_regexp", array); | |
| 358 return Handle<Object>(Top::Throw(*regexp_err)); | |
| 359 } | |
| 360 } | |
| 361 | 385 |
| 362 ASSERT(code != NULL); | 386 // Convert the return address to a ByteArray pointer. |
| 363 // Convert the return address to a ByteArray pointer. | 387 Handle<ByteArray> internal( |
| 364 Handle<ByteArray> internal( | 388 ByteArray::FromDataStartAddress(reinterpret_cast<Address>(code))); |
| 365 ByteArray::FromDataStartAddress(reinterpret_cast<Address>(code))); | |
| 366 | 389 |
| 367 Handle<FixedArray> value = Factory::NewFixedArray(2); | 390 Handle<FixedArray> value = Factory::NewFixedArray(2); |
| 368 value->set(CAPTURE_INDEX, Smi::FromInt(number_of_captures)); | 391 value->set(CAPTURE_INDEX, Smi::FromInt(number_of_captures)); |
| 369 value->set(INTERNAL_INDEX, *internal); | 392 value->set(INTERNAL_INDEX, *internal); |
| 370 Factory::SetRegExpData(re, JSRegExp::JSCRE, pattern, flags, value); | 393 Factory::SetRegExpData(re, JSRegExp::JSCRE, pattern, flags, value); |
| 371 | 394 |
| 372 return re; | 395 return re; |
| 373 } | |
| 374 } | 396 } |
| 375 | 397 |
| 376 | 398 |
| 377 Handle<Object> RegExpImpl::JsreExecOnce(Handle<JSRegExp> regexp, | 399 Handle<Object> RegExpImpl::JsreExecOnce(Handle<JSRegExp> regexp, |
| 378 int num_captures, | 400 int num_captures, |
| 379 Handle<String> subject, | 401 Handle<String> subject, |
| 380 int previous_index, | 402 int previous_index, |
| 381 const uc16* two_byte_subject, | 403 const uc16* two_byte_subject, |
| 382 int* offsets_vector, | 404 int* offsets_vector, |
| 383 int offsets_vector_length) { | 405 int offsets_vector_length) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 return Smi::cast(value->get(CAPTURE_INDEX))->value(); | 563 return Smi::cast(value->get(CAPTURE_INDEX))->value(); |
| 542 } | 564 } |
| 543 | 565 |
| 544 | 566 |
| 545 ByteArray* RegExpImpl::JsreInternal(Handle<JSRegExp> re) { | 567 ByteArray* RegExpImpl::JsreInternal(Handle<JSRegExp> re) { |
| 546 FixedArray* value = FixedArray::cast(re->DataAt(JSRegExp::kJscreDataIndex)); | 568 FixedArray* value = FixedArray::cast(re->DataAt(JSRegExp::kJscreDataIndex)); |
| 547 return ByteArray::cast(value->get(INTERNAL_INDEX)); | 569 return ByteArray::cast(value->get(INTERNAL_INDEX)); |
| 548 } | 570 } |
| 549 | 571 |
| 550 }} // namespace v8::internal | 572 }} // namespace v8::internal |
| OLD | NEW |