Skip to content
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

Improve “Illegal invocation” error messages #222

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/constructs/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Attribute {

let brandCheck = `
if (!exports.is(esValue)) {
throw new TypeError("Illegal invocation");
throw new TypeError("'$KEYWORD$ ${this.idl.name}' called on an object that does not implement interface ${this.interface.name}.");
}
`;
let getterBody = `return utils.tryWrapperForImpl(esValue[implSymbol]["${this.idl.name}"]);`;
Expand Down Expand Up @@ -78,11 +78,13 @@ class Attribute {
addMethod(this.idl.name, [], `
${promiseHandlingBefore}
const esValue = this !== null && this !== undefined ? this : globalObject;
${brandCheck}
${brandCheck.replace("$KEYWORD$", "get")}
${getterBody}
${promiseHandlingAfter}
`, "get", { configurable });

brandCheck = brandCheck.replace("$KEYWORD$", "set");

if (!this.idl.readonly) {
if (async) {
throw new Error(`Illegal promise-typed attribute "${this.idl.name}" in interface "${this.interface.idl.name}"`);
Expand Down Expand Up @@ -159,7 +161,7 @@ class Attribute {
addMethod("toString", [], `
const esValue = this;
if (!exports.is(esValue)) {
throw new TypeError("Illegal invocation");
throw new TypeError("'toString' called on an object that does not implement interface ${this.interface.name}.");
}

${getterBody}
Expand Down
8 changes: 4 additions & 4 deletions lib/constructs/iterable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Iterable {

generateFunction(key, kind) {
this.interface.addMethod(this.interface.defaultWhence, key, [], `
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
if (!exports.is(this)) {
throw new TypeError("'${key}' called on an object that does not implement interface ${this.interface.name}.");
}
return exports.createDefaultIterator(this, "${kind}");
`);
Expand All @@ -35,8 +35,8 @@ class Iterable {
this.generateFunction("entries", "key+value");
this.interface.addProperty(whence, Symbol.iterator, `${this.interface.name}.prototype.entries`);
this.interface.addMethod(whence, "forEach", ["callback"], `
if (!this || !exports.is(this)) {
throw new TypeError("Illegal invocation");
if (!exports.is(this)) {
throw new TypeError("'forEach' called on an object that does not implement interface ${this.interface.name}.");
}
if (arguments.length < 1) {
throw new TypeError("Failed to execute 'forEach' on '${this.name}': 1 argument required, " +
Expand Down
2 changes: 1 addition & 1 deletion lib/constructs/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Operation {
str += `
const esValue = this !== null && this !== undefined ? this : globalObject;
if (!exports.is(esValue)) {
throw new TypeError("Illegal invocation");
throw new TypeError("'${this.name}' called on an object that does not implement interface ${this.interface.name}.");
}
`;
}
Expand Down
Loading