forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathJavaScriptMetadata.ts
More file actions
63 lines (54 loc) · 2.1 KB
/
Copy pathJavaScriptMetadata.ts
File metadata and controls
63 lines (54 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2018 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 type * as Common from '../../core/common/common.js';
import {NativeFunctions} from './NativeFunctions.js';
let javaScriptMetadataInstance: JavaScriptMetadataImpl;
export class JavaScriptMetadataImpl implements Common.JavaScriptMetaData.JavaScriptMetaData {
private readonly uniqueFunctions: Map<string, string[][]>;
private readonly receiverMethods: Map<string, Map<string, string[][]>>;
static instance(opts: {
forceNew: boolean|null,
} = {forceNew: null}): JavaScriptMetadataImpl {
const {forceNew} = opts;
if (!javaScriptMetadataInstance || forceNew) {
javaScriptMetadataInstance = new JavaScriptMetadataImpl();
}
return javaScriptMetadataInstance;
}
constructor() {
this.uniqueFunctions = new Map();
this.receiverMethods = new Map();
for (const nativeFunction of NativeFunctions) {
if (!nativeFunction.receivers) {
this.uniqueFunctions.set(nativeFunction.name, nativeFunction.signatures);
continue;
}
for (const receiver of nativeFunction.receivers) {
let method = this.receiverMethods.get(receiver);
if (!method) {
method = new Map();
this.receiverMethods.set(receiver, method);
}
method.set(nativeFunction.name, nativeFunction.signatures);
}
}
}
signaturesForNativeFunction(name: string): string[][]|null {
return this.uniqueFunctions.get(name) || null;
}
signaturesForInstanceMethod(name: string, receiverClassName: string): string[][]|null {
const instanceMethod = this.receiverMethods.get(receiverClassName);
if (!instanceMethod) {
return null;
}
return instanceMethod.get(name) || null;
}
signaturesForStaticMethod(name: string, receiverConstructorName: string): string[][]|null {
const staticMethod = this.receiverMethods.get(receiverConstructorName + 'Constructor');
if (!staticMethod) {
return null;
}
return staticMethod.get(name) || null;
}
}