@idlizer/arktscgen 2.1.10-arktscgen-7 → 2.1.10-arktscgen-10

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.
Files changed (28) hide show
  1. package/build/libarkts-copy/generator/options.json5 +107 -99
  2. package/build/libarkts-copy/native/meson.build +22 -14
  3. package/build/libarkts-copy/native/mingw.cross +1 -1
  4. package/build/libarkts-copy/native/src/bridges.cpp +1 -298
  5. package/build/libarkts-copy/native/src/common.cpp +286 -76
  6. package/build/libarkts-copy/native/src/common.h +0 -15
  7. package/build/libarkts-copy/package.json +12 -16
  8. package/build/libarkts-copy/src/Es2pandaNativeModule.ts +28 -61
  9. package/build/libarkts-copy/src/arkts-api/index.ts +0 -1
  10. package/build/libarkts-copy/src/arkts-api/node-utilities/OpaqueTypeNode.ts +1 -1
  11. package/build/libarkts-copy/src/arkts-api/peers/AstNode.ts +14 -0
  12. package/build/libarkts-copy/src/arkts-api/peers/Context.ts +25 -58
  13. package/build/libarkts-copy/src/arkts-api/peers/ExternalSource.ts +8 -13
  14. package/build/libarkts-copy/src/arkts-api/plugins.ts +3 -2
  15. package/build/libarkts-copy/src/arkts-api/static/global.ts +8 -1
  16. package/build/libarkts-copy/src/arkts-api/utilities/extensions.ts +9 -12
  17. package/build/libarkts-copy/src/arkts-api/utilities/performance.ts +99 -9
  18. package/build/libarkts-copy/src/arkts-api/utilities/private.ts +3 -0
  19. package/build/libarkts-copy/src/arkts-api/utilities/public.ts +68 -148
  20. package/build/libarkts-copy/src/arkts-api/visitor.ts +17 -3
  21. package/build/libarkts-copy/src/index.ts +0 -1
  22. package/build/libarkts-copy/src/plugin-utils.ts +2 -1
  23. package/build/libarkts-copy/src/reexport-for-generated.ts +2 -1
  24. package/build/libarkts-copy/src/utils.ts +4 -0
  25. package/lib/index.js +4599 -4366
  26. package/package.json +3 -4
  27. package/templates/Es2pandaNativeModule.ts +1 -0
  28. package/templates/peer.ts +1 -0
@@ -37,9 +37,6 @@ import { Es2pandaPluginDiagnosticType } from '../generated/Es2pandaEnums';
37
37
  export type KPtrArray = BigUint64Array;
38
38
 
