| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/conversions-inl.h" | 8 #include "src/conversions-inl.h" |
| 9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 MUST_USE_RESULT static Object* StringReplaceGlobalRegExpWithString( | 480 MUST_USE_RESULT static Object* StringReplaceGlobalRegExpWithString( |
| 481 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> regexp, | 481 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> regexp, |
| 482 Handle<String> replacement, Handle<RegExpMatchInfo> last_match_info) { | 482 Handle<String> replacement, Handle<RegExpMatchInfo> last_match_info) { |
| 483 DCHECK(subject->IsFlat()); | 483 DCHECK(subject->IsFlat()); |
| 484 DCHECK(replacement->IsFlat()); | 484 DCHECK(replacement->IsFlat()); |
| 485 | 485 |
| 486 int capture_count = regexp->CaptureCount(); | 486 int capture_count = regexp->CaptureCount(); |
| 487 int subject_length = subject->length(); | 487 int subject_length = subject->length(); |
| 488 | 488 |
| 489 // CompiledReplacement uses zone allocation. | 489 // CompiledReplacement uses zone allocation. |
| 490 Zone zone(isolate->allocator()); | 490 Zone zone(isolate->allocator(), ZONE_NAME); |
| 491 CompiledReplacement compiled_replacement(&zone); | 491 CompiledReplacement compiled_replacement(&zone); |
| 492 bool simple_replace = | 492 bool simple_replace = |
| 493 compiled_replacement.Compile(replacement, capture_count, subject_length); | 493 compiled_replacement.Compile(replacement, capture_count, subject_length); |
| 494 | 494 |
| 495 // Shortcut for simple non-regexp global replacements | 495 // Shortcut for simple non-regexp global replacements |
| 496 if (regexp->TypeTag() == JSRegExp::ATOM && simple_replace) { | 496 if (regexp->TypeTag() == JSRegExp::ATOM && simple_replace) { |
| 497 if (subject->HasOnlyOneByteChars() && replacement->HasOnlyOneByteChars()) { | 497 if (subject->HasOnlyOneByteChars() && replacement->HasOnlyOneByteChars()) { |
| 498 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>( | 498 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>( |
| 499 isolate, subject, regexp, replacement, last_match_info); | 499 isolate, subject, regexp, replacement, last_match_info); |
| 500 } else { | 500 } else { |
| (...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1510 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1511 isolate, exec, JSObject::GetProperty( | 1511 isolate, exec, JSObject::GetProperty( |
| 1512 recv, factory->NewStringFromAsciiChecked("exec"))); | 1512 recv, factory->NewStringFromAsciiChecked("exec"))); |
| 1513 if (RegExpUtils::IsBuiltinExec(exec)) { | 1513 if (RegExpUtils::IsBuiltinExec(exec)) { |
| 1514 RETURN_RESULT_OR_FAILURE( | 1514 RETURN_RESULT_OR_FAILURE( |
| 1515 isolate, RegExpReplace(isolate, Handle<JSRegExp>::cast(recv), string, | 1515 isolate, RegExpReplace(isolate, Handle<JSRegExp>::cast(recv), string, |
| 1516 replace_obj)); | 1516 replace_obj)); |
| 1517 } | 1517 } |
| 1518 } | 1518 } |
| 1519 | 1519 |
| 1520 Zone zone(isolate->allocator()); | 1520 Zone zone(isolate->allocator(), ZONE_NAME); |
| 1521 ZoneVector<Handle<Object>> results(&zone); | 1521 ZoneVector<Handle<Object>> results(&zone); |
| 1522 | 1522 |
| 1523 while (true) { | 1523 while (true) { |
| 1524 Handle<Object> result; | 1524 Handle<Object> result; |
| 1525 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1525 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1526 isolate, result, RegExpUtils::RegExpExec(isolate, recv, string, exec)); | 1526 isolate, result, RegExpUtils::RegExpExec(isolate, recv, string, exec)); |
| 1527 | 1527 |
| 1528 // Ensure exec will be read again on the next loop through. | 1528 // Ensure exec will be read again on the next loop through. |
| 1529 exec = factory->undefined_value(); | 1529 exec = factory->undefined_value(); |
| 1530 | 1530 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 | 1652 |
| 1653 RUNTIME_FUNCTION(Runtime_IsRegExp) { | 1653 RUNTIME_FUNCTION(Runtime_IsRegExp) { |
| 1654 SealHandleScope shs(isolate); | 1654 SealHandleScope shs(isolate); |
| 1655 DCHECK(args.length() == 1); | 1655 DCHECK(args.length() == 1); |
| 1656 CONVERT_ARG_CHECKED(Object, obj, 0); | 1656 CONVERT_ARG_CHECKED(Object, obj, 0); |
| 1657 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); | 1657 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); |
| 1658 } | 1658 } |
| 1659 | 1659 |
| 1660 } // namespace internal | 1660 } // namespace internal |
| 1661 } // namespace v8 | 1661 } // namespace v8 |
| OLD | NEW |