ea82e09611
In order to limit the overall length of error message, limit the output of string provided by the user. This is implemented by a helper class which takes the maximum length as template argument and has simple accessors for the start address and the length of the truncated string. This is the compromise CL after https://chromium-review.googlesource.com/c/566815 and https://chromium-review.googlesource.com/c/594288. R=titzer@chromium.org Bug: chromium:740023, chromium:749041, v8:6634 Change-Id: I7c154eb18b3a6befd5ecabbd2f435b015ad71542 Reviewed-on: https://chromium-review.googlesource.com/600547 Reviewed-by: Ben Titzer <titzer@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#47157}
76 lines
2.6 KiB
JavaScript
76 lines
2.6 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);
|
|
})();
|
|
|
|
(function duplicateGlobalExportName() {
|
|
var builder = new WasmModuleBuilder();
|
|
builder.addGlobal(kWasmI64, false).exportAs('g');
|
|
builder.addGlobal(kWasmI64, false).exportAs('g');
|
|
assertThrows(
|
|
() => builder.instantiate(), WebAssembly.CompileError,
|
|
/Duplicate export name 'g' for global 0 and global 1/);
|
|
})();
|
|
|
|
(function exportNameClashWithFunction() {
|
|
var builder = new WasmModuleBuilder();
|
|
builder.addGlobal(kWasmI64, false).exportAs('foo');
|
|
builder.addFunction('f', kSig_v_v).addBody([]).exportAs('foo');
|
|
assertThrows(
|
|
() => builder.instantiate(), WebAssembly.CompileError,
|
|
/Duplicate export name 'foo' for global 0 and function 0/);
|
|
})();
|
|
|
|
(function veryLongExportName() {
|
|
// Regression test for crbug.com/740023.
|
|
var export_name = 'abc';
|
|
while (export_name.length < 8192) {
|
|
export_name = export_name.concat(export_name);
|
|
}
|
|
var builder = new WasmModuleBuilder();
|
|
var global = builder.addGlobal(kWasmI64, false);
|
|
global.exportAs(export_name);
|
|
global.exportAs(export_name);
|
|
var error_msg =
|
|
'Duplicate export name \'(abc){10,20}ab?c?\.\.\.\' for global 0 and global 0';
|
|
assertThrows(
|
|
() => builder.instantiate(), WebAssembly.CompileError,
|
|
new RegExp(error_msg));
|
|
})();
|