39
39
  export class Es2pandaNativeModule {
40
- _AnnotationAllowedAnnotations(context: KPtr, node: KPtr, returnLen: KPtr): KPtr {
41
- throw new Error('Not implemented');
42
- }
43
40
  _AstNodeRebind(context: KPtr, node: KPtr): void {
44
41
  throw new Error('Not implemented');
45
42
  }
@@ -64,9 +61,6 @@ export class Es2pandaNativeModule {
64
61
  _HasGlobalStructInfo(context: KNativePointer, str: String): KBoolean {
65
62
  throw new Error('Not implemented');
66
63
  }
67
- _DestroyContext(context: KPtr): void {
68
- throw new Error('Not implemented');
69
- }
70
64
  _ProceedToState(context: KPtr, state: number): void {
71
65
  throw new Error('Not implemented');
72
66
  }
@@ -91,9 +85,6 @@ export class Es2pandaNativeModule {
91
85
  _VariableDeclaration(context: KPtr, variable: KPtr): KPtr {
92
86
  throw new Error('Not implemented');
93
87
  }
94
- _DeclNode(context: KPtr, decl: KPtr): KPtr {
95
- throw new Error('Not implemented');
96
- }
97
88
  _ProgramSourceFilePath(context: KNativePointer, instance: KNativePointer): KNativePointer {
98
89
  throw new Error('Not implemented');
99
90
  }
@@ -141,54 +132,11 @@ export class Es2pandaNativeModule {
141
132
  _OptionsArkTsConfig(context: KNativePointer, options: KNativePointer): KNativePointer {
142
133
  throw new Error('Not implemented');
143
134
  }
144
- _Checker_CreateOpaqueTypeNode(context: KNativePointer, type: KNativePointer): KNativePointer {
145
- throw new Error('Not implemented');
146
- }
147
- _Checker_ScriptFunctionSignature(context: KNativePointer, node: KNativePointer): KNativePointer {
148
- throw new Error('Not implemented');
149
- }
150
- _Checker_ScriptFunctionSetSignature(
151
- context: KNativePointer,
152
- node: KNativePointer,
153
- signature: KNativePointer
154
- ): void {
155
- throw new Error('Not implemented');
156
- }
157
- _Checker_SignatureReturnType(context: KNativePointer, signature: KNativePointer): KNativePointer {
158
- throw new Error('Not implemented');
159
- }
160
- _Checker_ScriptFunctionGetPreferredReturnType(context: KNativePointer, node: KNativePointer): KNativePointer {
161
- throw new Error('Not implemented');
162
- }
163
- _Checker_ScriptFunctionSetPreferredReturnType(
135
+ _JumpFromETSTypeReferenceToTSTypeAliasDeclarationTypeAnnotation(
164
136
  context: KNativePointer,
165
- node: KNativePointer,
166
- type: KNativePointer
167
- ): void {
168
- throw new Error('Not implemented');
169
- }
170
- _Checker_ExpressionGetPreferredType(context: KNativePointer, node: KNativePointer): KNativePointer {
171
- throw new Error('Not implemented');
172
- }
173
- _Checker_ExpressionSetPreferredType(context: KNativePointer, node: KNativePointer, type: KNativePointer): void {
174
- throw new Error('Not implemented');
175
- }
176
- _Checker_TypeToString(context: KNativePointer, type: KNativePointer): KNativePointer {
177
- throw new Error('Not implemented');
178
- }
179
- _Checker_TypeClone(context: KNativePointer, type: KNativePointer): KNativePointer {
180
- throw new Error('Not implemented');
181
- }
182
- _Checker_TypeNodeGetType(context: KNativePointer, node: KNativePointer): KNativePointer {
183
- throw new Error('Not implemented');
184
- }
185
- _ScriptFunctionSetParams(
186
- context: KNativePointer,
187
- receiver: KNativePointer,
188
- paramsList: BigUint64Array,
189
- paramsListLength: KUInt
190
- ): void {
191
- throw new Error('Not implemented');
137
+ etsTypeReference: KNativePointer,
138
+ ): KNativePointer {
139
+ throw new Error('Not implemented')
192
140
  }
193
141
  _ClassDefinitionSetBody(
194
142
  context: KNativePointer,
@@ -212,6 +160,15 @@ export class Es2pandaNativeModule {
212
160
  _ClassVariableDeclaration(context: KNativePointer, classInstance: KNativePointer): KNativePointer {
213
161
  throw new Error('Not implemented');
214
162
  }
163
+ _DeclarationFromProperty(context: KPtr, property: KPtr): KPtr {
164
+ throw new Error('Not implemented');
165
+ }
166
+ _DeclarationFromMemberExpression(context: KPtr, expression: KPtr): KPtr {
167
+ throw new Error('Not implemented');
168
+ }
169
+ _DeclarationFromAstNode(context: KPtr, node: KPtr): KPtr {
170
+ throw new Error('Not implemented');
171
+ }
215
172
  _ETSParserGetGlobalProgramAbsName(context: KNativePointer): KNativePointer {
216
173
  throw new Error('Not implemented');
217
174
  }
@@ -234,16 +191,22 @@ export class Es2pandaNativeModule {
234
191
  _SetUpSoPath(soPath: string): void {
235
192
  throw new Error('Not implemented');
236
193
  }
237
- _MemInitialize(): void {
194
+ _ProgramCanSkipPhases(context: KNativePointer, program: KNativePointer): KBoolean {
238
195
  throw new Error('Not implemented');
239
196
  }
240
- _MemFinalize(): void {
197
+ _AstNodeProgram(context: KNativePointer, instance: KNativePointer): KNativePointer {
241
198
  throw new Error('Not implemented');
242
199
  }
243
- _ProgramCanSkipPhases(context: KNativePointer, program: KNativePointer): KBoolean {
200
+
201
+ _AstNodeFindNodeInInnerChild(context: KNativePointer, node: KNativePointer, target: KNativePointer): boolean {
244
202
  throw new Error('Not implemented');
245
203
  }
246
- _AstNodeProgram(context: KNativePointer, instance: KNativePointer): KNativePointer {
204
+
205
+ _AstNodeFindInnerChild(context: KNativePointer, node: KNativePointer, nodeType: KInt): KNativePointer {
206
+ throw new Error('Not implemented');
207
+ }
208
+
209
+ _AstNodeFindOuterParent(context: KNativePointer, node: KNativePointer, nodeType: KInt): KNativePointer {
247
210
  throw new Error('Not implemented');
248
211
  }
249
212
 
@@ -269,7 +232,11 @@ export class Es2pandaNativeModule {
269
232
  }
270
233
 
271
234
  export function findNativeModule(): string {
272
- const candidates = [path.resolve(__dirname, '../native/build'), path.resolve(__dirname, '../build/native/build')];
235
+ const candidates = [
236
+ path.resolve(__dirname, '../native/build'),
237
+ path.resolve(__dirname, '../build/native'),
238
+ path.resolve(__dirname, '../build/native/build')
239
+ ];
273
240
  let result = undefined;
274
241
  candidates.forEach((path) => {
275
242
  if (fs.existsSync(path)) {
@@ -29,7 +29,6 @@ export * from './ProgramProvider';
29
29
  export * from './peers/AstNode';
30
30
  export * from './peers/Config';
31
31
  export * from './peers/Context';
32
- export { GlobalContext } from './peers/Context';
33
32
  export * from './peers/ExternalSource';
34
33
  export * from './peers/Options';
35
34
  export * from './node-utilities/ArkTsConfig';
@@ -20,7 +20,7 @@ import { Es2pandaAstNodeType } from '../../../generated/Es2pandaEnums';
20
20
 
21
21
  export function createOpaqueTypeNode(typePointer: KNativePointer): OpaqueTypeNode {
22
22
  return new OpaqueTypeNode(
23
- global.es2panda._Checker_CreateOpaqueTypeNode(global.context, typePointer),
23
+ global.generatedEs2panda._CreateOpaqueTypeNode(global.context, typePointer),
24
24
  Es2pandaAstNodeType.AST_NODE_TYPE_OPAQUE_TYPE_NODE
25
25
  );
26
26
  }
@@ -105,6 +105,20 @@ export abstract class AstNode extends ArktsObject {
105
105
  return clonedNode as this;
106
106
  }
107
107
 
108
+ public findNodeInInnerChild(node: AstNode): boolean {
109
+ return global.es2panda._AstNodeFindNodeInInnerChild(global.context, this.peer, node.peer);
110
+ }
111
+
112
+ public findInnerChild<T extends AstNode>(nodeType: Es2pandaAstNodeType): T | undefined {
113
+ const childNodePeer = global.es2panda._AstNodeFindInnerChild(global.context, this.peer, nodeType);
114
+ return unpackNode(childNodePeer, nodeType);
115
+ }
116
+
117
+ public findOuterParent<T extends AstNode>(nodeType: Es2pandaAstNodeType): T | undefined {
118
+ const parentNodePeer = global.es2panda._AstNodeFindOuterParent(global.context, this.peer, nodeType);
119
+ return unpackNode(parentNodePeer, nodeType);
120
+ }
121
+
108
122
  public get parent(): AstNode | undefined {
109
123
  const parent = global.generatedEs2panda._AstNodeParent(global.context, this.peer);
110
124
  return unpackNode(parent);
@@ -14,110 +14,77 @@
14
14
  */
15
15
 
16
16
  import { ArktsObject } from './ArktsObject';
17
- import { Program } from '../../../generated';
17
+ import { compiler, Program } from '../../../generated';
18
18
  import { global } from '../static/global';
19
- import { passString, passStringArray } from '../utilities/private';
20
19
  import { KNativePointer, nullptr, KBoolean } from '@koalaui/interop';
21
20
  import { Config } from './Config';
22
- import { filterSource, throwError } from '../../utils';
21
+ import { filterSource } from '../../utils';
23
22
  import { AstNode } from './AstNode';
24
23
 
24
+ // Perhaps, this file would become generated some time later
25
+ // Please, do not add hard logic here
26
+
25
27
  export class Context extends ArktsObject {
26
28
  constructor(peer: KNativePointer) {
27
29
  super(peer);
28
30
  }
29
31
 
30
32
  static createFromString(source: string): Context {
31
- if (!global.configIsInitialized()) {
32
- throw new Error(`Config not initialized`);
33
- }
34
- return new Context(
35
- global.generatedEs2panda._CreateContextFromString(global.config, passString(source), passString(global.filePath))
36
- );
33
+ return compiler.createContextFromString(global.configObj, source, global.filePath);
37
34
  }
38
35
 
39
- /** @deprecated Use {@link createCacheFromFile} instead */
40
36
  static createCacheContextFromFile(
41
37
  configPtr: KNativePointer,
42
38
  fileName: string,
43
39
  globalContextPtr: KNativePointer,
44
40
  isExternal: KBoolean
45
41
  ): Context {
46
- return new Context(
47
- global.generatedEs2panda._CreateCacheContextFromFile(configPtr, passString(fileName), globalContextPtr, isExternal)
48
- );
42
+ return compiler.createCacheContextFromFile(new Config(configPtr), fileName, new GlobalContext(globalContextPtr), isExternal);
49
43
  }
50
44
 
51
45
  static createFromFile(filePath: string): Context {
52
- return new Context(global.generatedEs2panda._CreateContextFromFile(global.config, passString(filePath)));
46
+ return compiler.createContextFromFile(global.configObj, filePath);
53
47
  }
54
48
 
55
- static createCacheFromFile(filePath: string, config: Config, globalContext: GlobalContext, isExternal: boolean) {
56
- return new Context(
57
- global.generatedEs2panda._CreateCacheContextFromFile(
58
- config.peer,
59
- passString(filePath),
60
- globalContext.peer,
61
- isExternal
62
- )
63
- );
49
+ static createCacheFromFile(filePath: string, config: Config, globalContext: GlobalContext, isExternal: boolean): Context {
50
+ return compiler.createCacheContextFromFile(config, filePath, globalContext, isExternal);
64
51
  }
65
52
 
66
53
  static createContextGenerateAbcForExternalSourceFiles(filenames: string[]): Context {
67
- if (!global.configIsInitialized()) {
68
- throwError(`Config not initialized`);
69
- }
70
- return new Context(
71
- global.generatedEs2panda._CreateContextGenerateAbcForExternalSourceFiles(
72
- global.config,
73
- filenames.length,
74
- passStringArray(filenames)
75
- )
76
- );
54
+ return compiler.createContextGenerateAbcForExternalSourceFiles(global.configObj, filenames);
77
55
  }
78
56
 
79
- destroy() {
80
- if (this.peer !== nullptr) {
81
- global.es2panda._DestroyContext(this.peer);
82
- this.peer = nullptr;
83
- }
57
+ static createFromStringWithHistory(source: string): Context {
58
+ return compiler.createContextFromStringWithHistory(global.configObj, source, global.filePath);
59
+ }
60
+
61
+ destroy(): void {
62
+ compiler.destroyContext();
84
63
  }
85
64
 
86
65
  /** @deprecated */
87
66
  static destroyAndRecreate(ast: AstNode): Context {
88
67
  console.log('[TS WRAPPER] DESTROY AND RECREATE');
89
68
  const source = filterSource(ast.dumpSrc());
90
- global.es2panda._DestroyContext(global.context);
91
- global.compilerContext = Context.createFromString(source) as any; // Improve: commonize Context
92
-
93
- return new Context(global.context);
69
+ compiler.destroyContext();
70
+ return global.compilerContext = Context.createFromString(source);
94
71
  }
95
72
 
96
73
  get program(): Program {
97
- return new Program(global.generatedEs2panda._ContextProgram(this.peer));
74
+ return compiler.contextProgram();
98
75
  }
99
76
  }
100
77
 
101
78
  export class GlobalContext extends ArktsObject {
102
- static create(config: Config, externalFileList: string[]): GlobalContext {
103
- return new GlobalContext(
104
- global.generatedEs2panda._CreateGlobalContext(
105
- config.peer,
106
- passStringArray(externalFileList),
107
- externalFileList.length,
108
- false
109
- )
110
- );
111
- }
112
-
113
79
  constructor(peer: KNativePointer) {
114
80
  super(peer);
115
81
  }
116
82
 
83
+ static create(config: Config, externalFileList: string[]): GlobalContext {
84
+ return compiler.createGlobalContext(config, externalFileList, false);
85
+ }
86
+
117
87
  destroy() {
118
- if (this.peer !== nullptr) {
119
- global.generatedEs2panda._DestroyGlobalContext(this.peer);
120
- this.peer = nullptr;
121
- }
88
+ compiler.destroyGlobalContext();
122
89
  }
123
90
  }
@@ -13,11 +13,13 @@
13
13
  * limitations under the License.
14
14
  */
15
15
 
16
- import { global } from '../static/global';
17
- import { acceptNativeObjectArrayResult, unpackString } from '../utilities/private';
18
- import { KNativePointer, nullptr } from '@koalaui/interop';
16
+ import { KNativePointer } from '@koalaui/interop';
19
17
  import { Program } from '../../../generated';
20
18
  import { ArktsObject } from './ArktsObject';
19
+ import { compiler } from '../../../generated';
20
+
21
+ // Perhaps, this file would become generated some time later
22
+ // Please, do not add hard logic here
21
23
 
22
24
  export class ExternalSource extends ArktsObject {
23
25
  constructor(peer: KNativePointer) {
@@ -25,17 +27,10 @@ export class ExternalSource extends ArktsObject {
25
27
  }
26
28
 
27
29
  getName(): string {
28
- return unpackString(global.es2panda._ExternalSourceName(this.peer));
29
- }
30
-
31
- get programs(): Program[] {
32
- return acceptNativeObjectArrayResult<Program>(
33
- global.es2panda._ExternalSourcePrograms(this.peer),
34
- (instance: KNativePointer) => new Program(instance)
35
- );
30
+ return compiler.externalSourceName(this);
36
31
  }
37
32
 
38
- static instantiate(peer: KNativePointer) {
39
- return new ExternalSource(peer);
33
+ get programs(): readonly Program[] {
34
+ return compiler.externalSourcePrograms(this);
40
35
  }
41
36
  }
@@ -61,6 +61,7 @@ export interface ProjectConfig {
61
61
  frameworkMode?: string;
62
62
  isUi2abc?: boolean;
63
63
  memoPluginOptions?: Object;
64
+ uiPluginOptions?: Object;
64
65
  }
65
66
 
66
67
  export interface PluginContextBase {
@@ -223,10 +224,10 @@ export function defaultFilter(name: string): boolean {
223
224
  return true;
224
225
  }
225
226
 
226
- export function listPrograms(program: Program, filter: (name: string) => boolean = defaultFilter): Program[] {
227
+ export function listPrograms(program: Program, filter: (name: string) => boolean = defaultFilter): readonly Program[] {
227
228
  return [
228
229
  program,
229
- ...program.getExternalSources().flatMap((it: ExternalSource): Program[] => {
230
+ ...program.getExternalSources().flatMap((it: ExternalSource): readonly Program[] => {
230
231
  if (filter(it.getName())) {
231
232
  return it.programs;
232
233
  }
@@ -40,6 +40,7 @@ export class UpdateTracker {
40
40
  }
41
41
 
42
42
  export class global {
43
+ /** @deprecated */
43
44
  public static filePath: string = './plugins/input/main.ets';
44
45
 
45
46
  public static arktsconfig?: ArkTsConfig;
@@ -68,7 +69,6 @@ export class global {
68
69
 
69
70
  // Improve: rename to context when the pointer valued one is eliminated
70
71
  public static compilerContext: Context | undefined;
71
- public static isContextGenerateAbcForExternalSourceFiles: boolean = false;
72
72
 
73
73
  private static _es2panda: Es2pandaNativeModule | undefined = undefined;
74
74
  public static get es2panda(): Es2pandaNativeModule {
@@ -79,6 +79,13 @@ export class global {
79
79
  }
80
80
 
81
81
  private static _generatedEs2panda: GeneratedEs2pandaNativeModule | undefined = undefined;
82
+ /**
83
+ * @deprecated
84
+ *
85
+ * You should not generally use generatedEs2panda in handwritten code
86
+ * (only in exceptional cases).
87
+ * Please use generated wrapper for native call instead.
88
+ */
82
89
  public static get generatedEs2panda(): GeneratedEs2pandaNativeModule {
83
90
  if (this._generatedEs2panda === undefined) {
84
91
  this._generatedEs2panda = initGeneratedEs2panda();
@@ -61,14 +61,14 @@ export function extension_MethodDefinitionOnUpdate(this: MethodDefinition, origi
61
61
 
62
62
  // Improve: generate checker related stuff
63
63
  export function extension_ScriptFunctionGetSignaturePointer(this: ScriptFunction): KNativePointer {
64
- return global.es2panda._Checker_ScriptFunctionSignature(global.context, this.peer);
64
+ return global.generatedEs2panda._ScriptFunctionSignature(global.context, this.peer);
65
65
  }
66
66
 
67
67
  export function extension_ScriptFunctionSetSignaturePointer(
68
68
  this: ScriptFunction,
69
69
  signaturePointer: KNativePointer
70
70
  ): void {
71
- global.es2panda._Checker_ScriptFunctionSetSignature(global.context, this.peer, signaturePointer);
71
+ global.generatedEs2panda._ScriptFunctionSetSignature(global.context, this.peer, signaturePointer);
72
72
  }
73
73
 
74
74
  // Improve: weird API
@@ -81,23 +81,23 @@ export function extension_ScriptFunctionGetParamsCasted(this: ScriptFunction): r
81
81
 
82
82
  // Improve: perhaps "preferredReturnType" stuff can be removed later if "signature" is always enough
83
83
  export function extension_ScriptFunctionGetPreferredReturnTypePointer(this: ScriptFunction): KNativePointer {
84
- return global.es2panda._Checker_ScriptFunctionGetPreferredReturnType(global.context, this.peer);
84
+ return global.generatedEs2panda._ScriptFunctionGetPreferredReturnType(global.context, this.peer);
85
85
  }
86
86
 
87
87
  export function extension_ScriptFunctionSetPreferredReturnTypePointer(
88
88
  this: ScriptFunction,
89
89
  typePointer: KNativePointer
90
90
  ): void {
91
- global.es2panda._Checker_ScriptFunctionSetPreferredReturnType(global.context, this.peer, typePointer);
91
+ global.generatedEs2panda._ScriptFunctionSetPreferredReturnType(global.context, this.peer, typePointer);
92
92
  }
93
93
 
94
94
  // Improve: generate checker related stuff
95
95
  export function extension_ExpressionGetPreferredTypePointer(this: Expression): KNativePointer {
96
- return global.es2panda._Checker_ExpressionGetPreferredType(global.context, this.peer);
96
+ return global.generatedEs2panda._ExpressionPreferredTypeConst(global.context, this.peer);
97
97
  }
98
98
 
99
99
  export function extension_ExpressionSetPreferredTypePointer(this: Expression, typePointer: KNativePointer): void {
100
- global.es2panda._Checker_ExpressionSetPreferredType(global.context, this.peer, typePointer);
100
+ global.generatedEs2panda._ExpressionSetPreferredType(global.context, this.peer, typePointer);
101
101
  }
102
102
 
103
103
  // Improve: weird API
@@ -108,12 +108,9 @@ export function extension_ProgramGetAstCasted(this: Program): ETSModule {
108
108
  );
109
109
  }
110
110
 
111
- // Improve: generate methods with string[] args or return type
112
- export function extension_ProgramGetExternalSources(this: Program): ExternalSource[] {
113
- return acceptNativeObjectArrayResult<ExternalSource>(
114
- global.es2panda._ProgramExternalSources(global.context, this.peer),
115
- ExternalSource.instantiate
116
- );
111
+ /** @deprecated Now generated */
112
+ export function extension_ProgramGetExternalSources(this: Program): readonly ExternalSource[] {
113
+ return this.externalSources;
117
114
  }
118
115
 
119
116
  // Improve: SourcePositionLine is global in idl
@@ -56,22 +56,34 @@ function round(value: number, index: number = 2): number {
56
56
  return Math.round(value * factor) / factor;
57
57
  }
58
58
 
59
+ interface DetailedEventInfo {
60
+ duration: number;
61
+ count: number;
62
+ }
63
+
59
64
  export class Performance {
60
65
  private static instance: Performance;
61
66
  private events: Map<string, Event>;
67
+ private detailedEvents: Map<string, Event>;
62
68
  private historyEvents = new Map<string | null, Event[]>();
63
69
  private scopes: string[];
64
70
  private shouldSkip: boolean;
71
+ private shouldSkipDetail: boolean;
65
72
  private totalDuration: number;
66
73
  private memoryContexts = new Map<string, MemoryContext>();
67
74
  private memoryTrackerEnable: boolean;
75
+ private detailedEventInfos: Map<string, DetailedEventInfo>;
76
+
68
77
  private constructor() {
69
78
  this.events = new Map();
79
+ this.detailedEvents = new Map();
70
80
  this.historyEvents = new Map();
71
81
  this.scopes = [];
72
82
  this.shouldSkip = true;
83
+ this.shouldSkipDetail = true;
73
84
  this.memoryTrackerEnable = false;
74
85
  this.totalDuration = 0;
86
+ this.detailedEventInfos = new Map<string, DetailedEventInfo>();
75
87
  }
76
88
 
77
89
  public static getInstance(): Performance {
@@ -81,8 +93,14 @@ export class Performance {
81
93
  return this.instance;
82
94
  }
83
95
 
84
- skip(shouldSkip: boolean = true): void {
96
+ skip(shouldSkip: boolean = true): this {
85
97
  this.shouldSkip = shouldSkip;
98
+ return this;
99
+ }
100
+
101
+ skipDetail(shouldSkipDetail: boolean = true): this {
102
+ this.shouldSkipDetail = shouldSkipDetail;
103
+ return this;
86
104
  }
87
105
 
88
106
  enableMemoryTracker(enableMemoryTracker: boolean = false): void {
@@ -100,6 +118,57 @@ export class Performance {
100
118
  return newEvent;
101
119
  }
102
120
 
121
+ logDetailedEventInfos(shouldLog: boolean = false): void {
122
+ if (!shouldLog) {
123
+ return;
124
+ }
125
+ const sortedEvents = new Map([...this.detailedEventInfos.entries()].sort((a, b) => a[0].localeCompare(b[0])));
126
+ for (const [key, value] of sortedEvents) {
127
+ const dura = formatTime(value.duration);
128
+ const duraRound = round(value.duration);
129
+ const perDura = formatTime(value.duration / value.count);
130
+ const duraPerDura = round(value.duration / value.count);
131
+ console.log(
132
+ `[PERFORMANCE] name: ${key}, detailed-total-duration: ${dura}(${duraRound}), total-count: ${value.count}, time-per-conversion: ${perDura}(${duraPerDura})`
133
+ );
134
+ }
135
+ }
136
+
137
+ createDetailedEvent(name: string) {
138
+ if (this.shouldSkipDetail) {
139
+ return { name: '', startTime: 0 };
140
+ }
141
+ const startTime: number = performance.now();
142
+ const newEvent: Event = { name, startTime };
143
+ this.detailedEvents.set(name, newEvent);
144
+ }
145
+
146
+ stopDetailedEvent(name: string, shouldLog: boolean = false) {
147
+ if (this.shouldSkipDetail) {
148
+ return { name: '', startTime: 0 };
149
+ }
150
+ if (!this.detailedEvents.has(name)) {
151
+ throw new Error(`Event ${name} is not created.`);
152
+ }
153
+
154
+ const event: Event = this.detailedEvents.get(name)!;
155
+ const endTime: number = performance.now();
156
+ const duration: number = endTime - event.startTime;
157
+
158
+ let totalDetailedDuration = duration;
159
+ let totalDetailedCount = 1;
160
+ if (this.detailedEventInfos.has(name)) {
161
+ const lastInfo = this.detailedEventInfos.get(name)!;
162
+ totalDetailedDuration += lastInfo.duration;
163
+ totalDetailedCount += lastInfo.count;
164
+ }
165
+
166
+ this.detailedEventInfos.set(name, {
167
+ duration: totalDetailedDuration,
168
+ count: totalDetailedCount,
169
+ });
170
+ }
171
+
103
172
  stopEvent(name: string, shouldLog: boolean = false): Event {
104
173
  if (this.shouldSkip) {
105
174
  return { name: '', startTime: 0 };
@@ -122,7 +191,9 @@ export class Performance {
122
191
 
123
192
  if (shouldLog) {
124
193
  console.log(
125
- `[PERFORMANCE] name: ${event.name}, parent: ${parentEvent}, duration: ${formatTime(duration)}(${round(duration)}), total: ${formatTime(this.totalDuration)}(${round(this.totalDuration)})`
194
+ `[PERFORMANCE] name: ${event.name}, parent: ${parentEvent}, duration: ${formatTime(duration)}(${round(
195
+ duration
196
+ )}), total: ${formatTime(this.totalDuration)}(${round(this.totalDuration)})`
126
197
  );
127
198
  }
128
199
 
@@ -154,7 +225,9 @@ export class Performance {
154
225
 
155
226
  if (shouldLog) {
156
227
  console.log(
157
- `[PERFORMANCE] name: ${event.name}, parent: ${parentEvent}, duration: ${formatTime(duration)}(${round(duration)}), total: ${formatTime(this.totalDuration)}(${round(this.totalDuration)})`
228
+ `[PERFORMANCE] name: ${event.name}, parent: ${parentEvent}, duration: ${formatTime(duration)}(${round(
229
+ duration
230
+ )}), total: ${formatTime(this.totalDuration)}(${round(this.totalDuration)})`
158
231
  );
159
232
  }
160
233
 
@@ -176,6 +249,8 @@ export class Performance {
176
249
 
177
250
  clearTotalDuration(): void {
178
251
  this.totalDuration = 0;
252
+ this.detailedEventInfos.clear();
253
+ this.detailedEvents.clear();
179
254
  }
180
255
 
181
256
  clearHistory(): void {
@@ -273,23 +348,38 @@ export class Performance {
273
348
  console.log('---------------------------------------------------------------');
274
349
  console.log(
275
350
  '[PERFORMANCE]',
276
- `RSS | ${context.startMemory.rss.toFixed(2)} | ${(endMemory.rss / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.rss.toFixed(2)}`
351
+ `RSS | ${context.startMemory.rss.toFixed(2)} | ${(
352
+ endMemory.rss /
353
+ (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
354
+ ).toFixed(2)} | ${memoryDiff.rss.toFixed(2)}`
277
355
  );
278
356
  console.log(
279
357
  '[PERFORMANCE]',
280
- `Heap Total | ${context.startMemory.heapTotal.toFixed(2)} | ${(endMemory.heapTotal / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.heapTotal.toFixed(2)}`
358
+ `Heap Total | ${context.startMemory.heapTotal.toFixed(2)} | ${(
359
+ endMemory.heapTotal /
360
+ (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
361
+ ).toFixed(2)} | ${memoryDiff.heapTotal.toFixed(2)}`
281
362
  );
282
363
  console.log(
283
364
  '[PERFORMANCE]',
284
- `Heap Used | ${context.startMemory.heapUsed.toFixed(2)} | ${(endMemory.heapUsed / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.heapUsed.toFixed(2)}`
365
+ `Heap Used | ${context.startMemory.heapUsed.toFixed(2)} | ${(
366
+ endMemory.heapUsed /
367
+ (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
368
+ ).toFixed(2)} | ${memoryDiff.heapUsed.toFixed(2)}`
285
369
  );
286
370
  console.log(
287
371
  '[PERFORMANCE]',
288
- `External | ${context.startMemory.external.toFixed(2)} | ${(endMemory.external / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.external.toFixed(2)}`
372
+ `External | ${context.startMemory.external.toFixed(2)} | ${(
373
+ endMemory.external /
374
+ (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
375
+ ).toFixed(2)} | ${memoryDiff.external.toFixed(2)}`
289
376
  );
290
- if (!!endMemory.arrayBuffers) {
377
+ if (endMemory.arrayBuffers !== undefined) {
291
378
  console.log(
292
- `Array Buffers | ${context.startMemory.arrayBuffers.toFixed(2)} | ${((endMemory.arrayBuffers || 0) / (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)).toFixed(2)} | ${memoryDiff.arrayBuffers.toFixed(2)}`
379
+ `Array Buffers | ${context.startMemory.arrayBuffers.toFixed(2)} | ${(
380
+ (endMemory.arrayBuffers || 0) /
381
+ (BYTES_PER_KIBIBYTE * BYTES_PER_KIBIBYTE)
382
+ ).toFixed(2)} | ${memoryDiff.arrayBuffers.toFixed(2)}`
293
383
  );
294
384
  }
295
385
  console.log('---------------------------------------------------------------');
@@ -76,6 +76,9 @@ export function unpackNativeObjectArray<T extends ArktsObject>(
76
76
  arrayObject: KNativePointer,
77
77
  factory: (instance: KNativePointer) => T
78
78
  ): T[] {
79
+ if (arrayObject == nullptr) {
80
+ return [];
81
+ }
79
82
  return acceptNativeObjectArrayResult(arrayObject, factory);
80
83
  }
81
84