Commit a50b6751 authored by Franziska Hinkelmann's avatar Franziska Hinkelmann Committed by Commit Bot

[runtime] Port TypedArraySetFormArrayLike to C++

Bug: v8:6704
Change-Id: I316f085801f4fb6a792124f9a6f80a16e6d43162
Reviewed-on: https://chromium-review.googlesource.com/616721
Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47369}
parent f782f74b
...@@ -250,21 +250,7 @@ TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) ...@@ -250,21 +250,7 @@ TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE)
%SetForceInlineFlag(GlobalTypedArray.prototype.subarray); %SetForceInlineFlag(GlobalTypedArray.prototype.subarray);
function TypedArraySetFromOverlappingTypedArray(target, source, offset) {
function TypedArraySetFromArrayLike(target, source, sourceLength, offset) {
if (offset > 0) {
for (var i = 0; i < sourceLength; i++) {
target[offset + i] = source[i];
}
}
else {
for (var i = 0; i < sourceLength; i++) {
target[i] = source[i];
}
}
}
function TypedArraySetFromOverlappingTypedArray(target, source, offset) {
var sourceElementSize = source.BYTES_PER_ELEMENT; var sourceElementSize = source.BYTES_PER_ELEMENT;
var targetElementSize = target.BYTES_PER_ELEMENT; var targetElementSize = target.BYTES_PER_ELEMENT;
var sourceLength = %_TypedArrayGetLength(source); var sourceLength = %_TypedArrayGetLength(source);
...@@ -339,7 +325,7 @@ DEFINE_METHOD_LEN( ...@@ -339,7 +325,7 @@ DEFINE_METHOD_LEN(
if (intOffset === 0) { if (intOffset === 0) {
%TypedArrayCopyElements(this, obj, %_TypedArrayGetLength(obj)); %TypedArrayCopyElements(this, obj, %_TypedArrayGetLength(obj));
} else { } else {
TypedArraySetFromArrayLike( %_TypedArraySetFromArrayLike(
this, obj, %_TypedArrayGetLength(obj), intOffset); this, obj, %_TypedArrayGetLength(obj), intOffset);
} }
return; return;
...@@ -359,7 +345,7 @@ DEFINE_METHOD_LEN( ...@@ -359,7 +345,7 @@ DEFINE_METHOD_LEN(
if (intOffset + l > %_TypedArrayGetLength(this)) { if (intOffset + l > %_TypedArrayGetLength(this)) {
throw %make_range_error(kTypedArraySetSourceTooLarge); throw %make_range_error(kTypedArraySetSourceTooLarge);
} }
TypedArraySetFromArrayLike(this, obj, l, intOffset); %_TypedArraySetFromArrayLike(this, obj, l, intOffset);
return; return;
} }
}, },
......
...@@ -110,6 +110,32 @@ enum TypedArraySetResultCodes { ...@@ -110,6 +110,32 @@ enum TypedArraySetResultCodes {
TYPED_ARRAY_SET_NON_TYPED_ARRAY = 3 TYPED_ARRAY_SET_NON_TYPED_ARRAY = 3
}; };
// TypedArraySetFromArrayLike(target, source, source_length, offset);
RUNTIME_FUNCTION(Runtime_TypedArraySetFromArrayLike) {
HandleScope scope(isolate);
DCHECK_EQ(4, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, source, 1);
CONVERT_INT32_ARG_CHECKED(source_length, 2);
DCHECK_GE(source_length, 0);
CONVERT_INT32_ARG_CHECKED(offset, 3);
DCHECK_GE(offset, 0);
for (int i = 0; i < source_length; i++) {
Handle<Object> value;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value,
Object::GetElement(isolate, source, i));
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, value,
Object::SetElement(isolate, target, offset + i, value,
LanguageMode::STRICT));
}
return *target;
}
RUNTIME_FUNCTION(Runtime_TypedArraySetFastCases) { RUNTIME_FUNCTION(Runtime_TypedArraySetFastCases) {
HandleScope scope(isolate); HandleScope scope(isolate);
......
...@@ -619,6 +619,7 @@ namespace internal { ...@@ -619,6 +619,7 @@ namespace internal {
F(ArrayBufferViewWasNeutered, 1, 1) \ F(ArrayBufferViewWasNeutered, 1, 1) \
F(TypedArrayGetLength, 1, 1) \ F(TypedArrayGetLength, 1, 1) \
F(TypedArrayGetBuffer, 1, 1) \ F(TypedArrayGetBuffer, 1, 1) \
F(TypedArraySetFromArrayLike, 4, 1) \
F(TypedArraySetFastCases, 3, 1) \ F(TypedArraySetFastCases, 3, 1) \
F(TypedArraySortFast, 1, 1) \ F(TypedArraySortFast, 1, 1) \
F(TypedArrayMaxSizeInHeap, 0, 1) \ F(TypedArrayMaxSizeInHeap, 0, 1) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment