Commit c10d15b8 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Add test of function identity on re-export.

This adds a test checking whether function identity is preserved upon
re-export of various function kinds. The tests are expected to all pass
and just increase code coverage.

R=ahaas@chromium.org
TEST=mjsunit/wasm/export-identity

Change-Id: I4fbb7db2d78c7ffeb6278d6b6d87a7c029326387
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1687893Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62516}
parent 02f18b2d
// Copyright 2019 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.
load("test/mjsunit/wasm/wasm-module-builder.js");
function createExport(fun) {
let builder = new WasmModuleBuilder();
let fun_index = builder.addImport("m", "fun", kSig_i_v)
builder.addExport("fun", fun_index);
let instance = builder.instantiate({ m: { fun: fun }});
return instance.exports.fun;
}
// Test that re-exporting a generic JavaScript function changes identity, as
// the resulting export is an instance of {WebAssembly.Function} instead.
(function TestReExportOfJS() {
print(arguments.callee.name);
function fun() { return 7 }
let exported = createExport(fun);
assertNotSame(exported, fun);
assertEquals(7, exported());
assertEquals(7, fun());
})();
// Test that re-exporting and existing {WebAssembly.Function} that represents
// regular WebAssembly functions preserves identity.
(function TestReReExportOfWasm() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction('fun', kSig_i_v).addBody([kExprI32Const, 9]).exportFunc();
let fun = builder.instantiate().exports.fun;
let exported = createExport(fun);
assertSame(exported, fun);
assertEquals(9, fun());
})();
// Test that re-exporting and existing {WebAssembly.Function} that represents
// generic JavaScript functions preserves identity.
(function TestReReExportOfJS() {
print(arguments.callee.name);
let fun = createExport(() => 11)
let exported = createExport(fun);
assertSame(exported, fun);
assertEquals(11, fun());
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment