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 [
102107 assert ( ! types . isInt32Array ( { [ Symbol . toStringTag ] : 'Int32Array' } ) ) ;
103108 assert ( types . isInt32Array ( vm . runInNewContext ( 'new Int32Array' ) ) ) ;
104109
110+ assert ( ! types . isFloat16Array ( { [ Symbol . toStringTag ] : 'Float16Array' } ) ) ;
111+ assert ( types . isFloat16Array ( vm . runInNewContext ( 'new Float16Array' ) ) ) ;
112+
105113 assert ( ! types . isFloat32Array ( { [ Symbol . toStringTag ] : 'Float32Array' } ) ) ;
106114 assert ( types . isFloat32Array ( vm . runInNewContext ( 'new Float32Array' ) ) ) ;
107115
@@ -127,6 +135,7 @@ for (const [ value, _method ] of [
127135 const int8Array = new Int8Array ( arrayBuffer ) ;
128136 const int16Array = new Int16Array ( arrayBuffer ) ;
129137 const int32Array = new Int32Array ( arrayBuffer ) ;
138+ const float16Array = new Float16Array ( arrayBuffer ) ;
130139 const float32Array = new Float32Array ( arrayBuffer ) ;
131140 const float64Array = new Float64Array ( arrayBuffer ) ;
132141 const bigInt64Array = new BigInt64Array ( arrayBuffer ) ;
@@ -141,6 +150,7 @@ for (const [ value, _method ] of [
141150 const fakeInt8Array = { __proto__ : Int8Array . prototype } ;
142151 const fakeInt16Array = { __proto__ : Int16Array . prototype } ;
143152 const fakeInt32Array = { __proto__ : Int32Array . prototype } ;
153+ const fakeFloat16Array = { __proto__ : Float16Array . prototype } ;
144154 const fakeFloat32Array = { __proto__ : Float32Array . prototype } ;
145155 const fakeFloat64Array = { __proto__ : Float64Array . prototype } ;
146156 const fakeBigInt64Array = { __proto__ : BigInt64Array . prototype } ;
@@ -164,6 +174,10 @@ for (const [ value, _method ] of [
164174 Object . setPrototypeOf ( new Int16Array ( arrayBuffer ) , Int16Array . prototype ) ;
165175 const stealthyInt32Array =
166176 Object . setPrototypeOf ( new Int32Array ( arrayBuffer ) , Int32Array . prototype ) ;
177+ const stealthyFloat16Array =
178+ Object . setPrototypeOf (
179+ new Float16Array ( arrayBuffer ) , Float16Array . prototype
180+ ) ;
167181 const stealthyFloat32Array =
168182 Object . setPrototypeOf (
169183 new Float32Array ( arrayBuffer ) , Float32Array . prototype
@@ -191,6 +205,7 @@ for (const [ value, _method ] of [
191205 int8Array , fakeInt8Array , stealthyInt8Array ,
192206 int16Array , fakeInt16Array , stealthyInt16Array ,
193207 int32Array , fakeInt32Array , stealthyInt32Array ,
208+ float16Array , fakeFloat16Array , stealthyFloat16Array ,
194209 float32Array , fakeFloat32Array , stealthyFloat32Array ,
195210 float64Array , fakeFloat64Array , stealthyFloat64Array ,
196211 bigInt64Array , fakeBigInt64Array , stealthyBigInt64Array ,
@@ -208,6 +223,7 @@ for (const [ value, _method ] of [
208223 int8Array , stealthyInt8Array ,
209224 int16Array , stealthyInt16Array ,
210225 int32Array , stealthyInt32Array ,
226+ float16Array , stealthyFloat16Array ,
211227 float32Array , stealthyFloat32Array ,
212228 float64Array , stealthyFloat64Array ,
213229 bigInt64Array , stealthyBigInt64Array ,
@@ -222,6 +238,7 @@ for (const [ value, _method ] of [
222238 int8Array , stealthyInt8Array ,
223239 int16Array , stealthyInt16Array ,
224240 int32Array , stealthyInt32Array ,
241+ float16Array , stealthyFloat16Array ,
225242 float32Array , stealthyFloat32Array ,
226243 float64Array , stealthyFloat64Array ,
227244 bigInt64Array , stealthyBigInt64Array ,
@@ -248,6 +265,9 @@ for (const [ value, _method ] of [
248265 isInt32Array : [
249266 int32Array , stealthyInt32Array ,
250267 ] ,
268+ isFloat16Array : [
269+ float16Array , stealthyFloat16Array ,
270+ ] ,
251271 isFloat32Array : [
252272 float32Array , stealthyFloat32Array ,
253273 ] ,
0 commit comments