1
- // Flags: --experimental-vm-modules --expose-internals --allow-natives-syntax
1
+ // Flags: --experimental-vm-modules --expose-internals --allow-natives-syntax --js-float16array
2
+ // TODO(LiviaMedeiros): once `Float16Array` is unflagged in v8, remove `--js-float16array` above
2
3
'use strict' ;
3
4
const common = require ( '../common' ) ;
4
5
const assert = require ( 'assert' ) ;
@@ -9,6 +10,9 @@ const { JSStream } = internalBinding('js_stream');
9
10
10
11
const external = ( new JSStream ( ) ) . _externalStream ;
11
12
13
+ // TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line
14
+ const { Float16Array } = globalThis ;
15
+
12
16
for ( const [ value , _method ] of [
13
17
[ external , 'isExternal' ] ,
14
18
[ new Date ( ) ] ,
@@ -38,6 +42,7 @@ for (const [ value, _method ] of [
38
42
[ new Int8Array ( ) ] ,
39
43
[ new Int16Array ( ) ] ,
40
44
[ new Int32Array ( ) ] ,
45
+ [ new Float16Array ( ) ] ,
41
46
[ new Float32Array ( ) ] ,
42
47
[ new Float64Array ( ) ] ,
43
48
[ new BigInt64Array ( ) ] ,
@@ -102,6 +107,9 @@ for (const [ value, _method ] of [
102
107
assert ( ! types . isInt32Array ( { [ Symbol . toStringTag ] : 'Int32Array' } ) ) ;
103
108
assert ( types . isInt32Array ( vm . runInNewContext ( 'new Int32Array' ) ) ) ;
104
109
110
+ assert ( ! types . isFloat16Array ( { [ Symbol . toStringTag ] : 'Float16Array' } ) ) ;
111
+ assert ( types . isFloat16Array ( vm . runInNewContext ( 'new Float16Array' ) ) ) ;
112
+
105
113
assert ( ! types . isFloat32Array ( { [ Symbol . toStringTag ] : 'Float32Array' } ) ) ;
106
114
assert ( types . isFloat32Array ( vm . runInNewContext ( 'new Float32Array' ) ) ) ;
107
115
@@ -127,6 +135,7 @@ for (const [ value, _method ] of [
127
135
const int8Array = new Int8Array ( arrayBuffer ) ;
128
136
const int16Array = new Int16Array ( arrayBuffer ) ;
129
137
const int32Array = new Int32Array ( arrayBuffer ) ;
138
+ const float16Array = new Float16Array ( arrayBuffer ) ;
130
139
const float32Array = new Float32Array ( arrayBuffer ) ;
131
140
const float64Array = new Float64Array ( arrayBuffer ) ;
132
141
const bigInt64Array = new BigInt64Array ( arrayBuffer ) ;
@@ -141,6 +150,7 @@ for (const [ value, _method ] of [
141
150
const fakeInt8Array = { __proto__ : Int8Array . prototype } ;
142
151
const fakeInt16Array = { __proto__ : Int16Array . prototype } ;
143
152
const fakeInt32Array = { __proto__ : Int32Array . prototype } ;
153
+ const fakeFloat16Array = { __proto__ : Float16Array . prototype } ;
144
154
const fakeFloat32Array = { __proto__ : Float32Array . prototype } ;
145
155
const fakeFloat64Array = { __proto__ : Float64Array . prototype } ;
146
156
const fakeBigInt64Array = { __proto__ : BigInt64Array . prototype } ;
@@ -164,6 +174,10 @@ for (const [ value, _method ] of [
164
174
Object . setPrototypeOf ( new Int16Array ( arrayBuffer ) , Int16Array . prototype ) ;
165
175
const stealthyInt32Array =
166
176
Object . setPrototypeOf ( new Int32Array ( arrayBuffer ) , Int32Array . prototype ) ;
177
+ const stealthyFloat16Array =
178
+ Object . setPrototypeOf (
179
+ new Float16Array ( arrayBuffer ) , Float16Array . prototype
180
+ ) ;
167
181
const stealthyFloat32Array =
168
182
Object . setPrototypeOf (
169
183
new Float32Array ( arrayBuffer ) , Float32Array . prototype
@@ -191,6 +205,7 @@ for (const [ value, _method ] of [
191
205
int8Array , fakeInt8Array , stealthyInt8Array ,
192
206
int16Array , fakeInt16Array , stealthyInt16Array ,
193
207
int32Array , fakeInt32Array , stealthyInt32Array ,
208
+ float16Array , fakeFloat16Array , stealthyFloat16Array ,
194
209
float32Array , fakeFloat32Array , stealthyFloat32Array ,
195
210
float64Array , fakeFloat64Array , stealthyFloat64Array ,
196
211
bigInt64Array , fakeBigInt64Array , stealthyBigInt64Array ,
@@ -208,6 +223,7 @@ for (const [ value, _method ] of [
208
223
int8Array , stealthyInt8Array ,
209
224
int16Array , stealthyInt16Array ,
210
225
int32Array , stealthyInt32Array ,
226
+ float16Array , stealthyFloat16Array ,
211
227
float32Array , stealthyFloat32Array ,
212
228
float64Array , stealthyFloat64Array ,
213
229
bigInt64Array , stealthyBigInt64Array ,
@@ -222,6 +238,7 @@ for (const [ value, _method ] of [
222
238
int8Array , stealthyInt8Array ,
223
239
int16Array , stealthyInt16Array ,
224
240
int32Array , stealthyInt32Array ,
241
+ float16Array , stealthyFloat16Array ,
225
242
float32Array , stealthyFloat32Array ,
226
243
float64Array , stealthyFloat64Array ,
227
244
bigInt64Array , stealthyBigInt64Array ,
@@ -248,6 +265,9 @@ for (const [ value, _method ] of [
248
265
isInt32Array : [
249
266
int32Array , stealthyInt32Array ,
250
267
] ,
268
+ isFloat16Array : [
269
+ float16Array , stealthyFloat16Array ,
270
+ ] ,
251
271
isFloat32Array : [
252
272
float32Array , stealthyFloat32Array ,
253
273
] ,
0 commit comments