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

Unified Diff: src/runtime.cc

Issue 53047: Implement string.match in C++. (Closed)
Patch Set: Created 11 years, 9 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.h ('k') | src/string.js » ('j') | src/string.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 38db689a746a46d32f071f9dbc9b2a5c3a1e16fd..9d4383e55f04e286d73ecfc46b00478d5cbe50de 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -1038,7 +1038,9 @@ static Object* Runtime_RegExpExec(Arguments args) {
CONVERT_CHECKED(Smi, index, args[2]);
CONVERT_CHECKED(JSArray, raw_last_match_info, args[3]);
Handle<JSArray> last_match_info(raw_last_match_info);
- CHECK(last_match_info->HasFastElements());
+ RUNTIME_ASSERT(last_match_info->HasFastElements());
+ RUNTIME_ASSERT(index->value() >= 0);
+ RUNTIME_ASSERT(index->value() <= subject->length());
Handle<Object> result = RegExpImpl::Exec(regexp,
subject,
index->value(),
@@ -1048,23 +1050,6 @@ static Object* Runtime_RegExpExec(Arguments args) {
}
-static Object* Runtime_RegExpExecGlobal(Arguments args) {
- HandleScope scope;
- ASSERT(args.length() == 3);
- CONVERT_CHECKED(JSRegExp, raw_regexp, args[0]);
- Handle<JSRegExp> regexp(raw_regexp);
- CONVERT_CHECKED(String, raw_subject, args[1]);
- Handle<String> subject(raw_subject);
- CONVERT_CHECKED(JSArray, raw_last_match_info, args[2]);
- Handle<JSArray> last_match_info(raw_last_match_info);
- CHECK(last_match_info->HasFastElements());
- Handle<Object> result =
- RegExpImpl::ExecGlobal(regexp, subject, last_match_info);
- if (result.is_null()) return Failure::Exception();
- return *result;
-}
-
-
static Object* Runtime_MaterializeRegExpLiteral(Arguments args) {
HandleScope scope;
ASSERT(args.length() == 4);
@@ -2337,6 +2322,57 @@ static Object* Runtime_StringSlice(Arguments args) {
}
+static Object* Runtime_StringMatch(Arguments args) {
+ ASSERT_EQ(3, args.length());
+
+ CONVERT_ARG_CHECKED(String, subject, 0);
+ CONVERT_ARG_CHECKED(JSRegExp, regexp, 1);
+ CONVERT_ARG_CHECKED(JSArray, regexp_info, 2);
+ HandleScope handles;
+
+ Handle<Object> match = RegExpImpl::Exec(regexp, subject, 0, regexp_info);
+
+ if (match.is_null()) {
+ return Failure::Exception();
+ }
+ if (match->IsNull()) {
+ return Heap::null_value();
+ }
+ int length = subject->length();
+
+ ZoneScope zone_space(DELETE_ON_EXIT);
+ ZoneList<int> offsets(8);
+ do {
+ int start;
+ int end;
+ {
+ AssertNoAllocation no_alloc;
+ FixedArray* elements = regexp_info->elements();
+ start = Smi::cast(elements->get(RegExpImpl::kFirstCapture))->value();
+ end = Smi::cast(elements->get(RegExpImpl::kFirstCapture + 1))->value();
+ }
+ offsets.Add(start);
+ offsets.Add(end);
+ int index = start < end ? end : end + 1;
+ if (index > length) break;
+ match = RegExpImpl::Exec(regexp, subject, index, regexp_info);
+ if (match.is_null()) {
+ return Failure::Exception();
+ }
+ } while (!match->IsNull());
+ int matches = offsets.length() / 2;
+ Handle<FixedArray> elements = Factory::NewFixedArray(matches);
+ for (int i = 0; i < matches ; i++) {
+ int from = offsets.at(i * 2);
+ int to = offsets.at(i * 2 + 1);
+ elements->set(i, *Factory::NewStringSlice(subject, from, to));
+ }
+ Handle<JSArray> result = Factory::NewJSArrayWithElements(elements);
+ result->set_length(Smi::FromInt(matches));
+ return *result;
+}
+
+
static Object* Runtime_NumberToRadixString(Arguments args) {
NoHandleAllocation ha;
ASSERT(args.length() == 2);
« no previous file with comments | « src/runtime.h ('k') | src/string.js » ('j') | src/string.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698