Commit 3767ca8b authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

[change-array-by-copy] Remove TypedArray.prototype.toSpliced

Normative update from
https://github.com/tc39/proposal-change-array-by-copy/issues/88

Bug: v8:13035
Change-Id: I939cebc13b4ab3cafbfb96a45d93b50453fd07e9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3785282
Auto-Submit: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81989}
parent 6beb0cf4
......@@ -890,7 +890,6 @@ filegroup(
"src/builtins/typed-array-sort.tq",
"src/builtins/typed-array-subarray.tq",
"src/builtins/typed-array-to-reversed.tq",
"src/builtins/typed-array-to-spliced.tq",
"src/builtins/typed-array-values.tq",
"src/builtins/typed-array-with.tq",
"src/builtins/typed-array.tq",
......
......@@ -1830,7 +1830,6 @@ torque_files = [
"src/builtins/typed-array-sort.tq",
"src/builtins/typed-array-subarray.tq",
"src/builtins/typed-array-to-reversed.tq",
"src/builtins/typed-array-to-spliced.tq",
"src/builtins/typed-array-values.tq",
"src/builtins/typed-array-with.tq",
"src/builtins/typed-array.tq",
......
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
namespace typed_array {
const kBuiltinNameToSpliced: constexpr string =
'%TypedArray%.prototype.toSpliced';
transitioning macro SlowTypedArrayToSplicedContinuation(
implicit context: Context)(
accessor: TypedArrayAccessor, array: JSTypedArray, arrayLength: uintptr,
copy: JSTypedArray, newLen: uintptr, actualStart: uintptr,
actualDeleteCount: uintptr, insertCount: uintptr): void {
// 17. Let i be 0.
let i: uintptr = 0;
// 18. Let r be actualStart + actualDeleteCount.
let r: uintptr = actualStart + actualDeleteCount;
// 19. Repeat, while i < actualStart,
while (i < actualStart) {
// a. Let Pi be ! ToString(𝔽(i)).
// b. Let iValue be ! Get(O, Pi).
let iValue: JSAny;
if (i < arrayLength) {
iValue = accessor.LoadNumeric(array, i);
} else {
iValue = Undefined;
}
// c. Perform ! Set(target, Pi, iValue, true).
accessor.StoreJSAny(context, copy, i, iValue) otherwise unreachable;
// d. Set i to i + 1.
++i;
}
// 20. For each element E of convertedItems, do
// a. Let Pi be ! ToString(𝔽(i)).
// b. Perform ! Set(A, Pi, E, true).
// c. Set i to i + 1.
//
// Copying already done, just increment i.
i += insertCount;
// 21. Repeat, while i < newLen,
while (i < newLen) {
// a. Let Pi be ! ToString(𝔽(i)).
// b. Let from be ! ToString(𝔽(r)).
// c. Let fromValue be ! Get(O, from).
let fromValue: JSAny;
if (r < arrayLength) {
fromValue = accessor.LoadNumeric(array, r);
} else {
fromValue = Undefined;
}
// d. Perform ! Set(A, Pi, fromValue, true).
accessor.StoreJSAny(context, copy, i, fromValue) otherwise unreachable;
// e. Set i to i + 1.
++i;
// f. Set r to r + 1.
++r;
}
}
// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toSpliced
transitioning javascript builtin TypedArrayPrototypeToSpliced(
js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny {
try {
const start = arguments[0];
const deleteCount = arguments[1];
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
// 3. Let getBufferByteLength be
// MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
// 4. Let len be IntegerIndexedObjectLength(O, getBufferByteLength).
const array: JSTypedArray =
Cast<JSTypedArray>(receiver) otherwise NotTypedArray;
let attachedArrayAndLength = EnsureAttachedAndReadLength(array)
otherwise IsDetachedOrOutOfBounds;
const originalLength = attachedArrayAndLength.length;
// 5. Let relativeStart be ? ToIntegerOrInfinity(start).
const relativeStart: Number = ToInteger_Inline(start);
// 6. If relativeStart is -∞, let actualStart be 0.
// 7. Else if relativeStart < 0, let actualStart be
// max(len + relativeStart, 0).
// 8. Else, let actualStart be min(relativeStart, len).
const actualStart =
ConvertAndClampRelativeIndex(relativeStart, originalLength);
// 9. Let insertCount be the number of elements in items.
let insertCount: uintptr;
let actualDeleteCount: uintptr;
if (arguments.length == 0) {
// 10. If start is not present, then
// a. Let actualDeleteCount be 0.
actualDeleteCount = 0;
insertCount = 0;
} else if (arguments.length == 1) {
// 11. Else if deleteCount is not present, then
// a. Let actualDeleteCount be len - actualStart.
actualDeleteCount = originalLength - actualStart;
insertCount = 0;
} else {
// 12. Else,
// a. Let dc be ? ToIntegerOrInfinity(deleteCount).
// b. Let actualDeleteCount be the result of clamping dc between 0 and
// len - actualStart.
actualDeleteCount = ConvertAndClampRelativeIndex(
deleteCount, originalLength - actualStart);
insertCount = Convert<uintptr>(arguments.length - 2);
}
// 13. Let convertedItems be a new empty List.
const accessor: TypedArrayAccessor =
GetTypedArrayAccessor(array.elements_kind);
// (Step 14 done below, because use of an intermediate list is
// unobservable).
// 15. Let newLen be len + insertCount - actualDeleteCount.
const newLen = originalLength + insertCount - actualDeleteCount;
// 16. Let A be ? TypedArrayCreateSameType(O, « 𝔽(newLen) »).
const copy = TypedArrayCreateSameType(array, newLen);
// 14. For each element E of items, do
for (let k: uintptr = 0; k < insertCount; k++) {
// a. If O.[[ContentType]] is BigInt, let convertedValue be ? ToBigInt(E).
// b. Else, let convertedValue be ? ToNumber(E).
// c. Append convertedValue as the last element of convertedItems.
accessor.StoreJSAny(
context, copy, actualStart + k, arguments[Convert<intptr>(k + 2)])
otherwise unreachable;
}
// 17. Let i be 0.
// 18. Let r be actualStart + actualDeleteCount.
// 19. Repeat, while i < actualStart,
// a. Let Pi be ! ToString(𝔽(i)).
// b. Let iValue be ! Get(O, Pi).
// c. Perform ! Set(target, Pi, iValue, true).
// d. Set i to i + 1.
// 20. For each element E of convertedItems, do
// a. Let Pi be ! ToString(𝔽(i)).
// b. Perform ! Set(A, Pi, E, true).
// c. Set i to i + 1.
// 21. Repeat, while i < newLen,
// a. Let Pi be ! ToString(𝔽(i)).
// b. Let from be ! ToString(𝔽(r)).
// c. Let fromValue be ! Get(O, from).
// d. Perform ! Set(A, Pi, fromValue, true).
// e. Set i to i + 1.
// f. Set r to r + 1.
//
// Step 20 is performed as part of step 13 above.
//
// Steps 17-21 (excluding 20) are implemented by memmove'ing 2 parts: the
// first part before the inserted items, the second part after the inserted
// items.
try {
// If the array shrunk or was detached due to parameter conversion, we go
// to a slow path that implements the spec algorithm naively. While it's
// possible to do partial memmoves, computation of the indices and length
// for the partial moves are harder to reason about, and miscomputation is
// likely a security issue.
attachedArrayAndLength =
EnsureAttachedAndReadLength(array) otherwise goto Slow(0);
const reloadedLength = attachedArrayAndLength.length;
if (reloadedLength < originalLength) goto Slow(reloadedLength);
const info = GetTypedArrayElementsInfo(copy);
const firstPartLength = actualStart;
if (firstPartLength != 0) {
const firstPartCountBytes: uintptr =
info.CalculateByteLength(firstPartLength) otherwise unreachable;
if (IsSharedArrayBuffer(array.buffer)) {
CallCRelaxedMemmove(
copy.data_ptr, array.data_ptr, firstPartCountBytes);
} else {
CallCMemmove(copy.data_ptr, array.data_ptr, firstPartCountBytes);
}
}
const secondPartStartInSrc = actualStart + actualDeleteCount;
const secondPartStartInCopy = actualStart + insertCount;
const secondPartLength = newLen - secondPartStartInCopy;
dcheck(secondPartLength == originalLength - secondPartStartInSrc);
if (secondPartLength != 0) {
const secondPartCountBytes: uintptr =
info.CalculateByteLength(secondPartLength) otherwise unreachable;
const secondPartDstPtr: RawPtr = info.GetDataPointerOffsetByLength(
copy, secondPartStartInCopy) otherwise unreachable;
const secondPartSrcPtr: RawPtr = info.GetDataPointerOffsetByLength(
array, secondPartStartInSrc) otherwise unreachable;
if (IsSharedArrayBuffer(array.buffer)) {
CallCRelaxedMemmove(
secondPartDstPtr, secondPartSrcPtr, secondPartCountBytes);
} else {
CallCMemmove(
secondPartDstPtr, secondPartSrcPtr, secondPartCountBytes);
}
}
} label Slow(reloadedLength: uintptr) deferred {
SlowTypedArrayToSplicedContinuation(
accessor, array, reloadedLength, copy, newLen, actualStart,
actualDeleteCount, insertCount);
}
// 22. Return A.
return copy;
} label NotTypedArray deferred {
ThrowTypeError(MessageTemplate::kNotTypedArray, kBuiltinNameToSpliced);
} label IsDetachedOrOutOfBounds deferred {
ThrowTypeError(MessageTemplate::kDetachedOperation, kBuiltinNameToSpliced);
}
}
}
......@@ -50,22 +50,6 @@ struct TypedArrayElementsInfo {
return (bytes & ((1 << this.sizeLog2) - 1)) != 0;
}
// Computes the data pointer with an offset in number of elements.
macro GetDataPointerOffsetByLength(
array: JSTypedArray, offset: uintptr): RawPtr labels IfInvalid {
const dataPtr = array.data_ptr;
const byteOffset: uintptr =
this.CalculateByteLength(offset) otherwise IfInvalid;
@if(DEBUG) {
const byteLength = LoadJSArrayBufferViewByteLength(array, array.buffer)
otherwise unreachable;
dcheck(byteOffset <= byteLength);
}
return dataPtr + Convert<intptr>(byteOffset);
}
sizeLog2: uintptr;
kind: ElementsKind;
}
......
......@@ -4541,8 +4541,6 @@ void Genesis::InitializeGlobal_harmony_change_array_by_copy() {
isolate());
SimpleInstallFunction(isolate_, prototype, "toReversed",
Builtin::kTypedArrayPrototypeToReversed, 0, true);
SimpleInstallFunction(isolate_, prototype, "toSpliced",
Builtin::kTypedArrayPrototypeToSpliced, 2, false);
SimpleInstallFunction(isolate_, prototype, "with",
Builtin::kTypedArrayPrototypeWith, 2, true);
}
......
This diff is collapsed.
......@@ -543,30 +543,30 @@ KNOWN_OBJECTS = {
("old_space", 0x04a3d): "StringSplitCache",
("old_space", 0x04e45): "RegExpMultipleCache",
("old_space", 0x0524d): "BuiltinsConstantsTable",
("old_space", 0x05691): "AsyncFunctionAwaitRejectSharedFun",
("old_space", 0x056b5): "AsyncFunctionAwaitResolveSharedFun",
("old_space", 0x056d9): "AsyncGeneratorAwaitRejectSharedFun",
("old_space", 0x056fd): "AsyncGeneratorAwaitResolveSharedFun",
("old_space", 0x05721): "AsyncGeneratorYieldResolveSharedFun",
("old_space", 0x05745): "AsyncGeneratorReturnResolveSharedFun",
("old_space", 0x05769): "AsyncGeneratorReturnClosedRejectSharedFun",
("old_space", 0x0578d): "AsyncGeneratorReturnClosedResolveSharedFun",
("old_space", 0x057b1): "AsyncIteratorValueUnwrapSharedFun",
("old_space", 0x057d5): "PromiseAllResolveElementSharedFun",
("old_space", 0x057f9): "PromiseAllSettledResolveElementSharedFun",
("old_space", 0x0581d): "PromiseAllSettledRejectElementSharedFun",
("old_space", 0x05841): "PromiseAnyRejectElementSharedFun",
("old_space", 0x05865): "PromiseCapabilityDefaultRejectSharedFun",
("old_space", 0x05889): "PromiseCapabilityDefaultResolveSharedFun",
("old_space", 0x058ad): "PromiseCatchFinallySharedFun",
("old_space", 0x058d1): "PromiseGetCapabilitiesExecutorSharedFun",
("old_space", 0x058f5): "PromiseThenFinallySharedFun",
("old_space", 0x05919): "PromiseThrowerFinallySharedFun",
("old_space", 0x0593d): "PromiseValueThunkFinallySharedFun",
("old_space", 0x05961): "ProxyRevokeSharedFun",
("old_space", 0x05985): "ShadowRealmImportValueFulfilledSFI",
("old_space", 0x059a9): "SourceTextModuleExecuteAsyncModuleFulfilledSFI",
("old_space", 0x059cd): "SourceTextModuleExecuteAsyncModuleRejectedSFI",
("old_space", 0x0568d): "AsyncFunctionAwaitRejectSharedFun",
("old_space", 0x056b1): "AsyncFunctionAwaitResolveSharedFun",
("old_space", 0x056d5): "AsyncGeneratorAwaitRejectSharedFun",
("old_space", 0x056f9): "AsyncGeneratorAwaitResolveSharedFun",
("old_space", 0x0571d): "AsyncGeneratorYieldResolveSharedFun",
("old_space", 0x05741): "AsyncGeneratorReturnResolveSharedFun",
("old_space", 0x05765): "AsyncGeneratorReturnClosedRejectSharedFun",
("old_space", 0x05789): "AsyncGeneratorReturnClosedResolveSharedFun",
("old_space", 0x057ad): "AsyncIteratorValueUnwrapSharedFun",
("old_space", 0x057d1): "PromiseAllResolveElementSharedFun",
("old_space", 0x057f5): "PromiseAllSettledResolveElementSharedFun",
("old_space", 0x05819): "PromiseAllSettledRejectElementSharedFun",
("old_space", 0x0583d): "PromiseAnyRejectElementSharedFun",
("old_space", 0x05861): "PromiseCapabilityDefaultRejectSharedFun",
("old_space", 0x05885): "PromiseCapabilityDefaultResolveSharedFun",
("old_space", 0x058a9): "PromiseCatchFinallySharedFun",
("old_space", 0x058cd): "PromiseGetCapabilitiesExecutorSharedFun",
("old_space", 0x058f1): "PromiseThenFinallySharedFun",
("old_space", 0x05915): "PromiseThrowerFinallySharedFun",
("old_space", 0x05939): "PromiseValueThunkFinallySharedFun",
("old_space", 0x0595d): "ProxyRevokeSharedFun",
("old_space", 0x05981): "ShadowRealmImportValueFulfilledSFI",
("old_space", 0x059a5): "SourceTextModuleExecuteAsyncModuleFulfilledSFI",
("old_space", 0x059c9): "SourceTextModuleExecuteAsyncModuleRejectedSFI",
}
# Lower 32 bits of first page addresses for various heap spaces.
......
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