@@ -31,7 +31,12 @@ const notGlobals = new Set([
3131
3232for ( const [ name , primordialStaging ] of Object . entries ( primordialsStaging ) ) {
3333 assert . ok ( ! ( name in primordials ) , `${ name } is already in primordials. Consider removing it from 'internal/primordials_staging'` ) ;
34- assert . notStrictEqual ( primordialStaging , undefined , `${ name } is expected to exist. If it's new, the test requires runtime flag.` ) ;
34+
35+ // Do not treat missing builtins as error, because they might be disabled in this build
36+ if ( primordialStaging === undefined ) {
37+ console . log ( `${ name } is expected to exist. If it's new and not intentinally disabled, the test requires runtime flag.` ) ;
38+ continue ;
39+ }
3540
3641 if ( ! notGlobals . has ( name ) ) {
3742 originalGlobals [ name ] = globalThis [ name ] ;
@@ -41,31 +46,53 @@ for (const [ name, primordialStaging ] of Object.entries(primordialsStaging)) {
4146 }
4247}
4348
44- // Safe Temporal must work
45- {
46- const { Temporal : { Instant, Now } } = primordialsStaging ;
47- assert . ok ( Now . instant ( ) instanceof Instant ) ;
48- assert . strictEqual ( new Instant ( 123456789n ) . epochMilliseconds , 123 ) ;
49+ if ( primordialsStaging . Temporal !== undefined || globalThis . Temporal !== undefined ) {
50+ // Safe Temporal must work
51+ {
52+ const { Temporal : { Instant, Now } } = primordialsStaging ;
53+ assert . ok ( Now . instant ( ) instanceof Instant ) ;
54+ assert . strictEqual ( new Instant ( 123456789n ) . epochMilliseconds , 123 ) ;
55+ }
56+
57+ // Global Temporal must break
58+ {
59+ assert . throws ( ( ) => {
60+ // eslint-disable-next-line no-unused-vars
61+ const { Temporal : { Instant, Now } } = globalThis ;
62+ } , {
63+ code : 'ERR_ASSERTION' ,
64+ } ) ;
65+ assert . throws ( ( ) => {
66+ // eslint-disable-next-line no-unused-expressions
67+ Temporal . Now . instant ( ) instanceof Temporal . Instant ;
68+ } , {
69+ code : 'ERR_ASSERTION' ,
70+ } ) ;
71+ assert . throws ( ( ) => {
72+ // eslint-disable-next-line no-unused-expressions
73+ new Temporal . Instant ( 123456789n ) . epochMilliseconds ;
74+ } , {
75+ code : 'ERR_ASSERTION' ,
76+ } ) ;
77+ }
4978}
5079
51- // Global Temporal must break
52- {
53- assert . throws ( ( ) => {
54- // eslint-disable-next-line no-unused-vars
55- const { Temporal : { Instant, Now } } = globalThis ;
56- } , {
57- code : 'ERR_ASSERTION' ,
58- } ) ;
59- assert . throws ( ( ) => {
60- // eslint-disable-next-line no-unused-expressions
61- Temporal . Now . instant ( ) instanceof Temporal . Instant ;
62- } , {
63- code : 'ERR_ASSERTION' ,
64- } ) ;
65- assert . throws ( ( ) => {
66- // eslint-disable-next-line no-unused-expressions
67- new Temporal . Instant ( 123456789n ) . epochMilliseconds ;
68- } , {
69- code : 'ERR_ASSERTION' ,
70- } ) ;
80+ if ( primordialsStaging . Float16Array !== undefined || globalThis . Float16Array !== undefined ) {
81+ // Safe Float16Array must work
82+ {
83+ const { Float16Array } = primordialsStaging ;
84+ const buffer = new Float16Array ( [ 1 , 2 , 3 ] ) ;
85+ assert . ok ( buffer instanceof Float16Array ) ;
86+ assert . strictEqual ( buffer . byteLength , 6 ) ;
87+ }
88+
89+ // Global Float16Array must not work
90+ {
91+ const { Float16Array } = globalThis ;
92+ assert . throws ( ( ) => {
93+ new Float16Array ( [ 1 , 2 , 3 ] ) ;
94+ } , {
95+ name : 'TypeError' ,
96+ } ) ;
97+ }
7198}
0 commit comments