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

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

Issue 2663803002: [string] Migrate String.prototype.{split,replace} to TF (Closed)
Patch Set: Remove debug-evaluate whitelisting Created 3 years, 11 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') | src/v8.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-strings.cc
diff --git a/src/runtime/runtime-strings.cc b/src/runtime/runtime-strings.cc
index a126e8cd6379a92f766636036da5e9dcfc2903d6..d51d8bafa13d9c035f3efcfe75db65d0167694d8 100644
--- a/src/runtime/runtime-strings.cc
+++ b/src/runtime/runtime-strings.cc
@@ -13,6 +13,44 @@
namespace v8 {
namespace internal {
+RUNTIME_FUNCTION(Runtime_GetSubstitution) {
+ HandleScope scope(isolate);
+ DCHECK_EQ(4, args.length());
+ CONVERT_ARG_HANDLE_CHECKED(String, matched, 0);
+ CONVERT_ARG_HANDLE_CHECKED(String, subject, 1);
+ CONVERT_SMI_ARG_CHECKED(position, 2);
+ CONVERT_ARG_HANDLE_CHECKED(String, replacement, 3);
+
+ // A simple match without captures.
+ class SimpleMatch : public String::Match {
+ public:
+ SimpleMatch(Handle<String> match, Handle<String> prefix,
+ Handle<String> suffix)
+ : match_(match), prefix_(prefix), suffix_(suffix) {}
+
+ Handle<String> GetMatch() override { return match_; }
+ MaybeHandle<String> GetCapture(int i, bool* capture_exists) override {
+ *capture_exists = false;
+ return match_; // Return arbitrary string handle.
+ }
+ Handle<String> GetPrefix() override { return prefix_; }
+ Handle<String> GetSuffix() override { return suffix_; }
+ int CaptureCount() override { return 0; }
+
+ private:
+ Handle<String> match_, prefix_, suffix_;
+ };
+
+ Handle<String> prefix =
+ isolate->factory()->NewSubString(subject, 0, position);
+ Handle<String> suffix = isolate->factory()->NewSubString(
+ subject, position + matched->length(), subject->length());
+ SimpleMatch match(matched, prefix, suffix);
+
+ RETURN_RESULT_OR_FAILURE(
+ isolate, String::GetSubstitution(isolate, &match, replacement));
+}
+
// This may return an empty MaybeHandle if an exception is thrown or
// we abort due to reaching the recursion limit.
MaybeHandle<String> StringReplaceOneCharWithString(
« no previous file with comments | « src/runtime/runtime.h ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698