Skip to content

Commit

Permalink
Temporarily make [Exposed] and globalNames non-required
Browse files Browse the repository at this point in the history
This reverts the breaking changes introduced in #191, since it was accidentally released as a minor version in v15.2.0, while keeping the functionality.
  • Loading branch information
domenic committed Apr 19, 2020
1 parent 8d82d5a commit 96cb578
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 74 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ This method creates a brand new wrapper constructor and prototype and attach it

The second argument `globalNames` is an array containing the [global names](https://heycam.github.io/webidl/#dfn-global-name) of the interface that `globalObject` implements. This is used for the purposes of deciding which interfaces are [exposed](https://heycam.github.io/webidl/#dfn-exposed). For example, this array should be `["Window"]` for a [`Window`](https://html.spec.whatwg.org/multipage/window-object.html#window) global object. But for a [`DedicatedWorkerGlobalScope`](https://html.spec.whatwg.org/multipage/workers.html#dedicatedworkerglobalscope) global object, this array should be `["Worker", "DedicatedWorker"]`. Note that we do not yet implement [`[SecureContext]`](https://heycam.github.io/webidl/#SecureContext), so the "exposed" check is not fully implemented.

Temporarily, until the next major release, `globalNames` defaults to `["Window"]`.

#### `create(globalObject, constructorArgs, privateData)`

Creates a new instance of the wrapper class and corresponding implementation class, passing in the `globalObject`, the `constructorArgs` array and `privateData` object to the implementation class constructor. Then returns the wrapper class.
Expand Down Expand Up @@ -304,10 +306,12 @@ The resulting function has an _objectReference_ property, which is the same obje

If any part of the conversion fails, _context_ can be used to describe the provided value in any resulting error message.

#### `install(globalObject)`
#### `install(globalObject, globalNames)`

If this callback interface has constants, then this method creates a brand new legacy callback interface object and attaches it to the passed `globalObject`. Otherwise, this method is a no-op.

The second argument `globalNames` is the same as for [the `install()` export for interfaces](#installglobalobject-globalnames). (However, it does not have a default.)

### For dictionaries

#### `convert(value, { context })`
Expand Down Expand Up @@ -462,7 +466,7 @@ webidl2js is implementing an ever-growing subset of the Web IDL specification. S
- Variadic arguments
- `[Clamp]`
- `[EnforceRange]`
- `[Exposed]`
- `[Exposed]` (temporarily defaulting to `[Exposed=Window]`)
- `[LegacyArrayClass]`
- `[LegacyUnenumerableNamedProperties]`
- `[LegacyWindowAlias]`
Expand Down
11 changes: 8 additions & 3 deletions lib/constructs/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,13 @@ class Interface {
this.exposed = new Set();
}

if (!exposed && !utils.getExtAttr(this.idl.extAttrs, "NoInterfaceObject")) {
throw new Error(`Interface ${this.name} has neither [Exposed] nor [NoInterfaceObject]`);
// TODO: put back in next major version.
// if (!exposed && !utils.getExtAttr(this.idl.extAttrs, "NoInterfaceObject")) {
// throw new Error(`Interface ${this.name} has neither [Exposed] nor [NoInterfaceObject]`);
// }
// For now:
if (!exposed) {
this.exposed = new Set(["Window"]);
}

const legacyWindowAlias = utils.getExtAttr(this.idl.extAttrs, "LegacyWindowAlias");
Expand Down Expand Up @@ -1486,7 +1491,7 @@ class Interface {
this.str += `
const exposed = new Set(${JSON.stringify([...this.exposed])});
exports.install = (globalObject, globalNames) => {
exports.install = (globalObject, globalNames = ["Window"]) => {
if (!globalNames.some(globalName => exposed.has(globalName))) {
return;
}
Expand Down
Loading

0 comments on commit 96cb578

Please sign in to comment.