11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cibitfield struct JSArrayBufferFlags extends uint32 { 61cb0ef41Sopenharmony_ci is_external: bool: 1 bit; 71cb0ef41Sopenharmony_ci is_detachable: bool: 1 bit; 81cb0ef41Sopenharmony_ci was_detached: bool: 1 bit; 91cb0ef41Sopenharmony_ci is_asm_js_memory: bool: 1 bit; 101cb0ef41Sopenharmony_ci is_shared: bool: 1 bit; 111cb0ef41Sopenharmony_ci is_resizable: bool: 1 bit; 121cb0ef41Sopenharmony_ci} 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciextern class JSArrayBuffer extends JSObjectWithEmbedderSlots { 151cb0ef41Sopenharmony_ci byte_length: uintptr; 161cb0ef41Sopenharmony_ci max_byte_length: uintptr; 171cb0ef41Sopenharmony_ci // A SandboxedPtr if the sandbox is enabled 181cb0ef41Sopenharmony_ci backing_store: RawPtr; 191cb0ef41Sopenharmony_ci extension: RawPtr; 201cb0ef41Sopenharmony_ci bit_field: JSArrayBufferFlags; 211cb0ef41Sopenharmony_ci // Pads header size to be a multiple of kTaggedSize. 221cb0ef41Sopenharmony_ci @if(TAGGED_SIZE_8_BYTES) optional_padding: uint32; 231cb0ef41Sopenharmony_ci @ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void; 241cb0ef41Sopenharmony_ci} 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciextern operator '.backing_store_ptr' macro LoadJSArrayBufferBackingStorePtr( 271cb0ef41Sopenharmony_ci JSArrayBuffer): RawPtr; 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci@export 301cb0ef41Sopenharmony_cimacro IsDetachedBuffer(buffer: JSArrayBuffer): bool { 311cb0ef41Sopenharmony_ci return buffer.bit_field.was_detached; 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci@export 351cb0ef41Sopenharmony_cimacro IsSharedArrayBuffer(buffer: JSArrayBuffer): bool { 361cb0ef41Sopenharmony_ci return buffer.bit_field.is_shared; 371cb0ef41Sopenharmony_ci} 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci@export 401cb0ef41Sopenharmony_cimacro IsResizableArrayBuffer(buffer: JSArrayBuffer): bool { 411cb0ef41Sopenharmony_ci return buffer.bit_field.is_resizable; 421cb0ef41Sopenharmony_ci} 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci// We have 4 different DataViews & TypedArrays: 451cb0ef41Sopenharmony_ci// 1) Normal (backed by AB / SAB) or non-length tracking backed by GSAB (can't 461cb0ef41Sopenharmony_ci// go oob once constructed) 471cb0ef41Sopenharmony_ci// 2) Non-length tracking backed by RAB (can go oob once constructed) 481cb0ef41Sopenharmony_ci// 3) Length-tracking backed by RAB (JSArrayBuffer stores the length) 491cb0ef41Sopenharmony_ci// 4) Length-tracking backed by GSAB (BackingStore stores the length) 501cb0ef41Sopenharmony_cibitfield struct JSArrayBufferViewFlags extends uint32 { 511cb0ef41Sopenharmony_ci is_length_tracking: bool: 1 bit; 521cb0ef41Sopenharmony_ci is_backed_by_rab: bool: 1 bit; 531cb0ef41Sopenharmony_ci} 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci@abstract 561cb0ef41Sopenharmony_ciextern class JSArrayBufferView extends JSObjectWithEmbedderSlots { 571cb0ef41Sopenharmony_ci buffer: JSArrayBuffer; 581cb0ef41Sopenharmony_ci byte_offset: uintptr; 591cb0ef41Sopenharmony_ci byte_length: uintptr; 601cb0ef41Sopenharmony_ci bit_field: JSArrayBufferViewFlags; 611cb0ef41Sopenharmony_ci // Pads header size to be a multiple of kTaggedSize. 621cb0ef41Sopenharmony_ci @if(TAGGED_SIZE_8_BYTES) optional_padding: uint32; 631cb0ef41Sopenharmony_ci @ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void; 641cb0ef41Sopenharmony_ci} 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci@export 671cb0ef41Sopenharmony_cimacro IsVariableLengthJSArrayBufferView(array: JSArrayBufferView): bool { 681cb0ef41Sopenharmony_ci return array.bit_field.is_length_tracking || array.bit_field.is_backed_by_rab; 691cb0ef41Sopenharmony_ci} 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci@export 721cb0ef41Sopenharmony_cimacro IsLengthTrackingJSArrayBufferView(array: JSArrayBufferView): bool { 731cb0ef41Sopenharmony_ci return array.bit_field.is_length_tracking; 741cb0ef41Sopenharmony_ci} 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ciextern macro LoadVariableLengthJSArrayBufferViewByteLength( 771cb0ef41Sopenharmony_ci JSArrayBufferView, JSArrayBuffer): uintptr labels DetachedOrOutOfBounds; 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_cimacro LoadJSArrayBufferViewByteLength( 801cb0ef41Sopenharmony_ci view: JSArrayBufferView, 811cb0ef41Sopenharmony_ci buffer: JSArrayBuffer): uintptr labels DetachedOrOutOfBounds { 821cb0ef41Sopenharmony_ci if (IsVariableLengthJSArrayBufferView(view)) { 831cb0ef41Sopenharmony_ci return LoadVariableLengthJSArrayBufferViewByteLength(view, buffer) 841cb0ef41Sopenharmony_ci otherwise DetachedOrOutOfBounds; 851cb0ef41Sopenharmony_ci } 861cb0ef41Sopenharmony_ci if (IsDetachedBuffer(buffer)) goto DetachedOrOutOfBounds; 871cb0ef41Sopenharmony_ci return view.byte_length; 881cb0ef41Sopenharmony_ci} 891cb0ef41Sopenharmony_ci 901cb0ef41Sopenharmony_ciextern class JSTypedArray extends JSArrayBufferView { 911cb0ef41Sopenharmony_ci length: uintptr; 921cb0ef41Sopenharmony_ci // A SandboxedPtr if the sandbox is enabled 931cb0ef41Sopenharmony_ci external_pointer: RawPtr; 941cb0ef41Sopenharmony_ci base_pointer: ByteArray|Smi; 951cb0ef41Sopenharmony_ci} 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci@export 981cb0ef41Sopenharmony_cimacro IsOnHeapTypedArray(array: JSTypedArray): bool { 991cb0ef41Sopenharmony_ci // See JSTypedArray::is_on_heap() 1001cb0ef41Sopenharmony_ci return TaggedNotEqual(array.base_pointer, SmiConstant(0)); 1011cb0ef41Sopenharmony_ci} 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ciextern class JSDataView extends JSArrayBufferView { 1041cb0ef41Sopenharmony_ci // A SandboxedPtr if the sandbox is enabled 1051cb0ef41Sopenharmony_ci data_pointer: RawPtr; 1061cb0ef41Sopenharmony_ci} 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ci@abstract 1091cb0ef41Sopenharmony_ci@doNotGenerateCast extern class TypedArrayConstructor extends JSFunction 1101cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 1111cb0ef41Sopenharmony_ci@doNotGenerateCast 1121cb0ef41Sopenharmony_ciextern class Uint8TypedArrayConstructor extends TypedArrayConstructor 1131cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 1141cb0ef41Sopenharmony_ci@doNotGenerateCast 1151cb0ef41Sopenharmony_ciextern class Int8TypedArrayConstructor extends TypedArrayConstructor 1161cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 1171cb0ef41Sopenharmony_ci@doNotGenerateCast 1181cb0ef41Sopenharmony_ciextern class Uint16TypedArrayConstructor extends TypedArrayConstructor 1191cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 1201cb0ef41Sopenharmony_ci@doNotGenerateCast 1211cb0ef41Sopenharmony_ciextern class Int16TypedArrayConstructor extends TypedArrayConstructor 1221cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 1231cb0ef41Sopenharmony_ci@doNotGenerateCast 1241cb0ef41Sopenharmony_ciextern class Uint32TypedArrayConstructor extends TypedArrayConstructor 1251cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 1261cb0ef41Sopenharmony_ci@doNotGenerateCast 1271cb0ef41Sopenharmony_ciextern class Int32TypedArrayConstructor extends TypedArrayConstructor 1281cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 1291cb0ef41Sopenharmony_ci@doNotGenerateCast 1301cb0ef41Sopenharmony_ciextern class Float32TypedArrayConstructor extends TypedArrayConstructor 1311cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 1321cb0ef41Sopenharmony_ci@doNotGenerateCast 1331cb0ef41Sopenharmony_ciextern class Float64TypedArrayConstructor extends TypedArrayConstructor 1341cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 1351cb0ef41Sopenharmony_ci@doNotGenerateCast 1361cb0ef41Sopenharmony_ciextern class Uint8ClampedTypedArrayConstructor extends TypedArrayConstructor 1371cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 1381cb0ef41Sopenharmony_ci@doNotGenerateCast 1391cb0ef41Sopenharmony_ciextern class Biguint64TypedArrayConstructor extends TypedArrayConstructor 1401cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 1411cb0ef41Sopenharmony_ci@doNotGenerateCast 1421cb0ef41Sopenharmony_ciextern class Bigint64TypedArrayConstructor extends TypedArrayConstructor 1431cb0ef41Sopenharmony_ci generates 'TNode<JSFunction>'; 144