ce8812aceb
We currently print reference type indices as unsigned LEB. This will not work properly for large indices (>=64), as they will be interpreted as negative indices when read back. They may also alias with builtin types. In this CL, we fix this by defining builtin types as negative numbers. We add positive byte constants that can be used in function bodies. We adapt wasm-module-builder and tests to the above changes. Bug: v8:7748 Change-Id: I4dfaa65d4cbf77a6731ca2283148bd842ea5c56b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3080569 Commit-Queue: Manos Koukoutos <manoskouk@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#76176}
46 lines
1.6 KiB
JavaScript
46 lines
1.6 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.
|
|
|
|
// The test needs --wasm-tier-up because we can't serialize and deserialize
|
|
// Liftoff code.
|
|
// Flags: --allow-natives-syntax --experimental-wasm-reftypes --wasm-tier-up
|
|
|
|
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
(function testExternRefNull() {
|
|
const builder = new WasmModuleBuilder();
|
|
builder.addFunction('main', kSig_r_v)
|
|
.addBody([kExprRefNull, kExternRefCode])
|
|
.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 testExternRefIsNull() {
|
|
const builder = new WasmModuleBuilder();
|
|
builder.addFunction('main', kSig_i_r)
|
|
.addBody([kExprLocalGet, 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));
|
|
})();
|