@@ -66,6 +66,22 @@ const EXPECT_INVALID = false;
6666
6767/* DATA **********************************************************************/
6868
69+ let hostrefs = { } ;
70+ let hostsym = Symbol ( "hostref" ) ;
71+ function hostref ( s ) {
72+ if ( ! ( s in hostrefs ) ) hostrefs [ s ] = { [ hostsym ] : s } ;
73+ return hostrefs [ s ] ;
74+ }
75+ function is_hostref ( x ) {
76+ return ( x !== null && hostsym in x ) ? 1 : 0 ;
77+ }
78+ function is_funcref ( x ) {
79+ return typeof x === "function" ? 1 : 0 ;
80+ }
81+ function eq_ref ( x , y ) {
82+ return x === y ? 1 : 0 ;
83+ }
84+
6985let $$ ;
7086
7187// Default imports.
@@ -77,6 +93,10 @@ function reinitializeRegistry() {
7793 return ;
7894
7995 let spectest = {
96+ hostref : hostref ,
97+ is_hostref : is_hostref ,
98+ is_funcref : is_funcref ,
99+ eq_ref : eq_ref ,
80100 print : console . log . bind ( console ) ,
81101 print_i32 : console . log . bind ( console ) ,
82102 print_i32_f32 : console . log . bind ( console ) ,
@@ -228,13 +248,13 @@ function get(instance, name) {
228248 return ValueResult ( ( v instanceof WebAssembly . Global ) ? v . value : v ) ;
229249}
230250
231- function exports ( name , instance ) {
251+ function exports ( instance ) {
232252 _assert ( instance instanceof Result ) ;
233253
234254 if ( instance . isError ( ) )
235255 return instance ;
236256
237- return ValueResult ( { [ name ] : instance . value . exports } ) ;
257+ return ValueResult ( { module : instance . value . exports , spectest : registry . spectest } ) ;
238258}
239259
240260function run ( action ) {
@@ -320,11 +340,26 @@ function assert_return(action, expected) {
320340
321341 uniqueTest ( ( ) => {
322342 assert_true ( ! result . isError ( ) , `expected success result, got: ${ result . value } .` ) ;
323- if ( ! result . isError ( ) ) {
324- assert_equals ( result . value , expected ) ;
325- } ;
343+ let actual = result . value ;
344+ switch ( expected ) {
345+ case "nan:canonical" :
346+ case "nan:arithmetic" :
347+ // Note that JS can't reliably distinguish different NaN values,
348+ // so there's no good way to test that it's a canonical NaN.
349+ assert_true ( Number . isNaN ( actual ) , `expected NaN, observed ${ actual } .` ) ;
350+ return ;
351+ case "ref.func" :
352+ assert_true ( typeof actual === "function" , `expected Wasm function, got ${ actual } ` ) ;
353+ return ;
354+ case "ref.any" :
355+ assert_true ( actual !== null , `expected Wasm reference, got ${ actual } ` ) ;
356+ return ;
357+ default :
358+ assert_equals ( actual , expected ) ;
359+ }
360+
326361 } , "A wast module that must return a particular value." ) ;
327- } ;
362+ }
328363
329364function assert_return_nan ( action ) {
330365 let result = action ( ) ;
0 commit comments