2018-05-25 07:52:27 +00:00
|
|
|
// 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.
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
// Flags: --allow-natives-syntax --experimental-wasm-reftypes
|
2018-05-25 07:52:27 +00:00
|
|
|
|
|
|
|
load("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
(function testExternRefNull() {
|
2018-05-25 07:52:27 +00:00
|
|
|
const builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction('main', kSig_r_v)
|
2020-06-09 15:54:14 +00:00
|
|
|
.addBody([kExprRefNull, kWasmExternRef])
|
2018-05-25 07:52:27 +00:00
|
|
|
.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());
|
|
|
|
})();
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
(function testExternRefIsNull() {
|
2018-05-25 07:52:27 +00:00
|
|
|
const builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction('main', kSig_i_r)
|
2020-06-23 13:41:10 +00:00
|
|
|
.addBody([kExprLocalGet, 0, kExprRefIsNull])
|
2018-05-25 07:52:27 +00:00
|
|
|
.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));
|
|
|
|
})();
|