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

Unified Diff: src/builtins/builtins-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/builtins/builtins.h ('k') | src/contexts.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-regexp.cc
diff --git a/src/builtins/builtins-regexp.cc b/src/builtins/builtins-regexp.cc
index 91ada097d94155435a0a2d904b789dc1166658e2..fa7241941d7cc90d7a42025b405aa5f664657fd6 100644
--- a/src/builtins/builtins-regexp.cc
+++ b/src/builtins/builtins-regexp.cc
@@ -1655,5 +1655,63 @@ void Builtins::Generate_RegExpPrototypeReplace(CodeStubAssembler* a) {
}
}
+namespace {
+
+// TODO(jgruber): Replace this with a FixedArray.
+compiler::Node* GetInternalMatchInfo(CodeStubAssembler* a,
+ compiler::Node* context) {
+ typedef compiler::Node Node;
+
+ const ElementsKind elements_kind = FAST_ELEMENTS;
+ Node* const native_context = a->LoadNativeContext(context);
+ Node* const array_map =
+ a->LoadJSArrayElementsMap(elements_kind, native_context);
+ Node* const capacity = a->IntPtrConstant(RegExpImpl::kLastMatchOverhead + 2);
+ Node* const allocation_site = nullptr;
+
+ Node* const smi_zero = a->SmiConstant(Smi::kZero);
+
+ return a->AllocateJSArray(elements_kind, array_map, capacity, smi_zero,
+ allocation_site,
+ CodeStubAssembler::INTPTR_PARAMETERS);
+}
+
+} // namespace
+
+// Simple string matching functionality for internal use which does not modify
+// the last match info.
+void Builtins::Generate_RegExpInternalMatch(CodeStubAssembler* a) {
+ typedef CodeStubAssembler::Label Label;
+ typedef compiler::Node Node;
+
+ Isolate* const isolate = a->isolate();
+
+ Node* const regexp = a->Parameter(1);
+ Node* const string = a->Parameter(2);
+ Node* const context = a->Parameter(5);
+
+ Node* const null = a->NullConstant();
+ Node* const smi_zero = a->SmiConstant(Smi::FromInt(0));
+ Node* const internal_match_info = GetInternalMatchInfo(a, context);
+
+ Callable exec_callable = CodeFactory::RegExpExec(isolate);
+ Node* const match_indices = a->CallStub(
+ exec_callable, context, regexp, string, smi_zero, internal_match_info);
+
+ Label if_matched(a), if_didnotmatch(a);
+ a->Branch(a->WordEqual(match_indices, null), &if_didnotmatch, &if_matched);
+
+ a->Bind(&if_didnotmatch);
+ a->Return(null);
+
+ a->Bind(&if_matched);
+ {
+ Node* const match_elements = a->LoadElements(match_indices);
+ Node* result = ConstructNewResultFromMatchInfo(isolate, a, context,
+ match_elements, string);
+ a->Return(result);
+ }
+}
+
} // namespace internal
} // namespace v8
« no previous file with comments | « src/builtins/builtins.h ('k') | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698