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

Side by Side Diff: src/builtins/builtins-typedarray.cc

Issue 2732823002: [typedarrays] Move %TypedArray%.prototype.includes to C++ builtins (Closed)
Patch Set: Created 3 years, 9 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/builtins.h ('k') | src/js/typedarray.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/builtins-utils.h" 5 #include "src/builtins/builtins-utils.h"
6 #include "src/builtins/builtins.h" 6 #include "src/builtins/builtins.h"
7 #include "src/code-stub-assembler.h" 7 #include "src/code-stub-assembler.h"
8 #include "src/counters.h" 8 #include "src/counters.h"
9 #include "src/elements.h"
9 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
10 11
11 namespace v8 { 12 namespace v8 {
12 namespace internal { 13 namespace internal {
13 14
14 class TypedArrayBuiltinsAssembler : public CodeStubAssembler { 15 class TypedArrayBuiltinsAssembler : public CodeStubAssembler {
15 public: 16 public:
16 explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state) 17 explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state)
17 : CodeStubAssembler(state) {} 18 : CodeStubAssembler(state) {}
18 19
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 to = to * element_size; 450 to = to * element_size;
450 from = from * element_size; 451 from = from * element_size;
451 count = count * element_size; 452 count = count * element_size;
452 453
453 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr()); 454 uint8_t* data = static_cast<uint8_t*>(elements->DataPtr());
454 std::memmove(data + to, data + from, count); 455 std::memmove(data + to, data + from, count);
455 456
456 return *array; 457 return *array;
457 } 458 }
458 459
460 BUILTIN(TypedArrayPrototypeIncludes) {
461 HandleScope scope(isolate);
462
463 Handle<JSTypedArray> array;
464 const char* method = "%TypedArray%.prototype.includes";
465 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
466 isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method));
467
468 if (args.length() < 2) return isolate->heap()->false_value();
469
470 int64_t len = array->length_value();
471
472 if (len == 0) return isolate->heap()->false_value();
473
474 int64_t index = 0;
475 if (args.length() > 2) {
476 Handle<Object> num;
477 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
478 isolate, num, Object::ToInteger(isolate, args.at<Object>(2)));
479 index = CapRelativeIndex(num, 0, len);
480 }
481
482 Handle<Object> search_element = args.at<Object>(1);
483 ElementsAccessor* elements = array->GetElementsAccessor();
484 Maybe<bool> result = elements->IncludesValue(isolate, array, search_element,
485 static_cast<uint32_t>(index),
486 static_cast<uint32_t>(len));
487 return *isolate->factory()->ToBoolean(result.FromJust());
488 }
489
459 } // namespace internal 490 } // namespace internal
460 } // namespace v8 491 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698