Files
react-native-devtools-frontend/scripts/javascript_natives/index.js
T
Johan Bay 8d8c684c22 Update roll_deps.py to also run javascript_natives/ script
With this change, we also update the argument hints for javascript
functions defined in .idl files when we roll Chromium deps.

DISABLE_THIRD_PARTY_CHECK=changes to roll_deps.py and javascript_natives/
are related

Change-Id: I0544acbe82a0292e486cfb3fac47b683438c3759
Bug: 1255619
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3431347
Reviewed-by: Mathias Bynens <mathias@chromium.org>
Commit-Queue: Johan Bay <jobay@chromium.org>
2022-02-02 18:18:51 +00:00

98 lines
3.0 KiB
JavaScript

// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as fs from 'fs';
import glob from 'glob';
import * as path from 'path';
import ts from 'typescript';
import * as WebIDL2 from 'webidl2';
import {parseTSFunction, postProcess, walkRoot} from './helpers.js';
if (process.argv.length !== 4) {
throw new Error('Please provide path to chromium/src and devtools-frontend');
}
const chromiumSource = process.argv[2];
const typescriptSource = process.argv[3] + 'node_modules/typescript/lib/lib.esnext.d.ts';
const program = ts.createProgram([typescriptSource], {noLib: false, types: []});
for (const file of program.getSourceFiles()) {
ts.forEachChild(file, node => {
if (node.kind === ts.SyntaxKind.InterfaceDeclaration) {
for (const member of node.members) {
if (member.kind === ts.SyntaxKind.MethodSignature) {
parseTSFunction(member, node);
}
}
}
if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
parseTSFunction(node, {name: {text: 'Window'}});
}
});
}
// Assume the DevTools front-end repository is at
// `devtools/devtools-frontend`, where `devtools` is on the same level
// as `chromium`. This matches `scripts/npm_test.js`.
const files =
glob.sync(`${chromiumSource}/third_party/blink/renderer/+(core|modules)/**/*.idl`, {cwd: process.env.PWD});
for (const file of files) {
if (file.includes('testing')) {
continue;
}
const data = fs.readFileSync(path.join(process.env.PWD, file), 'utf8');
const lines = data.split('\n');
const newLines = [];
for (const line of lines) {
if (!line.includes(' attribute ')) {
newLines.push(line);
}
}
try {
WebIDL2.parse(newLines.join('\n')).forEach(walkRoot);
} catch (e) {
// console.error(file);
}
// Source for Console spec: https://console.spec.whatwg.org/#idl-index
WebIDL2
.parse(`
[Exposed=(Window,Worker,Worklet)]
namespace console { // but see namespace object requirements below
// Logging
undefined assert(optional boolean condition = false, any... data);
undefined clear();
undefined debug(any... data);
undefined error(any... data);
undefined info(any... data);
undefined log(any... data);
undefined table(optional any tabularData, optional sequence<DOMString> properties);
undefined trace(any... data);
undefined warn(any... data);
undefined dir(optional any item, optional object? options);
undefined dirxml(any... data);
// Counting
undefined count(optional DOMString label = "default");
undefined countReset(optional DOMString label = "default");
// Grouping
undefined group(any... data);
undefined groupCollapsed(any... data);
undefined groupEnd();
// Timing
undefined time(optional DOMString label = "default");
undefined timeLog(optional DOMString label = "default", any... data);
undefined timeEnd(optional DOMString label = "default");
};
`).forEach(walkRoot);
}
postProcess();