regress-7785.js 1.6 KB
Newer Older
1 2 3 4
// 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.

5
// The test needs --no-liftoff because we can't serialize and deserialize
6
// Liftoff code.
7
// Flags: --allow-natives-syntax --no-liftoff
8

9
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
10

11
(function testExternRefNull() {
12 13
  const builder = new WasmModuleBuilder();
  builder.addFunction('main', kSig_r_v)
14
      .addBody([kExprRefNull, kExternRefCode])
15 16 17 18 19 20 21 22 23 24 25
      .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());
})();

26
(function testExternRefIsNull() {
27 28
  const builder = new WasmModuleBuilder();
  builder.addFunction('main', kSig_i_r)
29
      .addBody([kExprLocalGet, 0, kExprRefIsNull])
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
      .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));
})();