summaryrefslogtreecommitdiff
path: root/chromium/v8/src/objects/js-array-buffer.tq
blob: ddd90d4c815825d042bd9cd69706a4ff34f44891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2019 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.

bitfield struct JSArrayBufferFlags extends uint32 {
  is_external: bool: 1 bit;
  is_detachable: bool: 1 bit;
  was_detached: bool: 1 bit;
  is_asm_js_memory: bool: 1 bit;
  is_shared: bool: 1 bit;
  is_resizable: bool: 1 bit;
}

@generateCppClass
extern class JSArrayBuffer extends JSObject {
  byte_length: uintptr;
  max_byte_length: uintptr;
  backing_store: ExternalPointer;
  extension: RawPtr;
  bit_field: JSArrayBufferFlags;
  // Pads header size to be a multiple of kTaggedSize.
  @if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
  @ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
}

extern operator '.backing_store_ptr' macro LoadJSArrayBufferBackingStorePtr(
    JSArrayBuffer): RawPtr;

@export
macro IsDetachedBuffer(buffer: JSArrayBuffer): bool {
  return buffer.bit_field.was_detached;
}

@export
macro IsSharedArrayBuffer(buffer: JSArrayBuffer): bool {
  return buffer.bit_field.is_shared;
}

@export
macro IsResizableArrayBuffer(buffer: JSArrayBuffer): bool {
  return buffer.bit_field.is_resizable;
}

@abstract
@generateCppClass
extern class JSArrayBufferView extends JSObject {
  buffer: JSArrayBuffer;
  byte_offset: uintptr;
  byte_length: uintptr;
}

// We have 4 different TypedArrays:
// 1) Normal (backed by AB / SAB) or non-length tracking backed by GSAB (can't
// go oob once constructed) 2) Non-length tracking backed by RAB (can go oob
// once constructed) 3) Length-tracking backed by RAB (JSArrayBuffer stores the
// length) 4) Length-tracking backed by GSAB (BackingStore stores the length)
bitfield struct JSTypedArrayFlags extends uint32 {
  is_length_tracking: bool: 1 bit;
  is_backed_by_rab: bool: 1 bit;
}

@generateCppClass
extern class JSTypedArray extends JSArrayBufferView {
  length: uintptr;
  external_pointer: ExternalPointer;
  base_pointer: ByteArray|Smi;
  bit_field: JSTypedArrayFlags;
  // Pads header size to be a multiple of kTaggedSize.
  @if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
  @ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
}

@export
macro IsVariableLengthTypedArray(array: JSTypedArray): bool {
  return array.bit_field.is_length_tracking || array.bit_field.is_backed_by_rab;
}

@export
macro IsLengthTrackingTypedArray(array: JSTypedArray): bool {
  return array.bit_field.is_length_tracking;
}

@generateCppClass
extern class JSDataView extends JSArrayBufferView {
  data_pointer: ExternalPointer;
}

@abstract
@doNotGenerateCast extern class TypedArrayConstructor extends JSFunction
    generates 'TNode<JSFunction>';
@doNotGenerateCast
extern class Uint8TypedArrayConstructor extends TypedArrayConstructor
    generates 'TNode<JSFunction>';
@doNotGenerateCast
extern class Int8TypedArrayConstructor extends TypedArrayConstructor
    generates 'TNode<JSFunction>';
@doNotGenerateCast
extern class Uint16TypedArrayConstructor extends TypedArrayConstructor
    generates 'TNode<JSFunction>';
@doNotGenerateCast
extern class Int16TypedArrayConstructor extends TypedArrayConstructor
    generates 'TNode<JSFunction>';
@doNotGenerateCast
extern class Uint32TypedArrayConstructor extends TypedArrayConstructor
    generates 'TNode<JSFunction>';
@doNotGenerateCast
extern class Int32TypedArrayConstructor extends TypedArrayConstructor
    generates 'TNode<JSFunction>';
@doNotGenerateCast
extern class Float32TypedArrayConstructor extends TypedArrayConstructor
    generates 'TNode<JSFunction>';
@doNotGenerateCast
extern class Float64TypedArrayConstructor extends TypedArrayConstructor
    generates 'TNode<JSFunction>';
@doNotGenerateCast
extern class Uint8ClampedTypedArrayConstructor extends TypedArrayConstructor
    generates 'TNode<JSFunction>';
@doNotGenerateCast
extern class Biguint64TypedArrayConstructor extends TypedArrayConstructor
    generates 'TNode<JSFunction>';
@doNotGenerateCast
extern class Bigint64TypedArrayConstructor extends TypedArrayConstructor
    generates 'TNode<JSFunction>';