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

Side by Side 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, 10 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
« no previous file with comments | « src/runtime/runtime.h ('k') | src/v8.gyp » ('j') | 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/regexp/jsregexp-inl.h" 8 #include "src/regexp/jsregexp-inl.h"
9 #include "src/string-builder.h" 9 #include "src/string-builder.h"
10 #include "src/string-case.h" 10 #include "src/string-case.h"
11 #include "src/string-search.h" 11 #include "src/string-search.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 RUNTIME_FUNCTION(Runtime_GetSubstitution) {
17 HandleScope scope(isolate);
18 DCHECK_EQ(4, args.length());
19 CONVERT_ARG_HANDLE_CHECKED(String, matched, 0);
20 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1);
21 CONVERT_SMI_ARG_CHECKED(position, 2);
22 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 3);
23
24 // A simple match without captures.
25 class SimpleMatch : public String::Match {
26 public:
27 SimpleMatch(Handle<String> match, Handle<String> prefix,
28 Handle<String> suffix)
29 : match_(match), prefix_(prefix), suffix_(suffix) {}
30
31 Handle<String> GetMatch() override { return match_; }
32 MaybeHandle<String> GetCapture(int i, bool* capture_exists) override {
33 *capture_exists = false;
34 return match_; // Return arbitrary string handle.
35 }
36 Handle<String> GetPrefix() override { return prefix_; }
37 Handle<String> GetSuffix() override { return suffix_; }
38 int CaptureCount() override { return 0; }
39
40 private:
41 Handle<String> match_, prefix_, suffix_;
42 };
43
44 Handle<String> prefix =
45 isolate->factory()->NewSubString(subject, 0, position);
46 Handle<String> suffix = isolate->factory()->NewSubString(
47 subject, position + matched->length(), subject->length());
48 SimpleMatch match(matched, prefix, suffix);
49
50 RETURN_RESULT_OR_FAILURE(
51 isolate, String::GetSubstitution(isolate, &match, replacement));
52 }
53
16 // This may return an empty MaybeHandle if an exception is thrown or 54 // This may return an empty MaybeHandle if an exception is thrown or
17 // we abort due to reaching the recursion limit. 55 // we abort due to reaching the recursion limit.
18 MaybeHandle<String> StringReplaceOneCharWithString( 56 MaybeHandle<String> StringReplaceOneCharWithString(
19 Isolate* isolate, Handle<String> subject, Handle<String> search, 57 Isolate* isolate, Handle<String> subject, Handle<String> search,
20 Handle<String> replace, bool* found, int recursion_limit) { 58 Handle<String> replace, bool* found, int recursion_limit) {
21 StackLimitCheck stackLimitCheck(isolate); 59 StackLimitCheck stackLimitCheck(isolate);
22 if (stackLimitCheck.HasOverflowed() || (recursion_limit == 0)) { 60 if (stackLimitCheck.HasOverflowed() || (recursion_limit == 0)) {
23 return MaybeHandle<String>(); 61 return MaybeHandle<String>();
24 } 62 }
25 recursion_limit--; 63 recursion_limit--;
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 SealHandleScope shs(isolate); 925 SealHandleScope shs(isolate);
888 DCHECK_EQ(2, args.length()); 926 DCHECK_EQ(2, args.length());
889 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); 927 if (!args[0]->IsString()) return isolate->heap()->undefined_value();
890 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); 928 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value();
891 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); 929 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value();
892 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); 930 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate);
893 } 931 }
894 932
895 } // namespace internal 933 } // namespace internal
896 } // namespace v8 934 } // namespace v8
OLDNEW
« 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