summaryrefslogtreecommitdiff
path: root/deps/v8/src/builtins/typed-array-createtypedarray.tq
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/builtins/typed-array-createtypedarray.tq')
-rw-r--r--deps/v8/src/builtins/typed-array-createtypedarray.tq51
1 files changed, 21 insertions, 30 deletions
diff --git a/deps/v8/src/builtins/typed-array-createtypedarray.tq b/deps/v8/src/builtins/typed-array-createtypedarray.tq
index 31be407e52..a0d745b2f4 100644
--- a/deps/v8/src/builtins/typed-array-createtypedarray.tq
+++ b/deps/v8/src/builtins/typed-array-createtypedarray.tq
@@ -12,26 +12,18 @@ namespace typed_array_createtypedarray {
implicit context: Context)(JSFunction, JSReceiver): JSTypedArray;
extern macro TypedArrayBuiltinsAssembler::AllocateEmptyOnHeapBuffer(
implicit context: Context)(JSTypedArray, uintptr): JSArrayBuffer;
- extern macro TypedArrayBuiltinsAssembler::AllocateOnHeapElements(
- Map, intptr, Number): FixedTypedArrayBase;
extern macro TypedArrayBuiltinsAssembler::GetDefaultConstructor(
implicit context: Context)(JSTypedArray): JSFunction;
extern macro TypedArrayBuiltinsAssembler::IsSharedArrayBuffer(JSArrayBuffer):
bool;
extern macro TypedArrayBuiltinsAssembler::SetupTypedArray(
- JSTypedArray, Smi, uintptr, uintptr): void;
+ JSTypedArray, uintptr, uintptr, uintptr): void;
extern runtime ThrowInvalidTypedArrayAlignment(implicit context: Context)(
Map, String): never;
extern runtime TypedArrayCopyElements(Context, JSTypedArray, Object, Number):
void;
- macro CalculateTotalElementsByteSize(byteLength: intptr): intptr {
- return (kFixedTypedArrayBaseHeaderSize + kObjectAlignmentMask +
- byteLength) &
- ~kObjectAlignmentMask;
- }
-
transitioning macro TypedArrayInitialize(implicit context: Context)(
initialize: constexpr bool, typedArray: JSTypedArray, length: PositiveSmi,
elementsInfo: typed_array::TypedArrayElementsInfo,
@@ -51,14 +43,8 @@ namespace typed_array_createtypedarray {
AllocateEmptyOnHeapBuffer(typedArray, byteLength);
- const totalSize =
- CalculateTotalElementsByteSize(Convert<intptr>(byteLength));
- const elements =
- AllocateOnHeapElements(elementsInfo.map, totalSize, length);
- typedArray.elements = elements;
-
if constexpr (initialize) {
- const backingStore = LoadFixedTypedArrayOnHeapBackingStore(elements);
+ const backingStore = typedArray.data_ptr;
typed_array::CallCMemset(backingStore, 0, byteLength);
}
}
@@ -73,12 +59,12 @@ namespace typed_array_createtypedarray {
label AttachOffHeapBuffer(bufferObj: Object) {
const buffer = Cast<JSArrayBuffer>(bufferObj) otherwise unreachable;
const byteOffset: uintptr = 0;
- typedArray.AttachOffHeapBuffer(
- buffer, elementsInfo.map, length, byteOffset);
+ typedArray.AttachOffHeapBuffer(buffer, byteOffset);
}
const byteOffset: uintptr = 0;
- SetupTypedArray(typedArray, length, byteOffset, byteLength);
+ SetupTypedArray(
+ typedArray, Convert<uintptr>(length), byteOffset, byteLength);
return byteLength;
}
@@ -126,7 +112,7 @@ namespace typed_array_createtypedarray {
goto IfSlow;
} else if (length > 0) {
- assert(byteLength <= kTypedArrayMaxByteLength);
+ assert(byteLength <= kArrayBufferMaxByteLength);
typed_array::CallCMemcpy(typedArray.data_ptr, src.data_ptr, byteLength);
}
}
@@ -157,7 +143,9 @@ namespace typed_array_createtypedarray {
let bufferConstructor: JSReceiver = GetArrayBufferFunction();
const srcBuffer: JSArrayBuffer = srcTypedArray.buffer;
// TODO(petermarshall): Throw on detached typedArray.
- let length: Smi = IsDetachedBuffer(srcBuffer) ? 0 : srcTypedArray.length;
+ // TODO(v8:4156): Update this to support huge TypedArrays.
+ let length =
+ IsDetachedBuffer(srcBuffer) ? 0 : Convert<Number>(srcTypedArray.length);
// The spec requires that constructing a typed array using a SAB-backed
// typed array use the ArrayBuffer constructor, not the species constructor.
@@ -236,9 +224,9 @@ namespace typed_array_createtypedarray {
goto IfInvalidLength;
}
- SetupTypedArray(typedArray, newLength, offset, newByteLength);
- typedArray.AttachOffHeapBuffer(
- buffer, elementsInfo.map, newLength, offset);
+ SetupTypedArray(
+ typedArray, Convert<uintptr>(newLength), offset, newByteLength);
+ typedArray.AttachOffHeapBuffer(buffer, offset);
}
label IfInvalidAlignment(problemString: String) deferred {
ThrowInvalidTypedArrayAlignment(typedArray.map, problemString);
@@ -288,11 +276,14 @@ namespace typed_array_createtypedarray {
const array: JSTypedArray = EmitFastNewObject(target, newTarget);
// We need to set the byte_offset / byte_length to some sane values
// to keep the heap verifier happy.
- // TODO(bmeurer): Fix this initialization to not use EmitFastNewObject,
- // which causes the problem, since it puts Undefined into all slots of
- // the object even though that doesn't make any sense for these fields.
+ // TODO(bmeurer, v8:4153): Fix this initialization to not use
+ // EmitFastNewObject, which causes the problem, since it puts
+ // Undefined into all slots of the object even though that
+ // doesn't make any sense for these fields.
array.byte_offset = 0;
array.byte_length = 0;
+ array.length = 0;
+ array.base_pointer = Convert<Smi>(0);
// 5. Let elementSize be the Number value of the Element Size value in Table
// 56 for constructorName.
@@ -371,15 +362,15 @@ namespace typed_array_createtypedarray {
}
}
+ @export
transitioning macro TypedArraySpeciesCreateByLength(implicit context:
Context)(
methodName: constexpr string, exemplar: JSTypedArray,
- length: Smi): JSTypedArray {
- assert(Is<PositiveSmi>(length));
+ length: PositiveSmi): JSTypedArray {
const numArgs: constexpr int31 = 1;
const typedArray: JSTypedArray = TypedArraySpeciesCreate(
methodName, numArgs, exemplar, length, Undefined, Undefined);
- if (typedArray.length < length) deferred {
+ if (typedArray.length < Convert<uintptr>(length)) deferred {
ThrowTypeError(kTypedArrayTooShort);
}