You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-3Lines changed: 21 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -282,11 +282,11 @@ Creates a new instance of the wrapper class and corresponding implementation cla
282
282
283
283
This is useful inside implementation class files, where it is easiest to only deal with impls, not wrappers.
284
284
285
-
#### `new(globalObject)`
285
+
#### `new(globalObject, newTarget)`
286
286
287
287
Creates a new instance of the wrapper class and corresponding implementation class, but without invoking the implementation class constructor logic. Then returns the implementation class.
288
288
289
-
This corresponds to the [Web IDL "new" algorithm](https://heycam.github.io/webidl/#new), and is useful when implementing specifications that initialize objects in different ways than their constructors do.
289
+
This corresponds to the [WebIDL "create a new object implementing the interface"](https://heycam.github.io/webidl/#new) and ["internally create a new object implementing the interface"](https://heycam.github.io/webidl/#internally-create-a-new-object-implementing-the-interface) algorithms, and is useful when implementing specifications that initialize objects in different ways than their constructors do.
@@ -407,6 +407,24 @@ It is often useful for implementation classes to inherit from each other, if the
407
407
408
408
However, it is not required! The wrapper classes will have a correct inheritance chain, regardless of the implementation class inheritance chain. Just make sure that, either via inheritance or manual implementation, you implement all of the expected operations and attributes.
409
409
410
+
### The `[LegacyFactoryFunction]` extended attribute
411
+
412
+
For interfaces which have the `[LegacyFactoryFunction]` extended attribute, the implementation class file must contain the `legacyFactoryFunction` export, with the signature `(globalObject, legacyFactoryFunctionArgs, legacyFactoryFunctionName)`, which is used for:
413
+
414
+
- Setting up initial state that will always be used, such as caches or default values
415
+
- Keep a reference to the relevant `globalObject` for later consumption.
416
+
- Processing constructor arguments `legacyFactoryFunctionArgs` passed to the legacy factory function constructor, if the legacy factory function takes arguments.
417
+
- Switching on the `legacyFactoryFunctionName`, if the interface defines multiple legacy factory functions, eg.:
The `legacyFactoryFunction` export is called with a `this` value of a new uninitialized implementation instance, which may be ignored by returning a different object, similarly to how constructors with overridden return types are implemented.
427
+
410
428
### The init export
411
429
412
430
In addition to the `implementation` export, for interfaces, your implementation class file can contain an `init` export. This would be a function taking as an argument an instance of the implementation class, and is called when any wrapper/implementation pairs are constructed (such as by the exports of the [generated wrapper module](https://github.com/jsdom/webidl2js#for-interfaces)). In particular, it is called even if they are constructed by [`new()`](newglobalobject), which does not invoke the implementation class constructor.
@@ -469,6 +487,7 @@ webidl2js is implementing an ever-growing subset of the Web IDL specification. S
469
487
-`[Clamp]`
470
488
-`[EnforceRange]`
471
489
-`[Exposed]`
490
+
-`[LegacyFactoryFunction]`
472
491
-`[LegacyLenientThis]`
473
492
-`[LegacyLenientSetter]`
474
493
-`[LegacyNoInterfaceObject]`
@@ -494,7 +513,6 @@ Notable missing features include:
494
513
-`[AllowShared]`
495
514
-`[Default]` (for `toJSON()` operations)
496
515
-`[Global]`'s various consequences, including the named properties object and `[[SetPrototypeOf]]`
0 commit comments