mirror of
				https://github.com/tc39/test262.git
				synced 2025-11-03 21:24:30 +01:00 
			
		
		
		
	sourceRevisionAtLastExport: 33f2fb0e53d135f0ee17cfccd9d993eb2a6f47de targetRevisionAtLastExport: 31340cbd9add103f586d501b0c3354b7b182abc0
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
// Copyright 2018 the V8 project authors. All rights reserved.
 | 
						|
// Use of this source code is governed by a BSD-style license that can be
 | 
						|
// found in the LICENSE file.
 | 
						|
 | 
						|
// Flags: --allow-natives-syntax --experimental-wasm-anyref
 | 
						|
 | 
						|
load("test/mjsunit/wasm/wasm-constants.js");
 | 
						|
load("test/mjsunit/wasm/wasm-module-builder.js");
 | 
						|
 | 
						|
(function testAnyRefNull() {
 | 
						|
  const builder = new WasmModuleBuilder();
 | 
						|
  builder.addFunction('main', kSig_r_v)
 | 
						|
      .addBody([kExprRefNull])
 | 
						|
      .exportFunc();
 | 
						|
 | 
						|
  var wire_bytes = builder.toBuffer();
 | 
						|
  var module = new WebAssembly.Module(wire_bytes);
 | 
						|
  var buffer = %SerializeWasmModule(module);
 | 
						|
  module = %DeserializeWasmModule(buffer, wire_bytes);
 | 
						|
  var instance = new WebAssembly.Instance(module);
 | 
						|
 | 
						|
  assertEquals(null, instance.exports.main());
 | 
						|
})();
 | 
						|
 | 
						|
(function testAnyRefIsNull() {
 | 
						|
  const builder = new WasmModuleBuilder();
 | 
						|
  builder.addFunction('main', kSig_i_r)
 | 
						|
      .addBody([kExprGetLocal, 0, kExprRefIsNull])
 | 
						|
      .exportFunc();
 | 
						|
 | 
						|
  var wire_bytes = builder.toBuffer();
 | 
						|
  var module = new WebAssembly.Module(wire_bytes);
 | 
						|
  var buffer = %SerializeWasmModule(module);
 | 
						|
  module = %DeserializeWasmModule(buffer, wire_bytes);
 | 
						|
  var instance = new WebAssembly.Instance(module);
 | 
						|
 | 
						|
  assertEquals(0, instance.exports.main({'hello' : 'world'}));
 | 
						|
  assertEquals(0, instance.exports.main(1234));
 | 
						|
  assertEquals(0, instance.exports.main(0));
 | 
						|
  assertEquals(0, instance.exports.main(123.4));
 | 
						|
  assertEquals(0, instance.exports.main(undefined));
 | 
						|
  assertEquals(1, instance.exports.main(null));
 | 
						|
  assertEquals(0, instance.exports.main(print));
 | 
						|
})();
 |