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

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

Issue 2415663007: [regexp] RegExp.prototype.replace fast-paths (Closed)
Patch Set: Remove unused variable Created 4 years, 2 months 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
« src/builtins/builtins-regexp.cc ('K') | « src/runtime/runtime.h ('k') | no next file » | 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 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 replace_obj); 1454 replace_obj);
1455 } 1455 }
1456 } 1456 }
1457 1457
1458 UNREACHABLE(); 1458 UNREACHABLE();
1459 return MaybeHandle<String>(); 1459 return MaybeHandle<String>();
1460 } 1460 }
1461 1461
1462 } // namespace 1462 } // namespace
1463 1463
1464 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithFunction) {
1465 HandleScope scope(isolate);
1466 DCHECK(args.length() == 3);
1467
1468 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
1469 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
1470 CONVERT_ARG_HANDLE_CHECKED(JSObject, replace, 2);
1471
1472 RETURN_RESULT_OR_FAILURE(isolate, StringReplaceGlobalRegExpWithFunction(
1473 isolate, subject, regexp, replace));
1474 }
1475
1476 RUNTIME_FUNCTION(Runtime_StringReplaceNonGlobalRegExpWithFunction) {
1477 HandleScope scope(isolate);
1478 DCHECK(args.length() == 3);
1479
1480 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
1481 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
1482 CONVERT_ARG_HANDLE_CHECKED(JSObject, replace, 2);
1483
1484 RETURN_RESULT_OR_FAILURE(isolate, StringReplaceNonGlobalRegExpWithFunction(
1485 isolate, subject, regexp, replace));
1486 }
1487
1464 // Slow path for: 1488 // Slow path for:
1465 // ES#sec-regexp.prototype-@@replace 1489 // ES#sec-regexp.prototype-@@replace
1466 // RegExp.prototype [ @@replace ] ( string, replaceValue ) 1490 // RegExp.prototype [ @@replace ] ( string, replaceValue )
1467 RUNTIME_FUNCTION(Runtime_RegExpReplace) { 1491 RUNTIME_FUNCTION(Runtime_RegExpReplace) {
1468 HandleScope scope(isolate); 1492 HandleScope scope(isolate);
1469 DCHECK(args.length() == 3); 1493 DCHECK(args.length() == 3);
1470 1494
1471 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, recv, 0); 1495 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, recv, 0);
1472 CONVERT_ARG_HANDLE_CHECKED(String, string, 1); 1496 CONVERT_ARG_HANDLE_CHECKED(String, string, 1);
1473 Handle<Object> replace_obj = args.at<Object>(2); 1497 Handle<Object> replace_obj = args.at<Object>(2);
(...skipping 22 matching lines...) Expand all
1496 Handle<Object> unicode_obj; 1520 Handle<Object> unicode_obj;
1497 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1521 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1498 isolate, unicode_obj, 1522 isolate, unicode_obj,
1499 JSReceiver::GetProperty(recv, factory->unicode_string())); 1523 JSReceiver::GetProperty(recv, factory->unicode_string()));
1500 unicode = unicode_obj->BooleanValue(); 1524 unicode = unicode_obj->BooleanValue();
1501 1525
1502 RETURN_FAILURE_ON_EXCEPTION(isolate, 1526 RETURN_FAILURE_ON_EXCEPTION(isolate,
1503 RegExpUtils::SetLastIndex(isolate, recv, 0)); 1527 RegExpUtils::SetLastIndex(isolate, recv, 0));
1504 } 1528 }
1505 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).
1506 // TODO(adamk): this fast path is wrong as we doesn't ensure that 'exec' 1535 // TODO(adamk): this fast path is wrong as we doesn't ensure that 'exec'
1507 // is actually a data property on RegExp.prototype. 1536 // is actually a data property on RegExp.prototype.
1508 Handle<Object> exec = factory->undefined_value(); 1537 Handle<Object> exec = factory->undefined_value();
1509 if (recv->IsJSRegExp()) { 1538 if (recv->IsJSRegExp()) {
1510 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1539 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1511 isolate, exec, JSObject::GetProperty( 1540 isolate, exec, JSObject::GetProperty(
1512 recv, factory->NewStringFromAsciiChecked("exec"))); 1541 recv, factory->NewStringFromAsciiChecked("exec")));
1513 if (RegExpUtils::IsBuiltinExec(exec)) { 1542 if (RegExpUtils::IsBuiltinExec(exec)) {
1514 RETURN_RESULT_OR_FAILURE( 1543 RETURN_RESULT_OR_FAILURE(
1515 isolate, RegExpReplace(isolate, Handle<JSRegExp>::cast(recv), string, 1544 isolate, RegExpReplace(isolate, Handle<JSRegExp>::cast(recv), string,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 1681
1653 RUNTIME_FUNCTION(Runtime_IsRegExp) { 1682 RUNTIME_FUNCTION(Runtime_IsRegExp) {
1654 SealHandleScope shs(isolate); 1683 SealHandleScope shs(isolate);
1655 DCHECK(args.length() == 1); 1684 DCHECK(args.length() == 1);
1656 CONVERT_ARG_CHECKED(Object, obj, 0); 1685 CONVERT_ARG_CHECKED(Object, obj, 0);
1657 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); 1686 return isolate->heap()->ToBoolean(obj->IsJSRegExp());
1658 } 1687 }
1659 1688
1660 } // namespace internal 1689 } // namespace internal
1661 } // namespace v8 1690 } // namespace v8
OLDNEW
« src/builtins/builtins-regexp.cc ('K') | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698