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 |