Chromium Code Reviews| 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 |