MCPcopy Create free account
hub / github.com/ChromeDevTools/devtools-frontend / postProcess

Function postProcess

scripts/javascript_natives/helpers.js:136–232  ·  view source on GitHub ↗
(dryRun = false)

Source from the content-addressed store, hash-verified

134}
135
136export function postProcess(dryRun = false) {
137 for (const name of methods.keys()) {
138 // We use the set jsonParents to track the set of different signatures across parent for this function name.
139 // If all signatures are identical, we leave out the parent and emit a single NativeFunction entry without receiver.
140 const jsonParents = new Set();
141 for (const [parent, signatures] of methods.get(name)) {
142 signatures.sort((a, b) => a.length - b.length);
143 const filteredSignatures = [];
144 for (const signature of signatures) {
145 const smallerIndex = filteredSignatures.findIndex(smaller => startsTheSame(smaller, signature));
146 if (smallerIndex !== -1) {
147 filteredSignatures[smallerIndex] = (signature.map((arg, index) => {
148 const otherArg = filteredSignatures[smallerIndex][index];
149 if (otherArg) {
150 return otherArg.length > arg.length ? otherArg : arg;
151 }
152 if (arg.startsWith('?') || arg.startsWith('...')) {
153 return arg;
154 }
155 return '?' + arg;
156 }));
157 } else {
158 filteredSignatures.push(signature);
159 }
160 }
161
162 function startsTheSame(smaller, bigger) {
163 for (let i = 0; i < smaller.length; i++) {
164 const withoutQuestion = str => /[\?]?(.*)/.exec(str)[1];
165 if (withoutQuestion(smaller[i]) !== withoutQuestion(bigger[i])) {
166 return false;
167 }
168 }
169 return true;
170 }
171
172 methods.get(name).set(parent, filteredSignatures);
173 jsonParents.add(JSON.stringify(filteredSignatures));
174 }
175 // If all parents had the same signature for this name, we put a `*` as parent for this entry.
176 if (jsonParents.size === 1) {
177 methods.set(name, new Map([['*', JSON.parse(jsonParents.values().next().value)]]));
178 }
179 for (const [parent, signatures] of methods.get(name)) {
180 if (signatures.length === 1 && !signatures[0].length) {
181 methods.get(name).delete(parent);
182 }
183 }
184 if (methods.get(name).size === 0) {
185 methods.delete(name);
186 }
187 }
188 const functions = [];
189 for (const [name, method] of methods) {
190 if (method.has('*')) {
191 // All parents had the same signature so we emit an entry without receiver.
192 functions.push({name, signatures: method.get('*')});
193 } else {

Callers 2

index.jsFile · 0.90
tests.jsFile · 0.90

Calls 15

startsTheSameFunction · 0.85
findIndexMethod · 0.80
valuesMethod · 0.80
getMethod · 0.65
setMethod · 0.65
stringifyMethod · 0.65
nextMethod · 0.65
deleteMethod · 0.65
keysMethod · 0.45
sortMethod · 0.45
mapMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected