Skip to content

Commit a0e05e8

Browse files
danbevaddaleax
authored andcommitted
tools: fix tools/addon-verify.js
The current implementation of addon-verify.js is including the code for the "Function arguments" section in test/addons/01_callbacks and there is no directory generated or the "Function arguments section". This continues and leads to the last section, "AtExit", code to be excluded. There is an test/addons/07_atexit_hooks but it contains code from the "Passing wrapped objects around" section. This commit modifies addon-verify to associate headers with code and then iterates over the set and generates the files as a separate step. PR-URL: #14048 Reviewed-By: Michaël Zasso <[email protected]>
1 parent 06ba2da commit a0e05e8

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

doc/api/addons.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ Test in JavaScript by running:
11251125
11261126
```js
11271127
// test.js
1128-
const addon = require('./build/Release/addon');
1128+
require('./build/Release/addon');
11291129
```
11301130

11311131
[Embedder's Guide]: https://github.com/v8/v8/wiki/Embedder's%20Guide

tools/doc/addon-verify.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@ const verifyDir = path.resolve(rootDir, 'test', 'addons');
1111
const contents = fs.readFileSync(doc).toString();
1212

1313
const tokens = marked.lexer(contents);
14-
let files = null;
1514
let id = 0;
1615

17-
// Just to make sure that all examples will be processed
18-
tokens.push({ type: 'heading' });
19-
20-
for (var i = 0; i < tokens.length; i++) {
21-
var token = tokens[i];
16+
let currentHeader;
17+
const addons = {};
18+
tokens.forEach((token) => {
2219
if (token.type === 'heading' && token.text) {
23-
const blockName = token.text;
24-
if (files && Object.keys(files).length !== 0) {
25-
verifyFiles(files,
26-
blockName,
27-
console.log.bind(null, 'wrote'),
28-
function(err) { if (err) throw err; });
29-
}
30-
files = {};
31-
} else if (token.type === 'code') {
20+
currentHeader = token.text;
21+
addons[currentHeader] = {
22+
files: {}
23+
};
24+
}
25+
if (token.type === 'code') {
3226
var match = token.text.match(/^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/);
33-
if (match === null)
34-
continue;
35-
files[match[1]] = token.text;
27+
if (match !== null) {
28+
addons[currentHeader].files[match[1]] = token.text;
29+
}
3630
}
31+
});
32+
for (var header in addons) {
33+
verifyFiles(addons[header].files,
34+
header,
35+
console.log.bind(null, 'wrote'),
36+
function(err) { if (err) throw err; });
3737
}
3838

3939
function once(fn) {

0 commit comments

Comments
 (0)