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

Side by Side 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, 6 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/builtins.h ('k') | src/js/string.js » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/builtins.h" 5 #include "src/builtins.h"
6 6
7 #include "src/api-arguments.h" 7 #include "src/api-arguments.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 #define CHECK_RECEIVER(Type, name, method) \ 172 #define CHECK_RECEIVER(Type, name, method) \
173 if (!args.receiver()->Is##Type()) { \ 173 if (!args.receiver()->Is##Type()) { \
174 THROW_NEW_ERROR_RETURN_FAILURE( \ 174 THROW_NEW_ERROR_RETURN_FAILURE( \
175 isolate, \ 175 isolate, \
176 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \ 176 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \
177 isolate->factory()->NewStringFromAsciiChecked(method), \ 177 isolate->factory()->NewStringFromAsciiChecked(method), \
178 args.receiver())); \ 178 args.receiver())); \
179 } \ 179 } \
180 Handle<Type> name = Handle<Type>::cast(args.receiver()) 180 Handle<Type> name = Handle<Type>::cast(args.receiver())
181 181
182 // Throws a TypeError for {method} if the receiver is not coercible to Object,
183 // or converts the receiver to a String otherwise and assigns it to a new var
184 // with the given {name}.
185 #define TO_THIS_STRING(name, method) \
186 if (args.receiver()->IsNull() || args.receiver()->IsUndefined()) { \
187 THROW_NEW_ERROR_RETURN_FAILURE( \
188 isolate, \
189 NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, \
190 isolate->factory()->NewStringFromAsciiChecked(method))); \
191 } \
192 Handle<String> name; \
193 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \
194 isolate, name, Object::ToString(isolate, args.receiver()))
182 195
183 inline bool ClampedToInteger(Object* object, int* out) { 196 inline bool ClampedToInteger(Object* object, int* out) {
184 // This is an extended version of ECMA-262 7.1.11 handling signed values 197 // This is an extended version of ECMA-262 7.1.11 handling signed values
185 // Try to convert object to a number and clamp values to [kMinInt, kMaxInt] 198 // Try to convert object to a number and clamp values to [kMinInt, kMaxInt]
186 if (object->IsSmi()) { 199 if (object->IsSmi()) {
187 *out = Smi::cast(object)->value(); 200 *out = Smi::cast(object)->value();
188 return true; 201 return true;
189 } else if (object->IsHeapNumber()) { 202 } else if (object->IsHeapNumber()) {
190 double value = HeapNumber::cast(object)->value(); 203 double value = HeapNumber::cast(object)->value();
191 if (std::isnan(value)) { 204 if (std::isnan(value)) {
(...skipping 4342 matching lines...) Expand 10 before | Expand all | Expand 10 after
4534 assembler->Return(assembler->NaNConstant()); 4547 assembler->Return(assembler->NaNConstant());
4535 assembler->Bind(&if_positioninbounds); 4548 assembler->Bind(&if_positioninbounds);
4536 } 4549 }
4537 4550
4538 // Load the character at the {position} from the {receiver}. 4551 // Load the character at the {position} from the {receiver}.
4539 Node* value = assembler->StringCharCodeAt(receiver, position); 4552 Node* value = assembler->StringCharCodeAt(receiver, position);
4540 Node* result = assembler->SmiFromWord32(value); 4553 Node* result = assembler->SmiFromWord32(value);
4541 assembler->Return(result); 4554 assembler->Return(result);
4542 } 4555 }
4543 4556
4557 // ES6 section 21.1.3.25 String.prototype.trim ()
4558 BUILTIN(StringPrototypeTrim) {
4559 HandleScope scope(isolate);
4560 TO_THIS_STRING(string, "String.prototype.trim");
4561 return *String::Trim(string, String::kTrim);
4562 }
4563
4564 // Non-standard WebKit extension
4565 BUILTIN(StringPrototypeTrimLeft) {
4566 HandleScope scope(isolate);
4567 TO_THIS_STRING(string, "String.prototype.trimLeft");
4568 return *String::Trim(string, String::kTrimLeft);
4569 }
4570
4571 // Non-standard WebKit extension
4572 BUILTIN(StringPrototypeTrimRight) {
4573 HandleScope scope(isolate);
4574 TO_THIS_STRING(string, "String.prototype.trimRight");
4575 return *String::Trim(string, String::kTrimRight);
4576 }
4577
4544 // ----------------------------------------------------------------------------- 4578 // -----------------------------------------------------------------------------
4545 // ES6 section 21.1 ArrayBuffer Objects 4579 // ES6 section 21.1 ArrayBuffer Objects
4546 4580
4547 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Call]] case. 4581 // ES6 section 24.1.2.1 ArrayBuffer ( length ) for the [[Call]] case.
4548 BUILTIN(ArrayBufferConstructor) { 4582 BUILTIN(ArrayBufferConstructor) {
4549 HandleScope scope(isolate); 4583 HandleScope scope(isolate);
4550 Handle<JSFunction> target = args.target<JSFunction>(); 4584 Handle<JSFunction> target = args.target<JSFunction>();
4551 DCHECK(*target == target->native_context()->array_buffer_fun() || 4585 DCHECK(*target == target->native_context()->array_buffer_fun() ||
4552 *target == target->native_context()->shared_array_buffer_fun()); 4586 *target == target->native_context()->shared_array_buffer_fun());
4553 THROW_NEW_ERROR_RETURN_FAILURE( 4587 THROW_NEW_ERROR_RETURN_FAILURE(
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
5566 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) 5600 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T)
5567 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 5601 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
5568 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 5602 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
5569 #undef DEFINE_BUILTIN_ACCESSOR_C 5603 #undef DEFINE_BUILTIN_ACCESSOR_C
5570 #undef DEFINE_BUILTIN_ACCESSOR_A 5604 #undef DEFINE_BUILTIN_ACCESSOR_A
5571 #undef DEFINE_BUILTIN_ACCESSOR_T 5605 #undef DEFINE_BUILTIN_ACCESSOR_T
5572 #undef DEFINE_BUILTIN_ACCESSOR_H 5606 #undef DEFINE_BUILTIN_ACCESSOR_H
5573 5607
5574 } // namespace internal 5608 } // namespace internal
5575 } // namespace v8 5609 } // namespace v8
OLDNEW
« 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