41e8af2c7c
On an error during {ProcessExports()}, we would just continue execution, resulting in a DCHECK failure later. I did not find any tests for exported globals, so I added a few (including a regression test for the referenced bug). R=ahaas@chromium.org BUG=chromium:734295 Change-Id: I35370de934c274f870680c662ef848c72268a7bc Reviewed-on: https://chromium-review.googlesource.com/539401 Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Andreas Haas <ahaas@chromium.org> Cr-Commit-Position: refs/heads/master@{#46064}
41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
// Copyright 2017 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-constants.js");
|
|
load("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
(function exportImmutableGlobal() {
|
|
var builder = new WasmModuleBuilder();
|
|
let globals = [
|
|
[kWasmI32, 'i32_noinit'], // -
|
|
[kWasmI32, 'i32', 4711], // -
|
|
[kWasmF32, 'f32_noinit'], // -
|
|
[kWasmF32, 'f32', Math.fround(3.14)], // -
|
|
[kWasmF64, 'f64_noinit'], // -
|
|
[kWasmF64, 'f64', 1 / 7] // -
|
|
];
|
|
for (let g of globals) {
|
|
let global_builder = builder.addGlobal(g[0], false).exportAs(g[1]);
|
|
if (g[2]) global_builder.init = g[2];
|
|
}
|
|
var module = builder.instantiate();
|
|
|
|
for (let g of globals) {
|
|
assertEquals("number", typeof module.exports[g[1]], g[1]);
|
|
assertEquals(g[2] || 0, module.exports[g[1]], g[1]);
|
|
}
|
|
})();
|
|
|
|
(function cannotExportMutableGlobal() {
|
|
var builder = new WasmModuleBuilder();
|
|
builder.addGlobal(kWasmI32, true).exportAs('g');
|
|
assertThrows(() => builder.instantiate(), WebAssembly.CompileError);
|
|
})();
|
|
|
|
(function cannotExportI64Global() {
|
|
var builder = new WasmModuleBuilder();
|
|
builder.addGlobal(kWasmI64, false).exportAs('g');
|
|
assertThrows(() => builder.instantiate(), WebAssembly.LinkError);
|
|
})();
|