Skip to content

Commit

Permalink
[jsapi] update limits.any.js (#975)
Browse files Browse the repository at this point in the history
Caches the generated Wasm buffer instead of re-generating
it for each test.

Refs WebAssembly/spec#972
  • Loading branch information
xtuc authored and Honry committed Oct 19, 2019
1 parent be6cbf3 commit 3c1436a
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions test/js-api/limits.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,38 @@ function testLimit(name, min, limit, gen) {
return builder.toBuffer();
}

const buffer_with_min = get_buffer(min);
const buffer_with_limit = get_buffer(limit);
const buffer_with_limit_plus_1 = get_buffer(limit + 1);

test(() => {
const buffer = get_buffer(min);
assert_true(WebAssembly.validate(buffer));
assert_true(WebAssembly.validate(buffer_with_min));
}, `Validate ${name} mininum`);
test(() => {
const buffer = get_buffer(limit);
assert_true(WebAssembly.validate(buffer));
assert_true(WebAssembly.validate(buffer_with_limit));
}, `Validate ${name} limit`);
test(() => {
const buffer = get_buffer(limit + 1);
assert_false(WebAssembly.validate(buffer));
assert_false(WebAssembly.validate(buffer_with_limit_plus_1));
}, `Validate ${name} over limit`);

test(() => {
const buffer = get_buffer(min);
new WebAssembly.Module(buffer);
new WebAssembly.Module(buffer_with_min);
}, `Compile ${name} mininum`);
test(() => {
const buffer = get_buffer(limit);
new WebAssembly.Module(buffer);
new WebAssembly.Module(buffer_with_limit);
}, `Compile ${name} limit`);
test(() => {
const buffer = get_buffer(limit + 1);
assert_throws(new WebAssembly.CompileError(), () => new WebAssembly.Module(buffer));
assert_throws(new WebAssembly.CompileError(), () => new WebAssembly.Module(buffer_with_limit_plus_1));
}, `Compile ${name} over limit`);

promise_test(t => {
const buffer = get_buffer(min);
return WebAssembly.compile(buffer);
return WebAssembly.compile(buffer_with_min);
}, `Async compile ${name} mininum`);
promise_test(t => {
const buffer = get_buffer(limit);
return WebAssembly.compile(buffer);
return WebAssembly.compile(buffer_with_limit);
}, `Async compile ${name} limit`);
promise_test(t => {
const buffer = get_buffer(limit + 1);
return promise_rejects(t, new WebAssembly.CompileError(), WebAssembly.compile(buffer));
return promise_rejects(t, new WebAssembly.CompileError(), WebAssembly.compile(buffer_with_limit_plus_1));
}, `Async compile ${name} over limit`);
}

Expand Down

0 comments on commit 3c1436a

Please sign in to comment.