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

Unified Diff: src/runtime/runtime-regexp.cc

Issue 2409513003: [regexp] Port remaining JS functions in regexp.js (Closed)
Patch Set: Rebaseline bytecode expectations 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime.h ('k') | test/cctest/interpreter/bytecode_expectations/CallRuntime.golden » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-regexp.cc
diff --git a/src/runtime/runtime-regexp.cc b/src/runtime/runtime-regexp.cc
index b6c71311de85a883fdd5471cdcff435b83a08b2e..986c7365ef46692b035b64bb3ecc6fa813346778 100644
--- a/src/runtime/runtime-regexp.cc
+++ b/src/runtime/runtime-regexp.cc
@@ -656,16 +656,11 @@ MUST_USE_RESULT static Object* StringReplaceGlobalRegExpWithEmptyString(
return *answer;
}
+namespace {
-RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) {
- HandleScope scope(isolate);
- DCHECK(args.length() == 4);
-
- CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
- CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2);
- CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
- CONVERT_ARG_HANDLE_CHECKED(JSObject, last_match_info, 3);
-
+Object* StringReplaceGlobalRegExpWithStringHelper(
+ Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> subject,
+ Handle<String> replacement, Handle<JSObject> last_match_info) {
CHECK(regexp->GetFlags() & JSRegExp::kGlobal);
CHECK(last_match_info->HasFastObjectElements());
@@ -687,6 +682,20 @@ RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) {
replacement, last_match_info);
}
+} // namespace
+
+RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 4);
+
+ CONVERT_ARG_HANDLE_CHECKED(String, subject, 0);
+ CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2);
+ CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1);
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, last_match_info, 3);
+
+ return StringReplaceGlobalRegExpWithStringHelper(
+ isolate, regexp, subject, replacement, last_match_info);
+}
RUNTIME_FUNCTION(Runtime_StringSplit) {
HandleScope handle_scope(isolate);
@@ -769,6 +778,32 @@ RUNTIME_FUNCTION(Runtime_StringSplit) {
return *result;
}
+// ES##sec-regexpcreate
+// RegExpCreate ( P, F )
+RUNTIME_FUNCTION(Runtime_RegExpCreate) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(Object, source_object, 0);
+
+ Handle<String> source;
+ if (source_object->IsUndefined(isolate)) {
+ source = isolate->factory()->empty_string();
+ } else {
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, source, Object::ToString(isolate, source_object));
+ }
+
+ Handle<Map> map(isolate->regexp_function()->initial_map());
+ Handle<JSRegExp> regexp =
+ Handle<JSRegExp>::cast(isolate->factory()->NewJSObjectFromMap(map));
+
+ JSRegExp::Flags flags = JSRegExp::kNone;
+
+ RETURN_FAILURE_ON_EXCEPTION(isolate,
+ JSRegExp::Initialize(regexp, source, flags));
+
+ return *regexp;
+}
RUNTIME_FUNCTION(Runtime_RegExpExec) {
HandleScope scope(isolate);
@@ -835,6 +870,22 @@ RUNTIME_FUNCTION(Runtime_RegExpInitializeAndCompile) {
return *regexp;
}
+RUNTIME_FUNCTION(Runtime_RegExpInternalReplace) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 3);
+ CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0);
+ CONVERT_ARG_HANDLE_CHECKED(String, subject, 1);
+ CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2);
+
+ static const int kInitialMatchSlots = 2;
+ Handle<JSArray> internal_match_info = isolate->factory()->NewJSArray(
+ FAST_ELEMENTS, 0, RegExpImpl::kLastMatchOverhead + kInitialMatchSlots,
+ INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
+
+ return StringReplaceGlobalRegExpWithStringHelper(
+ isolate, regexp, subject, replacement, internal_match_info);
+}
+
namespace {
class MatchInfoBackedMatch : public String::Match {
« no previous file with comments | « src/runtime/runtime.h ('k') | test/cctest/interpreter/bytecode_expectations/CallRuntime.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698