-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[js-api] Add spec tests for proposed API additions #155
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// META: global=window,dedicatedworker,jsshell | ||
// META: script=/wasm/jsapi/assertions.js | ||
|
||
test(() => { | ||
assert_function_name( | ||
WebAssembly.Exception, | ||
"Exception", | ||
"WebAssembly.Exception" | ||
); | ||
}, "name"); | ||
|
||
test(() => { | ||
assert_function_length(WebAssembly.Exception, 1, "WebAssembly.Exception"); | ||
}, "length"); | ||
|
||
test(() => { | ||
assert_throws_js(TypeError, () => new WebAssembly.Exception()); | ||
}, "No arguments"); | ||
|
||
test(() => { | ||
const argument = new WebAssembly.Tag({ parameters: [] }); | ||
assert_throws_js(TypeError, () => WebAssembly.Exception(argument)); | ||
}, "Calling"); | ||
|
||
test(() => { | ||
const invalidArguments = [ | ||
undefined, | ||
null, | ||
false, | ||
true, | ||
"", | ||
"test", | ||
Symbol(), | ||
1, | ||
NaN, | ||
{}, | ||
]; | ||
for (const invalidArgument of invalidArguments) { | ||
assert_throws_js( | ||
TypeError, | ||
() => new WebAssembly.Exception(invalidArgument), | ||
`new Exception(${format_value(invalidArgument)})` | ||
); | ||
} | ||
}, "Invalid descriptor argument"); | ||
|
||
test(() => { | ||
const typesAndArgs = [ | ||
["i32", 123n], | ||
["i32", Symbol()], | ||
["f32", 123n], | ||
["f64", 123n], | ||
["i64", undefined], | ||
]; | ||
for (const typeAndArg of typesAndArgs) { | ||
const exn = new WebAssembly.Tag({ parameters: [typeAndArg[0]] }); | ||
assert_throws_js( | ||
TypeError, | ||
() => new WebAssembly.Exception(exn, typeAndArg[1]) | ||
); | ||
} | ||
}, "Invalid exception argument"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// META: global=window,dedicatedworker,jsshell | ||
// META: script=/wasm/jsapi/memory/assertions.js | ||
|
||
test(() => { | ||
const tag = new WebAssembly.Tag({ parameters: [] }); | ||
const exn = new WebAssembly.Exception(tag, []); | ||
assert_throws_js(TypeError, () => exn.getArg()); | ||
assert_throws_js(TypeError, () => exn.getArg(tag)); | ||
}, "Missing arguments"); | ||
|
||
test(() => { | ||
const invalidValues = [undefined, null, true, "", Symbol(), 1, {}]; | ||
const tag = new WebAssembly.Tag({ parameters: [] }); | ||
const exn = new WebAssembly.Exception(tag, []); | ||
for (argument of invalidValues) { | ||
assert_throws_js(TypeError, () => exn.getArg(argument, 0)); | ||
} | ||
}, "Invalid exception argument"); | ||
|
||
test(() => { | ||
const tag = new WebAssembly.Tag({ parameters: [] }); | ||
const exn = new WebAssembly.Exception(tag, []); | ||
assert_throws_js(RangeError, () => exn.getArg(tag, 1)); | ||
}, "Index out of bounds"); | ||
|
||
test(() => { | ||
const outOfRangeValues = [ | ||
undefined, | ||
NaN, | ||
Infinity, | ||
-Infinity, | ||
-1, | ||
0x100000000, | ||
0x1000000000, | ||
"0x100000000", | ||
{ | ||
valueOf() { | ||
return 0x100000000; | ||
}, | ||
}, | ||
]; | ||
|
||
const tag = new WebAssembly.Tag({ parameters: [] }); | ||
const exn = new WebAssembly.Exception(tag, []); | ||
for (const value of outOfRangeValues) { | ||
assert_throws_js(TypeError, () => exn.getArg(tag, value)); | ||
} | ||
}, "Getting out-of-range argument"); | ||
|
||
test(() => { | ||
const tag = new WebAssembly.Tag({ parameters: ["i32"] }); | ||
const exn = new WebAssembly.Exception(tag, [42]); | ||
assert_equals(exn.getArg(tag, 0), 42); | ||
}, "getArg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// META: global=window,dedicatedworker,jsshell | ||
// META: script=/wasm/jsapi/memory/assertions.js | ||
|
||
test(() => { | ||
const tag = new WebAssembly.Tag({ parameters: [] }); | ||
const exn = new WebAssembly.Exception(tag, []); | ||
assert_throws_js(TypeError, () => exn.is()); | ||
}, "Missing arguments"); | ||
|
||
test(() => { | ||
const invalidValues = [undefined, null, true, "", Symbol(), 1, {}]; | ||
const tag = new WebAssembly.Tag({ parameters: [] }); | ||
const exn = new WebAssembly.Exception(tag, []); | ||
for (argument of invalidValues) { | ||
assert_throws_js(TypeError, () => exn.is(argument)); | ||
} | ||
}, "Invalid exception argument"); | ||
|
||
test(() => { | ||
const tag1 = new WebAssembly.Tag({ parameters: ["i32"] }); | ||
const tag2 = new WebAssembly.Tag({ parameters: ["i32"] }); | ||
const exn = new WebAssembly.Exception(tag1, [42]); | ||
assert_true(exn.is(tag1)); | ||
assert_false(exn.is(tag2)); | ||
}, "is"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// META: global=window,dedicatedworker,jsshell | ||
|
||
test(() => { | ||
const argument = { parameters: [] }; | ||
const tag = new WebAssembly.Tag(argument); | ||
const exception = new WebAssembly.Exception(tag, []); | ||
assert_class_string(exception, "WebAssembly.Exception"); | ||
}, "Object.prototype.toString on an Exception"); | ||
|
||
test(() => { | ||
assert_own_property(WebAssembly.Exception.prototype, Symbol.toStringTag); | ||
|
||
const propDesc = Object.getOwnPropertyDescriptor( | ||
WebAssembly.Exception.prototype, | ||
Symbol.toStringTag | ||
); | ||
assert_equals(propDesc.value, "WebAssembly.Exception", "value"); | ||
assert_equals(propDesc.configurable, true, "configurable"); | ||
assert_equals(propDesc.enumerable, false, "enumerable"); | ||
assert_equals(propDesc.writable, false, "writable"); | ||
}, "@@toStringTag exists on the prototype with the appropriate descriptor"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// META: global=window,dedicatedworker,jsshell | ||
// META: script=/wasm/jsapi/assertions.js | ||
|
||
function assert_type(argument) { | ||
const exception = new WebAssembly.Exception(argument); | ||
const exceptiontype = exception.type(); | ||
|
||
assert_array_equals(exceptiontype.parameters, argument.parameters); | ||
} | ||
|
||
test(() => { | ||
assert_type({ "parameters": [] }); | ||
}, "[]"); | ||
|
||
test(() => { | ||
assert_type({ "parameters": ["i32", "i64"] }); | ||
}, "[i32 i64]"); | ||
|
||
test(() => { | ||
assert_type({ "parameters": ["i32", "i64", "f32", "f64"] }); | ||
}, "[i32 i64 f32 f64]"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// META: global=window,dedicatedworker,jsshell | ||
// META: script=/wasm/jsapi/assertions.js | ||
|
||
test(() => { | ||
assert_function_name(WebAssembly.Tag, "Tag", "WebAssembly.Tag"); | ||
}, "name"); | ||
|
||
test(() => { | ||
assert_function_length(WebAssembly.Tag, 1, "WebAssembly.Tag"); | ||
}, "length"); | ||
|
||
test(() => { | ||
assert_throws_js(TypeError, () => new WebAssembly.Tag()); | ||
}, "No arguments"); | ||
|
||
test(() => { | ||
const argument = { parameters: [] }; | ||
assert_throws_js(TypeError, () => WebAssembly.Tag(argument)); | ||
}, "Calling"); | ||
Comment on lines
+16
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this throw? Are we not allowed to have a tag with zero argument? I don't recall such a restriction though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
|
||
test(() => { | ||
const invalidArguments = [ | ||
undefined, | ||
null, | ||
false, | ||
true, | ||
"", | ||
"test", | ||
Symbol(), | ||
1, | ||
NaN, | ||
{}, | ||
]; | ||
for (const invalidArgument of invalidArguments) { | ||
assert_throws_js( | ||
TypeError, | ||
() => new WebAssembly.Tag(invalidArgument), | ||
`new Tag(${format_value(invalidArgument)})` | ||
); | ||
} | ||
}, "Invalid descriptor argument"); | ||
|
||
test(() => { | ||
const invalidTypes = ["i16", "i128", "f16", "f128", "u32", "u64", "i32\0"]; | ||
for (const value of invalidTypes) { | ||
const argument = { parameters: [value] }; | ||
assert_throws_js(TypeError, () => new WebAssembly.Tag(argument)); | ||
} | ||
}, "Invalid type parameter"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// META: global=window,dedicatedworker,jsshell | ||
|
||
test(() => { | ||
const argument = { parameters: [] }; | ||
const tag = new WebAssembly.Tag(argument); | ||
assert_class_string(tag, "WebAssembly.Tag"); | ||
}, "Object.prototype.toString on a Tag"); | ||
|
||
test(() => { | ||
assert_own_property(WebAssembly.Tag.prototype, Symbol.toStringTag); | ||
|
||
const propDesc = Object.getOwnPropertyDescriptor( | ||
WebAssembly.Tag.prototype, | ||
Symbol.toStringTag | ||
); | ||
assert_equals(propDesc.value, "WebAssembly.Tag", "value"); | ||
assert_equals(propDesc.configurable, true, "configurable"); | ||
assert_equals(propDesc.enumerable, false, "enumerable"); | ||
assert_equals(propDesc.writable, false, "writable"); | ||
}, "@@toStringTag exists on the prototype with the appropriate descriptor"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// META: global=window,dedicatedworker,jsshell | ||
// META: script=/wasm/jsapi/assertions.js | ||
|
||
function assert_type(argument) { | ||
const tag = new WebAssembly.Tag(argument); | ||
const tagtype = tag.type(); | ||
|
||
assert_array_equals(tagtype.parameters, argument.parameters); | ||
} | ||
|
||
test(() => { | ||
assert_type({ parameters: [] }); | ||
}, "[]"); | ||
|
||
test(() => { | ||
assert_type({ parameters: ["i32", "i64"] }); | ||
}, "[i32 i64]"); | ||
|
||
test(() => { | ||
assert_type({ parameters: ["i32", "i64", "f32", "f64"] }); | ||
}, "[i32 i64 f32 f64]"); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this throw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue here is the absence of the
new
keyword, which leads toNewTarget
being undefined, which causes an exception in step 1.2 of the "create an interface object" algorithm.