Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: src/runtime/runtime-regexp.cc

Issue 2438283002: Revert of [regexp] Use consistent map checks for fast paths (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/regexp/regexp-utils.cc ('k') | test/mjsunit/es6/regexp-flags.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 DCHECK(args.length() == 3); 1493 DCHECK(args.length() == 3);
1494 1494
1495 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, recv, 0); 1495 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, recv, 0);
1496 CONVERT_ARG_HANDLE_CHECKED(String, string, 1); 1496 CONVERT_ARG_HANDLE_CHECKED(String, string, 1);
1497 Handle<Object> replace_obj = args.at<Object>(2); 1497 Handle<Object> replace_obj = args.at<Object>(2);
1498 1498
1499 Factory* factory = isolate->factory(); 1499 Factory* factory = isolate->factory();
1500 1500
1501 string = String::Flatten(string); 1501 string = String::Flatten(string);
1502 1502
1503 // Fast-path for unmodified JSRegExps.
1504 if (RegExpUtils::IsUnmodifiedRegExp(isolate, recv)) {
1505 RETURN_RESULT_OR_FAILURE(
1506 isolate, RegExpReplace(isolate, Handle<JSRegExp>::cast(recv), string,
1507 replace_obj));
1508 }
1509
1510 const int length = string->length(); 1503 const int length = string->length();
1511 const bool functional_replace = replace_obj->IsCallable(); 1504 const bool functional_replace = replace_obj->IsCallable();
1512 1505
1513 Handle<String> replace; 1506 Handle<String> replace;
1514 if (!functional_replace) { 1507 if (!functional_replace) {
1515 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, replace, 1508 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, replace,
1516 Object::ToString(isolate, replace_obj)); 1509 Object::ToString(isolate, replace_obj));
1517 } 1510 }
1518 1511
1519 Handle<Object> global_obj; 1512 Handle<Object> global_obj;
1520 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1513 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1521 isolate, global_obj, 1514 isolate, global_obj,
1522 JSReceiver::GetProperty(recv, factory->global_string())); 1515 JSReceiver::GetProperty(recv, factory->global_string()));
1523 const bool global = global_obj->BooleanValue(); 1516 const bool global = global_obj->BooleanValue();
1524 1517
1525 bool unicode = false; 1518 bool unicode = false;
1526 if (global) { 1519 if (global) {
1527 Handle<Object> unicode_obj; 1520 Handle<Object> unicode_obj;
1528 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1521 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1529 isolate, unicode_obj, 1522 isolate, unicode_obj,
1530 JSReceiver::GetProperty(recv, factory->unicode_string())); 1523 JSReceiver::GetProperty(recv, factory->unicode_string()));
1531 unicode = unicode_obj->BooleanValue(); 1524 unicode = unicode_obj->BooleanValue();
1532 1525
1533 RETURN_FAILURE_ON_EXCEPTION(isolate, 1526 RETURN_FAILURE_ON_EXCEPTION(isolate,
1534 RegExpUtils::SetLastIndex(isolate, recv, 0)); 1527 RegExpUtils::SetLastIndex(isolate, recv, 0));
1535 } 1528 }
1536 1529
1530 // TODO(jgruber): Here and at all other fast path checks, rely on map checks
1531 // instead.
1532 // TODO(jgruber): We could speed up the fast path by checking flags
1533 // afterwards, but that would violate the spec (which states that exec is
1534 // accessed after global and unicode).
1535 // TODO(adamk): this fast path is wrong as we doesn't ensure that 'exec'
1536 // is actually a data property on RegExp.prototype.
1537 Handle<Object> exec = factory->undefined_value();
1538 if (recv->IsJSRegExp()) {
1539 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1540 isolate, exec, JSObject::GetProperty(
1541 recv, factory->NewStringFromAsciiChecked("exec")));
1542 if (RegExpUtils::IsBuiltinExec(exec)) {
1543 RETURN_RESULT_OR_FAILURE(
1544 isolate, RegExpReplace(isolate, Handle<JSRegExp>::cast(recv), string,
1545 replace_obj));
1546 }
1547 }
1548
1537 Zone zone(isolate->allocator(), ZONE_NAME); 1549 Zone zone(isolate->allocator(), ZONE_NAME);
1538 ZoneVector<Handle<Object>> results(&zone); 1550 ZoneVector<Handle<Object>> results(&zone);
1539 1551
1540 while (true) { 1552 while (true) {
1541 Handle<Object> result; 1553 Handle<Object> result;
1542 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1554 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1543 isolate, result, RegExpUtils::RegExpExec(isolate, recv, string, 1555 isolate, result, RegExpUtils::RegExpExec(isolate, recv, string, exec));
1544 factory->undefined_value())); 1556
1557 // Ensure exec will be read again on the next loop through.
1558 exec = factory->undefined_value();
1545 1559
1546 if (result->IsNull(isolate)) break; 1560 if (result->IsNull(isolate)) break;
1547 1561
1548 results.push_back(result); 1562 results.push_back(result);
1549 if (!global) break; 1563 if (!global) break;
1550 1564
1551 Handle<Object> match_obj; 1565 Handle<Object> match_obj;
1552 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, match_obj, 1566 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, match_obj,
1553 Object::GetElement(isolate, result, 0)); 1567 Object::GetElement(isolate, result, 0));
1554 1568
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 1681
1668 RUNTIME_FUNCTION(Runtime_IsRegExp) { 1682 RUNTIME_FUNCTION(Runtime_IsRegExp) {
1669 SealHandleScope shs(isolate); 1683 SealHandleScope shs(isolate);
1670 DCHECK(args.length() == 1); 1684 DCHECK(args.length() == 1);
1671 CONVERT_ARG_CHECKED(Object, obj, 0); 1685 CONVERT_ARG_CHECKED(Object, obj, 0);
1672 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); 1686 return isolate->heap()->ToBoolean(obj->IsJSRegExp());
1673 } 1687 }
1674 1688
1675 } // namespace internal 1689 } // namespace internal
1676 } // namespace v8 1690 } // namespace v8
OLDNEW
« no previous file with comments | « src/regexp/regexp-utils.cc ('k') | test/mjsunit/es6/regexp-flags.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698