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
The above is a simplification of the actual generated code, but should give you some idea of what's going on. We bring your attention to a few points:
@@ -128,15 +128,15 @@ By default webidl2js ignores HTML Standard-defined extended attributes [`[CEReac
128
128
129
129
Both hooks have the signature `(code) => replacementCode`, where:
130
130
131
-
-`code` is the code generated by webidl2js normally, for calling into the impl class.
131
+
-`code`(string) is the code generated by webidl2js normally, for calling into the impl class.
132
132
133
-
-`replacementCode` is the new code that will be output in place of `code` in the wrapper class.
133
+
-`replacementCode`(string) is the new code that will be output in place of `code` in the wrapper class.
134
134
135
135
If either hook is omitted, then the code will not be replaced, i.e. the default is equivalent to `(code) => code`.
136
136
137
-
Both hooks also have some utility methods that are accessible via `this`:
137
+
Both hooks also have a utility method that is accessible via `this`:
138
138
139
-
-`addImport(relPath, [importedIdentifier])` utility to require external modules from the generated interface. This method accepts 2 parameters: `relPath` the relative path from the generated interface file, and an optional `importedIdentifier` the identifier to import. This method returns the local identifier from the imported path.
139
+
-`addImport(path, [importedIdentifier])` utility to require external modules from the generated interface. This method accepts 2 parameters: `path` the relative or absolute path from the generated interface file, and an optional `importedIdentifier` the identifier to import. This method returns the local identifier from the imported path.
140
140
141
141
The following variables are available in the scope of the replacement code:
Many HTML IDL attributes are defined using [reflecting a content attribute to an IDL attribute](https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflect). By default webidl2js doesn't do much with reflection, since it requires detailed knowledge of the host environment to implement correctly. However, we offer the `processReflect` processor hook to allow the host environment to automate the task of implementing reflected IDL attributes.
188
+
189
+
The `processReflect` processor hook has the signature `(idl, implName) => ({ get, set })`, where:
190
+
191
+
-`idl` is the [`attribute` AST node](https://github.com/w3c/webidl2.js/#attribute-member) as emitted by the [webidl2](https://github.com/w3c/webidl2.js) parser.
192
+
193
+
-`implName` (string) is a JavaScript expression that would evaluate to the implementation object at runtime.
194
+
195
+
-`get` (string) is the code that will be output in the attribute getter, after any function prologue.
196
+
197
+
-`set` (string) is the code that will be output in the attribute setter, after any function prologue.
198
+
199
+
The hook also has a utility method that is accessible via `this`:
200
+
201
+
-`addImport(path, [importedIdentifier])` utility to require external modules from the generated interface. This method accepts 2 parameters: `path` the relative or absolute path from the generated interface file, and an optional `importedIdentifier` the identifier to import. This method returns the local identifier from the imported path.
202
+
203
+
The following variables are available in the scope of the replacement code:
204
+
205
+
-`globalObject` (object) is the global object associated with the interface
206
+
207
+
-`interfaceName` (string) is the name of the interface
208
+
209
+
- (for setter only) `V` (any) is the converted input to the setter method.
210
+
211
+
To mark an attribute as reflected, an extended attribute whose name starts with `Reflect` should be added to the IDL attribute. This means that any of the following is treated as reflected by webidl2js:
webidl2js itself does not particularly care about the particular reflection-related extended attribute(s) being used, only that one exists. However, your processor hook can make use of the extended attributes for additional information on how the attribute is reflected.
220
+
221
+
An example processor function that implements `boolean` IDL attribute reflection is as follows:
222
+
223
+
```js
224
+
functionprocessReflect(idl, implName) {
225
+
// Assume the name of the reflected content attribute is the same as the IDL attribute, lowercased.
thrownewError(`Not-yet-implemented IDL type for reflection: ${idl.idlType.idlType}`);
241
+
}
242
+
```
243
+
185
244
## Generated wrapper class file API
186
245
187
246
The example above showed a simplified generated wrapper file with only three exports: `create`, `is`, and `interface`. In reality the generated wrapper file will contain more functionality, documented here. This functionality is different between generated wrapper files for interfaces and for dictionaries.
@@ -414,17 +473,7 @@ Notable missing features include:
414
473
415
474
## Nonstandard extended attributes
416
475
417
-
A couple of non-standard extended attributes are baked in to webidl2js.
418
-
419
-
### `[Reflect]`
420
-
421
-
The `[Reflect]` extended attribute is used on IDL attributes to implement the rules for [reflecting a content attribute to an IDL attribute](https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflect). If `[Reflect]` is specified, the implementation class does not need to implement any getter or setter logic; webidl2js will take care of it.
422
-
423
-
By default the attribute passed to `this.getAttribute` and `this.setAttribute` will be the same as the name of the property being reflected. You can use the form `[Reflect=custom]` or `[Reflect=custom_with_dashes]` to change that to be `"custom"` or `"custom-with-dashes"`, respectively.
424
-
425
-
Note that only the basics of the reflect algorithm are implemented so far: `boolean`, `DOMString`, `long`, and `unsigned long`, with no parametrizations.
426
-
427
-
In the future we may change this extended attribute to be handled by the caller, similar to `[CEReactions]` and `[HTMLConstructor]`, since it is more related to HTML than to Web IDL.
476
+
One non-standard extended attribute is baked in to webidl2js:
0 commit comments