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

Unified Diff: src/builtins.cc

Issue 2018963002: [builtins] Migrate String.prototype.trim/trimLeft/trimRight to C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address Franziskas comments. Created 4 years, 7 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.h ('k') | src/js/string.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index e5feca997a077674cb77660814ed3015be0329ce..b2cf4861ec0ed6f7cb462e6173807f1b70d311cd 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -179,6 +179,19 @@ BUILTIN_LIST_C(DEF_ARG_TYPE)
} \
Handle<Type> name = Handle<Type>::cast(args.receiver())
+// Throws a TypeError for {method} if the receiver is not coercible to Object,
+// or converts the receiver to a String otherwise and assigns it to a new var
+// with the given {name}.
+#define TO_THIS_STRING(name, method) \
+ if (args.receiver()->IsNull() || args.receiver()->IsUndefined()) { \
+ THROW_NEW_ERROR_RETURN_FAILURE( \
+ isolate, \
+ NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, \
+ isolate->factory()->NewStringFromAsciiChecked(method))); \
+ } \
+ Handle<String> name; \
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \
+ isolate, name, Object::ToString(isolate, args.receiver()))
inline bool ClampedToInteger(Object* object, int* out) {
// This is an extended version of ECMA-262 7.1.11 handling signed values
@@ -4541,6 +4554,27 @@ void Builtins::Generate_StringPrototypeCharCodeAt(
assembler->Return(result);
}
+// ES6 section 21.1.3.25 String.prototype.trim ()
+BUILTIN(StringPrototypeTrim) {
+ HandleScope scope(isolate);
+ TO_THIS_STRING(string, "String.prototype.trim");
+ return *String::Trim(string, String::kTrim);
+}
+
+// Non-standard WebKit extension
+BUILTIN(StringPrototypeTrimLeft) {
+ HandleScope scope(isolate);
+ TO_THIS_STRING(string, "String.prototype.trimLeft");
+ return *String::Trim(string, String::kTrimLeft);
+}
+
+// Non-standard WebKit extension
+BUILTIN(StringPrototypeTrimRight) {
+ HandleScope scope(isolate);
+ TO_THIS_STRING(string, "String.prototype.trimRight");
+ return *String::Trim(string, String::kTrimRight);
+}
+
// -----------------------------------------------------------------------------
// ES6 section 21.1 ArrayBuffer Objects
« no previous file with comments | « src/builtins.h ('k') | src/js/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698