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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/typedarray.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-typedarray.cc
diff --git a/src/builtins/builtins-typedarray.cc b/src/builtins/builtins-typedarray.cc
index 8a8bde4be027a1329ccaaea4dfe92d75c32957a3..6e4a1bfb936044b23c5a75c74939f381a0f08e9d 100644
--- a/src/builtins/builtins-typedarray.cc
+++ b/src/builtins/builtins-typedarray.cc
@@ -6,6 +6,7 @@
#include "src/builtins/builtins.h"
#include "src/code-stub-assembler.h"
#include "src/counters.h"
+#include "src/elements.h"
#include "src/objects-inl.h"
namespace v8 {
@@ -456,5 +457,35 @@ BUILTIN(TypedArrayPrototypeCopyWithin) {
return *array;
}
+BUILTIN(TypedArrayPrototypeIncludes) {
+ HandleScope scope(isolate);
+
+ Handle<JSTypedArray> array;
+ const char* method = "%TypedArray%.prototype.includes";
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method));
+
+ if (args.length() < 2) return isolate->heap()->false_value();
+
+ int64_t len = array->length_value();
+
+ if (len == 0) return isolate->heap()->false_value();
+
+ int64_t index = 0;
+ if (args.length() > 2) {
+ Handle<Object> num;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, num, Object::ToInteger(isolate, args.at<Object>(2)));
+ index = CapRelativeIndex(num, 0, len);
+ }
+
+ Handle<Object> search_element = args.at<Object>(1);
+ ElementsAccessor* elements = array->GetElementsAccessor();
+ Maybe<bool> result = elements->IncludesValue(isolate, array, search_element,
+ static_cast<uint32_t>(index),
+ static_cast<uint32_t>(len));
+ return *isolate->factory()->ToBoolean(result.FromJust());
+}
+
} // namespace internal
} // namespace v8
« 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