Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 29 additions & 0 deletions lib/productions/callback-interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Container } from "./container.js";
import { Operation } from "./operation.js";
import { Constant } from "./constant.js";


export class CallbackInterface extends Container {
/**
* @param {import("../tokeniser").Tokeniser} tokeniser
*/
static parse(tokeniser, callback, { partial = null } = {}) {
const tokens = { callback };
tokens.base = tokeniser.consume("interface");
if (!tokens.base) {
return;
}
return Container.parse(tokeniser, new CallbackInterface({ source: tokeniser.source, tokens }), {
type: "callback interface",
inheritable: !partial,
allowedMembers: [
[Constant.parse],
[Operation.parse, { regular: true }]
]
});
}

get type() {
return "callback interface";
}
}
7 changes: 2 additions & 5 deletions lib/productions/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export class Interface extends Container {
/**
* @param {import("../tokeniser").Tokeniser} tokeniser
*/
static parse(tokeniser, base, { callback = null, partial = null } = {}) {
const tokens = { callback, partial, base };
static parse(tokeniser, base, { partial = null } = {}) {
const tokens = { partial, base };
return Container.parse(tokeniser, new Interface({ source: tokeniser.source, tokens }), {
type: "interface",
inheritable: !partial,
Expand All @@ -38,9 +38,6 @@ export class Interface extends Container {
}

get type() {
if (this.tokens.callback) {
return "callback interface";
}
return "interface";
}
}
6 changes: 3 additions & 3 deletions lib/webidl2.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Interface } from "./productions/interface.js";
import { Mixin } from "./productions/mixin.js";
import { Dictionary } from "./productions/dictionary.js";
import { Namespace } from "./productions/namespace.js";
import { CallbackInterface } from "./productions/callback-interface.js";

/**
* @param {Tokeniser} tokeniser
Expand All @@ -30,9 +31,8 @@ function parseByTokens(tokeniser, options) {
function callback() {
const callback = consume("callback");
if (!callback) return;
const tok = consume("interface");
if (tok) {
return Interface.parse(tokeniser, tok, { callback });
if (tokeniser.probe("interface")) {
return CallbackInterface.parse(tokeniser, callback);
}
return CallbackFunction.parse(tokeniser, callback);
}
Expand Down
3 changes: 3 additions & 0 deletions test/invalid/baseline/callback-attribute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Syntax error at line 2, since `callback interface Attribute`:
attribute boolean attr;
^ Missing return type
2 changes: 1 addition & 1 deletion test/invalid/baseline/no-semicolon-callback.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Syntax error at line 5, since `callback interface NoSemicolon`:
enum YouNeedOne {
^ Missing semicolon after interface
^ Missing semicolon after callback interface
3 changes: 3 additions & 0 deletions test/invalid/idl/callback-attribute.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
callback interface Attribute {
attribute boolean attr;
};
2 changes: 1 addition & 1 deletion test/invalid/idl/no-semicolon-callback.widl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
callback interface NoSemicolon {
attribute boolean noSemiColon;
void noSemiColon();
}

enum YouNeedOne {
Expand Down