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
23'use strict' ;
34const common = require ( '../common' ) ;
45const assert = require ( 'assert' ) ;
@@ -9,6 +10,9 @@ const { JSStream } = internalBinding('js_stream');
910
1011const external = ( new JSStream ( ) ) . _externalStream ;
1112
13+ // TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line
14+ const { Float16Array } = globalThis ;
15+
1216for ( const [ value , _method ] of [
1317[ external , 'isExternal' ] ,
1418[ new Date ( ) ] ,
@@ -38,6 +42,7 @@ for (const [ value, _method ] of [
3842[ new Int8Array ( ) ] ,
3943[ new Int16Array ( ) ] ,
4044[ new Int32Array ( ) ] ,
45+ [ new Float16Array ( ) ] ,
4146[ new Float32Array ( ) ] ,
4247[ new Float64Array ( ) ] ,
4348[ new BigInt64Array ( ) ] ,
@@ -102,6 +107,9 @@ for (const [ value, _method ] of [
102107assert ( ! types . isInt32Array ( { [ Symbol . toStringTag ] : 'Int32Array' } ) ) ;
103108assert ( types . isInt32Array ( vm . runInNewContext ( 'new Int32Array' ) ) ) ;
104109
110+ assert ( ! types . isFloat16Array ( { [ Symbol . toStringTag ] : 'Float16Array' } ) ) ;
111+ assert ( types . isFloat16Array ( vm . runInNewContext ( 'new Float16Array' ) ) ) ;
112+
105113assert ( ! types . isFloat32Array ( { [ Symbol . toStringTag ] : 'Float32Array' } ) ) ;
106114assert ( types . isFloat32Array ( vm . runInNewContext ( 'new Float32Array' ) ) ) ;
107115
@@ -127,6 +135,7 @@ for (const [ value, _method ] of [
127135const int8Array = new Int8Array ( arrayBuffer ) ;
128136const int16Array = new Int16Array ( arrayBuffer ) ;
129137const int32Array = new Int32Array ( arrayBuffer ) ;
138+ const float16Array = new Float16Array ( arrayBuffer ) ;
130139const float32Array = new Float32Array ( arrayBuffer ) ;
131140const float64Array = new Float64Array ( arrayBuffer ) ;
132141const bigInt64Array = new BigInt64Array ( arrayBuffer ) ;
@@ -141,6 +150,7 @@ for (const [ value, _method ] of [
141150const fakeInt8Array = { __proto__ : Int8Array . prototype } ;
142151const fakeInt16Array = { __proto__ : Int16Array . prototype } ;
143152const fakeInt32Array = { __proto__ : Int32Array . prototype } ;
153+ const fakeFloat16Array = { __proto__ : Float16Array . prototype } ;
144154const fakeFloat32Array = { __proto__ : Float32Array . prototype } ;
145155const fakeFloat64Array = { __proto__ : Float64Array . prototype } ;
146156const fakeBigInt64Array = { __proto__ : BigInt64Array . prototype } ;
@@ -164,6 +174,10 @@ for (const [ value, _method ] of [
164174Object . setPrototypeOf ( new Int16Array ( arrayBuffer ) , Int16Array . prototype ) ;
165175const stealthyInt32Array =
166176Object . setPrototypeOf ( new Int32Array ( arrayBuffer ) , Int32Array . prototype ) ;
177+ const stealthyFloat16Array =
178+ Object . setPrototypeOf (
179+ new Float16Array ( arrayBuffer ) , Float16Array . prototype
180+ ) ;
167181const stealthyFloat32Array =
168182Object . setPrototypeOf (
169183new Float32Array ( arrayBuffer ) , Float32Array . prototype
@@ -191,6 +205,7 @@ for (const [ value, _method ] of [
191205int8Array , fakeInt8Array , stealthyInt8Array ,
192206int16Array , fakeInt16Array , stealthyInt16Array ,
193207int32Array , fakeInt32Array , stealthyInt32Array ,
208+ float16Array , fakeFloat16Array , stealthyFloat16Array ,
194209float32Array , fakeFloat32Array , stealthyFloat32Array ,
195210float64Array , fakeFloat64Array , stealthyFloat64Array ,
196211bigInt64Array , fakeBigInt64Array , stealthyBigInt64Array ,
@@ -208,6 +223,7 @@ for (const [ value, _method ] of [
208223int8Array , stealthyInt8Array ,
209224int16Array , stealthyInt16Array ,
210225int32Array , stealthyInt32Array ,
226+ float16Array , stealthyFloat16Array ,
211227float32Array , stealthyFloat32Array ,
212228float64Array , stealthyFloat64Array ,
213229bigInt64Array , stealthyBigInt64Array ,
@@ -222,6 +238,7 @@ for (const [ value, _method ] of [
222238int8Array , stealthyInt8Array ,
223239int16Array , stealthyInt16Array ,
224240int32Array , stealthyInt32Array ,
241+ float16Array , stealthyFloat16Array ,
225242float32Array , stealthyFloat32Array ,
226243float64Array , stealthyFloat64Array ,
227244bigInt64Array , stealthyBigInt64Array ,
@@ -248,6 +265,9 @@ for (const [ value, _method ] of [
248265isInt32Array : [
249266int32Array , stealthyInt32Array ,
250267] ,
268+ isFloat16Array : [
269+ float16Array , stealthyFloat16Array ,
270+ ] ,
251271isFloat32Array : [
252272float32Array , stealthyFloat32Array ,
253273] ,
0 commit comments