Skip to content

Commit 2ef92f4

Browse files
committed
update documentation based on feedback
1 parent 948de8c commit 2ef92f4

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,16 @@ Both hooks have the signature `(code) => replacementCode`, where:
134134

135135
If either hook is omitted, then the code will not be replaced, i.e. the default is equivalent to `(code) => code`.
136136

137-
Both hooks also some utility methods that are are accessible via `this`:
137+
Both hooks also have some utility methods that are accessible via `this`:
138138

139139
- `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 `importedIdentifier` the identifier to import. This method returns the local identifier from the imported path.
140140

141+
The following variables are available in the scope of the replacement code:
142+
143+
- `globalObject` (object) is the global object associated with the interface
144+
145+
- `interfaceName` (string) is the name of the interface
146+
141147
An example of code that uses these hooks is as follows:
142148

143149
```js
@@ -147,21 +153,24 @@ const WebIDL2JS = require("webidl2js");
147153
const transformer = new WebIDL2JS({
148154
implSuffix: "-impl",
149155
processCEReactions(code) {
156+
const ceReactionsPreSteps = this.addImport("../ce-reactions", "ceReactionsPreSteps");
157+
const ceReactionsPostSteps = this.addImport("../ce-reactions", "ceReactionsPostSteps");
158+
150159
return `
151-
// CEReactions pre steps
160+
${ceReactionsPreSteps}(globalObject);
152161
try {
153162
${code}
154163
} finally {
155-
// CEReactions post steps
164+
${ceReactionsPostSteps}(globalObject);
156165
}
157166
`;
158167
},
159168
processHTMLConstructor(code) {
160-
const identifier = this.addImport("../HTMLConstructor", "HTMLConstructor");
169+
const htmlConstructor = this.addImport("../HTMLConstructor", "HTMLConstructor");
161170

162171
return `
163-
// HTMLConstructor
164172
${code}
173+
${htmlConstructor}(globalObject, interfaceName);
165174
`;
166175
}
167176
});

0 commit comments

Comments
 (0)