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

Unified Diff: src/builtins/builtins-typedarray.cc

Issue 2733193002: [typedarrays] Move %TypedArray%.prototype.indexOf to C++ (Closed)
Patch Set: Add comments 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 6e4a1bfb936044b23c5a75c74939f381a0f08e9d..cd210e7c41b312bc3669876ee40cbc4cf82faf04 100644
--- a/src/builtins/builtins-typedarray.cc
+++ b/src/builtins/builtins-typedarray.cc
@@ -468,7 +468,6 @@ BUILTIN(TypedArrayPrototypeIncludes) {
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;
@@ -479,13 +478,48 @@ BUILTIN(TypedArrayPrototypeIncludes) {
index = CapRelativeIndex(num, 0, len);
}
+ // TODO(cwhan.tunz): throw. See the above comment in CopyWithin.
+ if (V8_UNLIKELY(array->WasNeutered())) return isolate->heap()->false_value();
+
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));
+ MAYBE_RETURN(result, isolate->heap()->exception());
Camillo Bruni 2017/03/07 13:59:53 Technically not necessary, given that you can only
return *isolate->factory()->ToBoolean(result.FromJust());
}
+BUILTIN(TypedArrayPrototypeIndexOf) {
+ HandleScope scope(isolate);
+
+ Handle<JSTypedArray> array;
+ const char* method = "%TypedArray%.prototype.indexOf";
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, array, JSTypedArray::Validate(isolate, args.receiver(), method));
+
+ int64_t len = array->length_value();
+ if (len == 0) return Smi::FromInt(-1);
+
+ 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);
+ }
+
+ // TODO(cwhan.tunz): throw. See the above comment in CopyWithin.
+ if (V8_UNLIKELY(array->WasNeutered())) return Smi::FromInt(-1);
+
+ Handle<Object> search_element = args.at<Object>(1);
+ ElementsAccessor* elements = array->GetElementsAccessor();
+ Maybe<int64_t> result = elements->IndexOfValue(isolate, array, search_element,
+ static_cast<uint32_t>(index),
+ static_cast<uint32_t>(len));
+ MAYBE_RETURN(result, isolate->heap()->exception());
+ return *isolate->factory()->NewNumberFromInt64(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