chrome-devtools-frontend 1.0.1013237 → 1.0.1013875

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,85 @@
1
+ // Copyright 2020 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // eslint-disable-next-line rulesdir/es_modules_import
6
+ import idl from '@webref/idl';
7
+ import * as fs from 'fs';
8
+ import * as path from 'path';
9
+ import * as url from 'url';
10
+
11
+ import {SPECS} from './config.js';
12
+ import {addMetadata, getIDLProps, minimize} from './get-props.js';
13
+ import {getMissingTypes} from './util.js';
14
+
15
+ if (process.argv.length !== 3) {
16
+ throw new Error('Please provide the path to devtools-frontend');
17
+ }
18
+
19
+ const files = await idl.listAll();
20
+ const names = Object.keys(SPECS);
21
+ const specs = await Promise.all(names.map(name => files[name].parse().then(idls => ({name, idls}))));
22
+
23
+ const output = addMetadata(getIDLProps(specs));
24
+ const missing = getMissingTypes(output);
25
+
26
+ for (const type of missing) {
27
+ console.warn('Found missing type:', type);
28
+ }
29
+
30
+ const frontendPath = path.resolve(process.argv[2]);
31
+ const jsMetadataPath = path.join(frontendPath, 'front_end/models/javascript_metadata/');
32
+ const outPath = path.join(jsMetadataPath, 'DOMPinnedProperties.ts');
33
+ const thisPath = path.relative(frontendPath, url.fileURLToPath(import.meta.url));
34
+
35
+ fs.writeFileSync(outPath, `
36
+ // Copyright 2022 The Chromium Authors. All rights reserved.
37
+ // Use of this source code is governed by a BSD-style license that can be
38
+ // found in the LICENSE file.
39
+ // Generated from ${thisPath}
40
+
41
+ /**
42
+ * All the specs used when generating the DOM pinned properties dataset.
43
+ */
44
+ export const SPECS = ${JSON.stringify(SPECS)};
45
+
46
+ export interface DOMPinnedWebIDLProp {
47
+ // A flag specifying whether it's a "global" attribute.
48
+ global?: boolean;
49
+ // A bitfield of the specs in which the property is found.
50
+ // If missing, it implies the default spec: "html".
51
+ specs?: number;
52
+ }
53
+
54
+ export interface DOMPinnedWebIDLType {
55
+ // An inherited Type.
56
+ inheritance?: string;
57
+ // A set of Types to also include properties from.
58
+ includes?: Array<string>;
59
+ // The properties defined on this Type.
60
+ props?: {
61
+ // A property name such as "checked".
62
+ [PropName: string]: DOMPinnedWebIDLProp,
63
+ };
64
+ // The "states" in which only certain properties are "applicable".
65
+ states?: {
66
+ // A CSS selector such as "[type=checkbox]".
67
+ [State: string]: {
68
+ [PropName: string]: DOMPinnedWebIDLProp,
69
+ },
70
+ };
71
+ }
72
+
73
+ export interface DOMPinnedPropertiesDataset {
74
+ [TypeName: string]: DOMPinnedWebIDLType;
75
+ }
76
+
77
+ /**
78
+ * The DOM pinned properties dataset. Generated from WebIDL data parsed from
79
+ * the SPECS above.
80
+ *
81
+ * This is an object with WebIDL type names as keys and their WebIDL properties
82
+ * and inheritance/include chains as values.
83
+ */
84
+ export const DOMPinnedProperties: DOMPinnedPropertiesDataset = ${JSON.stringify(minimize(output))};
85
+ `);
@@ -0,0 +1,9 @@
1
+ {
2
+ "private": true,
3
+ "main": "index.js",
4
+ "type": "module",
5
+ "scripts": {
6
+ "start": "node index.js",
7
+ "test": "mocha tests.js"
8
+ }
9
+ }
@@ -0,0 +1,118 @@
1
+ // Copyright 2022 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // eslint-disable-next-line rulesdir/es_modules_import
6
+ import idl from '@webref/idl';
7
+ import * as assert from 'assert';
8
+
9
+ import {SPECS} from './config.js';
10
+ import {addMetadata, getIDLProps, minimize} from './get-props.js';
11
+ import {getMissingTypes} from './util.js';
12
+
13
+ describe('DOM pinned properties dataset generation', function() {
14
+ let output;
15
+
16
+ this.beforeEach(async () => {
17
+ const files = await idl.listAll();
18
+ const names = Object.keys(SPECS);
19
+ const specs = await Promise.all(names.map(name => files[name].parse().then(idls => ({name, idls}))));
20
+ output = addMetadata(getIDLProps(specs));
21
+ });
22
+
23
+ it('doesn\'t have missing types', () => {
24
+ const missing = getMissingTypes(output);
25
+ assert.strictEqual(missing.length, 0);
26
+ });
27
+
28
+ it('generates valid data for HTMLElement', () => {
29
+ const type = output.HTMLElement;
30
+ assert.strictEqual(type.inheritance, 'Element');
31
+ assert.deepEqual(type.includes, [
32
+ 'GlobalEventHandlers',
33
+ 'DocumentAndElementEventHandlers',
34
+ 'ElementContentEditable',
35
+ 'HTMLOrSVGElement',
36
+ 'ElementCSSInlineStyle',
37
+ ]);
38
+ assert.deepEqual(type.props.title, {
39
+ global: true,
40
+ specs: ['html'],
41
+ });
42
+ assert.strictEqual(type.states, undefined);
43
+ });
44
+
45
+ it('generates valid data for HTMLInputElement', () => {
46
+ const type = output.HTMLInputElement;
47
+ assert.strictEqual(type.inheritance, 'HTMLElement');
48
+ assert.deepEqual(type.includes, []);
49
+ assert.deepEqual(type.props.checked, {
50
+ global: false,
51
+ specs: ['html'],
52
+ });
53
+ assert.deepEqual(type.states['[type=checkbox]'], {
54
+ checked: {global: false, specs: ['html']},
55
+ required: {global: false, specs: ['html']},
56
+ value: {global: false, specs: ['html']},
57
+ });
58
+ });
59
+
60
+ it('generates valid data for MouseEvent', () => {
61
+ const type = output.MouseEvent;
62
+ assert.strictEqual(type.inheritance, 'UIEvent');
63
+ assert.deepEqual(type.includes, []);
64
+ assert.deepEqual(type.props.screenX, {
65
+ global: false,
66
+ specs: ['uievents'],
67
+ });
68
+ assert.strictEqual(type.states, undefined);
69
+ });
70
+
71
+ it('generates valid data for PointerEvent', () => {
72
+ const type = output.PointerEvent;
73
+ assert.strictEqual(type.inheritance, 'MouseEvent');
74
+ assert.deepEqual(type.includes, []);
75
+ assert.deepEqual(type.props.pressure, {
76
+ global: false,
77
+ specs: ['pointerevents'],
78
+ });
79
+ assert.strictEqual(type.states, undefined);
80
+ });
81
+
82
+ it('generates an entry for DOMParser', () => {
83
+ const type = output.DOMParser;
84
+ assert.strictEqual(type.inheritance, null);
85
+ assert.deepEqual(type.includes, []);
86
+ assert.deepEqual(type.props, {});
87
+ assert.strictEqual(type.states, undefined);
88
+ });
89
+
90
+ it('minimizes the data for HTMLInputElement', () => {
91
+ const minimized = minimize(output);
92
+ const type = minimized.HTMLInputElement;
93
+ assert.strictEqual(type.inheritance, 'HTMLElement');
94
+ assert.strictEqual(type.includes, undefined);
95
+ assert.deepEqual(type.props.checked, {});
96
+ assert.deepEqual(type.states['[type=checkbox]'], {
97
+ checked: {},
98
+ required: {},
99
+ value: {},
100
+ });
101
+ });
102
+
103
+ it('minimizes the data for PointerEvent', () => {
104
+ const minimized = minimize(output);
105
+ const type = minimized.PointerEvent;
106
+ assert.strictEqual(type.inheritance, 'MouseEvent');
107
+ assert.strictEqual(type.includes, undefined);
108
+ assert.deepEqual(type.props.pressure, {
109
+ specs: 8,
110
+ });
111
+ assert.strictEqual(type.states, undefined);
112
+ });
113
+
114
+ it('removes the entry for DOMParser in the minimized output', () => {
115
+ const minimized = minimize(output);
116
+ assert.strictEqual(minimized.DOMParser, undefined);
117
+ });
118
+ });
@@ -0,0 +1,81 @@
1
+ // Copyright 2022 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ /**
6
+ * Merges objects or arrays of objects. This is a simplistic merge operation
7
+ * that is only useful for generating the DOM pinned properties dataset.
8
+ *
9
+ * The merge happens in-place: b is merged *into* a.
10
+ * Both objects must be of the same type.
11
+ * Arrays are merged as unions with simple same-value-zero equality.
12
+ * Objects are merged with truthy-property precedence.
13
+ *
14
+ * @param {array|object} a
15
+ * @param {array|object} b
16
+ */
17
+ export function merge(a, b) {
18
+ if (Array.isArray(a) && Array.isArray(b)) {
19
+ mergeArrays(a, b);
20
+ } else if (isNonNullObject(a) && isNonNullObject(b)) {
21
+ mergeObjects(a, b);
22
+ } else {
23
+ throw Error;
24
+ }
25
+
26
+ function isNonNullObject(value) {
27
+ return typeof value === 'object' && value !== null;
28
+ }
29
+
30
+ function mergeArrays(a, b) {
31
+ const set = new Set(a);
32
+ for (const value of b) {
33
+ if (!set.has(value)) {
34
+ a.push(value);
35
+ }
36
+ }
37
+ }
38
+
39
+ function mergeObjects(a, b) {
40
+ for (const key of Object.keys(b)) {
41
+ if (isNonNullObject(a[key]) && isNonNullObject(b[key])) {
42
+ merge(a[key], b[key]);
43
+ } else {
44
+ a[key] = a[key] ?? b[key];
45
+ }
46
+ }
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Finds "missing" types in a DOM pinned properties dataset.
52
+ * A "missing" type is defined as a type that is inherited or included by/in
53
+ * another type, but for which a definition wasn't found in the specs.
54
+ *
55
+ * This is a helper which helps to ensure that all relevant specs are parsed.
56
+ * E.g. some specs might reference types defined in other specs.
57
+ *
58
+ * @param {object} data
59
+ * @returns {array}
60
+ */
61
+ export function getMissingTypes(data) {
62
+ const missing = new Set();
63
+ const keys = new Set(Object.keys(data));
64
+
65
+ for (const value of Object.values(data)) {
66
+ if (value.inherits) {
67
+ if (!keys.has(value.inherits)) {
68
+ missing.add(value.inherits);
69
+ }
70
+ }
71
+ if (value.includes) {
72
+ for (const include of value.includes) {
73
+ if (!keys.has(include)) {
74
+ missing.add(include);
75
+ }
76
+ }
77
+ }
78
+ }
79
+
80
+ return [...missing];
81
+ }