@@ -66,6 +66,22 @@ const EXPECT_INVALID = false;
66
66
67
67
/* DATA **********************************************************************/
68
68
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
+
69
85
let $$ ;
70
86
71
87
// Default imports.
@@ -77,6 +93,10 @@ function reinitializeRegistry() {
77
93
return ;
78
94
79
95
let spectest = {
96
+ hostref : hostref ,
97
+ is_hostref : is_hostref ,
98
+ is_funcref : is_funcref ,
99
+ eq_ref : eq_ref ,
80
100
print : console . log . bind ( console ) ,
81
101
print_i32 : console . log . bind ( console ) ,
82
102
print_i32_f32 : console . log . bind ( console ) ,
@@ -228,13 +248,13 @@ function get(instance, name) {
228
248
return ValueResult ( ( v instanceof WebAssembly . Global ) ? v . value : v ) ;
229
249
}
230
250
231
- function exports ( name , instance ) {
251
+ function exports ( instance ) {
232
252
_assert ( instance instanceof Result ) ;
233
253
234
254
if ( instance . isError ( ) )
235
255
return instance ;
236
256
237
- return ValueResult ( { [ name ] : instance . value . exports } ) ;
257
+ return ValueResult ( { module : instance . value . exports , spectest : registry . spectest } ) ;
238
258
}
239
259
240
260
function run ( action ) {
@@ -320,11 +340,26 @@ function assert_return(action, expected) {
320
340
321
341
uniqueTest ( ( ) => {
322
342
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
+
326
361
} , "A wast module that must return a particular value." ) ;
327
- } ;
362
+ }
328
363
329
364
function assert_return_nan ( action ) {
330
365
let result = action ( ) ;
0 commit comments