已开启
docs: update cjbind download link and demo code in hle #530
Cangjie-wanggang创建于 5月30日
docs: update cjbind download link and demo code in hle #530
已开启
Cangjie-wanggang创建于 5月30日
4 个文件变更+1612-808
@@ -75,8 +75,9 @@ hle -b ${CANGJIE_HOME}/tools/dtsparser/node_modules/.bin/cjbind -c --module-name
75 75 
76The `-b` parameter is used to specify the path to the cjbind binary file. The cjbind download link is as follows:76The `-b` parameter is used to specify the path to the cjbind binary file. The cjbind download link is as follows:
77 77 
78-- Linux: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v0.2.7/cjbind-linux-x64>78+- Linux-x64: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v1.1.0-alpha.53.1/cjbind-linux-x64>
79-- Windows: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v0.2.7/cjbind-windows-x64.exe>79+- Linux-arm64: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v1.1.0-alpha.53.1/cjbind-linux-arm64>
80-- macOS: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v0.2.7/cjbind-darwin-arm64>80+- Windows-x64: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v1.1.0-alpha.53.1/cjbind-windows-x64.exe>
81+- macOS-arm64: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v1.1.0-alpha.53.1/cjbind-darwin-arm64>
81 82 
82The `--clang-args` parameter is directly passed to clang, and the -I option can be used within its value to specify header file search paths. System header file paths are searched automatically by the program, while user-defined header file paths need to be explicitly specified.83The `--clang-args` parameter is directly passed to clang, and the -I option can be used within its value to specify header file search paths. System header file paths are searched automatically by the program, while user-defined header file paths need to be explicitly specified.
@@ -42,9 +42,9 @@ import ohos.base.*
42 42 
43/***********METHOD***********/43/***********METHOD***********/
44/**44/**
45-* @brief greeter(fn: (a: string) => void): void45+ * @brief greeter(fn: (a: string) => void): void
46-*/46+ */
47-public func greeter(fn: (a: String) -> Unit): Unit {47+public func greeter(fn: (String) -> Unit): Unit {
48 hmsGlobalApiCall < Unit >( "_ark_interop_api", "greeter", { ctx =>[ctx.function({ ctx, info =>48 hmsGlobalApiCall < Unit >( "_ark_interop_api", "greeter", { ctx =>[ctx.function({ ctx, info =>
49 let p0 = String.fromJSValue(ctx, info[0])49 let p0 = String.fromJSValue(ctx, info[0])
50 fn(p0)50 fn(p0)
@@ -53,12 +53,11 @@ public func greeter(fn: (a: String) -> Unit): Unit {
53}53}
54 54 
55/**55/**
56-* @brief printToConsole(s: string): void56+ * @brief printToConsole(s: string): void
57-*/57+ */
58public func printToConsole(s: String): Unit {58public func printToConsole(s: String): Unit {
59 hmsGlobalApiCall < Unit >( "_ark_interop_api", "printToConsole", { ctx =>[s.toJSValue(ctx)] })59 hmsGlobalApiCall < Unit >( "_ark_interop_api", "printToConsole", { ctx =>[s.toJSValue(ctx)] })
60}60}
61- 
62```61```
63 62 
64Generic function example:63Generic function example:
@@ -72,15 +71,17 @@ declare function testMultiGenericT<T, M>(t: T, m: M): T;
72Generated Cangjie code:71Generated Cangjie code:
73 72 
74```cangjie73```cangjie
75-/**74+import ohos.ark_interop.*
76- * @brief testMultiGenericT(t: T, m: M): T75+import ohos.ark_interop_helper.*
77- */76+import ohos.base.*
78-public func testMultiGenericT < T, M >(t: T, m: M): T where T <: JSInteropType<T>, M <: JSInteropType<M> {
79- hmsGlobalApiCall < T >( "my_module_genericFunction", "testMultiGenericT", { ctx =>[t.toJSValue(ctx), m.toJSValue(ctx)] }) {
80- ctx, info => T.fromJSValue(ctx, info)
81- }
82-}
83 77 
78+/***********METHOD***********/
79+/**
80+ * @brief testMultiGenericT(t: T, m: M): T
81+ */
82+public func testMultiGenericT < T, M >(t: T, m: M): T where T <: JSInteropType<T>, M <: JSInteropType<M> {
83+ hmsGlobalApiCall < T >( "_ark_interop_api", "testMultiGenericT", { ctx =>[t.toJSValue(ctx), m.toJSValue(ctx)] }) { ctx, info => T.fromJSValue(ctx, info) }
84+}
84```85```
85 86 
86### Global Variables87### Global Variables
@@ -100,11 +101,11 @@ declare let qoo: number;
100Generated Cangjie code:101Generated Cangjie code:
101 102 
102```cangjie103```cangjie
103-public const foo = !!!!!check in dts!!!!!104+public const foo = 0/* FIXME: Initialization is required */
104 105 
105-public const goo = !!!!!check in dts!!!!!106+public const goo = 0/* FIXME: Initialization is required */
106 107 
107-public const qoo = !!!!!check in dts!!!!!108+public const qoo = 0/* FIXME: Initialization is required */
108```109```
109 110 
110### Interfaces111### Interfaces
@@ -127,42 +128,55 @@ interface GreetingSettings {
127Generated Cangjie code:128Generated Cangjie code:
128 129 
129```cangjie130```cangjie
130-public class GreetingSettings {131+/*interface GreetingSettings {
132+ greeting: String;
133+ duration?: number;
134+ color?: String;
135+ }*/
131 136 
132- protected GreetingSettings(public var greeting: String,137+public open class GreetingSettings {
133- public var duration!: Option<Float64> = None,138+ public var greeting: String
134- public var color!: Option<String> = None) {}139+ public var duration: Option<Float64> = None
140+ public var color: Option<String> = None
141+ protected init(
142+ greeting: String,
143+ duration!: Option<Float64> = None,
144+ color!: Option<String> = None) {
145+ this.greeting = greeting
146+ this.duration = duration
147+ this.color = color
148+ }
135 149 
136- 150+ public open func toJSValue(context: JSContext): JSValue {
137- public func toJSValue(context: JSContext): JSValue {
138 let obj = context.object()151 let obj = context.object()
139 obj["greeting"] = greeting.toJSValue(context)152 obj["greeting"] = greeting.toJSValue(context)
140- if(let Some(v) <- duration) {153+ if (let Some(v) <- duration) {
141 obj["duration"] = v.toJSValue(context)154 obj["duration"] = v.toJSValue(context)
142 }155 }
143- if(let Some(v) <- color) {156+ if (let Some(v) <- color) {
144 obj["color"] = v.toJSValue(context)157 obj["color"] = v.toJSValue(context)
145 }158 }
146 obj.toJSValue()159 obj.toJSValue()
147 }160 }
148 161 
149- public static func fromJSValue (context: JSContext, input: JSValue): GreetingSettings {162+ public static func fromJSValue(context: JSContext, input: JSValue): GreetingSettings {
150 let obj = input.asObject()163 let obj = input.asObject()
151 GreetingSettings(164 GreetingSettings(
152 String.fromJSValue(context, obj["greeting"]),165 String.fromJSValue(context, obj["greeting"]),
153- duration: if(obj["duration"].isUndefined()) {166+ duration:
154- None167+ if (obj["duration"].isNull()) {
168+ None < Float64 >
155 } else {169 } else {
156 Float64.fromJSValue(context, obj["duration"])170 Float64.fromJSValue(context, obj["duration"])
157 },171 },
158- color: if(obj["color"].isUndefined()) {172+ color:
159- None173+ if (obj["color"].isNull()) {
174+ None < String >
160 } else {175 } else {
161 String.fromJSValue(context, obj["color"])176 String.fromJSValue(context, obj["color"])
162 }177 }
163 )178 )
164 }179 }
165- 
166}180}
167```181```
168 182 
@@ -180,30 +194,35 @@ interface Product {
180Generated Cangjie code:194Generated Cangjie code:
181 195 
182```cangjie196```cangjie
183-public class Product {197+/*interface Product {
198+ price?: number;
199+ }*/
184 200 
185- protected Product(public var price!: Option<Float64> = None) {}201+public open class Product {
202+ public var price: Option<Float64> = None
203+ protected init(price!: Option<Float64> = None) {
204+ this.price = price
205+ }
186 206 
187- 207+ public open func toJSValue(context: JSContext): JSValue {
188- public func toJSValue(context: JSContext): JSValue {
189 let obj = context.object()208 let obj = context.object()
190- if(let Some(v) <- price) {209+ if (let Some(v) <- price) {
191 obj["price"] = v.toJSValue(context)210 obj["price"] = v.toJSValue(context)
192 }211 }
193 obj.toJSValue()212 obj.toJSValue()
194 }213 }
195 214 
196- public static func fromJSValue (context: JSContext, input: JSValue): Product {215+ public static func fromJSValue(context: JSContext, input: JSValue): Product {
197 let obj = input.asObject()216 let obj = input.asObject()
198 Product(217 Product(
199- price: if(obj["price"].isUndefined()) {218+ price:
200- None219+ if (obj["price"].isNull()) {
220+ None < Float64 >
201 } else {221 } else {
202 Float64.fromJSValue(context, obj["price"])222 Float64.fromJSValue(context, obj["price"])
203 }223 }
204 )224 )
205 }225 }
206- 
207}226}
208```227```
209 228 
@@ -222,27 +241,35 @@ interface Point {
222Generated Cangjie code:241Generated Cangjie code:
223 242 
224```cangjie243```cangjie
225-public class Point {244+/*interface Point {
245+ ReadonlyKeywordx: number;
246+ ReadonlyKeywordy: number;
247+ }*/
226 248 
227- protected Point(public let x: Float64,249+public open class Point {
228- public let y: Float64) {}250+ public let x: Float64
251+ public let y: Float64
252+ protected init(
253+ x: Float64,
254+ y: Float64) {
255+ this.x = x
256+ this.y = y
257+ }
229 258 
230- 259+ public open func toJSValue(context: JSContext): JSValue {
231- public func toJSValue(context: JSContext): JSValue {
232 let obj = context.object()260 let obj = context.object()
233 obj["x"] = x.toJSValue(context)261 obj["x"] = x.toJSValue(context)
234 obj["y"] = y.toJSValue(context)262 obj["y"] = y.toJSValue(context)
235 obj.toJSValue()263 obj.toJSValue()
236 }264 }
237 265 
238- public static func fromJSValue (context: JSContext, input: JSValue): Point {266+ public static func fromJSValue(context: JSContext, input: JSValue): Point {
239 let obj = input.asObject()267 let obj = input.asObject()
240 Point(268 Point(
241 Float64.fromJSValue(context, obj["x"]),269 Float64.fromJSValue(context, obj["x"]),
242 Float64.fromJSValue(context, obj["y"])270 Float64.fromJSValue(context, obj["y"])
243 )271 )
244 }272 }
245- 
246}273}
247```274```
248 275 
@@ -274,10 +301,13 @@ interface Person {
274Generated Cangjie code:301Generated Cangjie code:
275 302 
276```cangjie303```cangjie
277-public class Person {304+/*interface Person {
278- 305+ name: String;
279- protected Person(let arkts_object: JSObject) {}306+ greet(): String
307+ }*/
280 308 
309+public open class Person {
310+ protected Person(var arkts_object: JSObject) { }
281 311 
282 public mut prop name: String {312 public mut prop name: String {
283 get() {313 get() {
@@ -294,17 +324,17 @@ public class Person {
294 }324 }
295 325 
296 /**326 /**
297- * @brief greet(): String327+ * @brief greet(): String
298- */328+ */
299 public func greet(): String {329 public func greet(): String {
300- jsObjApiCall < String >( arkts_object, "greet", emptyArg)330+ jsObjApiCall < String >( arkts_object, "greet", EMPTY_ARG)
301 }331 }
302 332 
303- func toJSValue(context: JSContext): JSValue {333+ public open func toJSValue(_: JSContext): JSValue {
304 arkts_object.toJSValue()334 arkts_object.toJSValue()
305 }335 }
306 336 
307- static func fromJSValue (context: JSContext, input: JSValue): Person {337+ public static func fromJSValue(_: JSContext, input: JSValue): Person {
308 Person(input.asObject())338 Person(input.asObject())
309 }339 }
310}340}
@@ -325,29 +355,32 @@ interface Calculator {
325Generated Cangjie code:355Generated Cangjie code:
326 356 
327```cangjie357```cangjie
328-public class Calculator {358+/*interface Calculator {
329- 359+ add(x: number, y: number): number
330- protected Calculator(let arkts_object: JSObject) {}360+ add(x: string, y: string): String
361+ }*/
331 362 
363+public open class Calculator {
364+ protected Calculator(var arkts_object: JSObject) { }
332 365 
333 /**366 /**
334- * @brief add(x: number,y: number): number367+ * @brief add(x: number, y: number): number
335- */368+ */
336 public func add(x: Float64, y: Float64): Float64 {369 public func add(x: Float64, y: Float64): Float64 {
337 jsObjApiCall < Float64 >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })370 jsObjApiCall < Float64 >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })
338 }371 }
339 /**372 /**
340- * @brief add(x: string,y: string): String373+ * @brief add(x: string, y: string): String
341- */374+ */
342 public func add(x: String, y: String): String {375 public func add(x: String, y: String): String {
343 jsObjApiCall < String >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })376 jsObjApiCall < String >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })
344 }377 }
345 378 
346- func toJSValue(context: JSContext): JSValue {379+ public open func toJSValue(_: JSContext): JSValue {
347 arkts_object.toJSValue()380 arkts_object.toJSValue()
348 }381 }
349 382 
350- static func fromJSValue (context: JSContext, input: JSValue): Calculator {383+ public static func fromJSValue(_: JSContext, input: JSValue): Calculator {
351 Calculator(input.asObject())384 Calculator(input.asObject())
352 }385 }
353}386}
@@ -368,37 +401,40 @@ interface List {
368Generated Cangjie code:401Generated Cangjie code:
369 402 
370```cangjie403```cangjie
371-public class List {404+/*interface List {
372- 405+ items: String[];
373- protected List(let arkts_object: JSObject) {}406+ add(item: string): void
407+ }*/
374 408 
409+public open class List {
410+ protected List(var arkts_object: JSObject) { }
375 411 
376 public mut prop items: Array<String> {412 public mut prop items: Array<String> {
377 get() {413 get() {
378 checkThreadAndCall < Array<String> >(getMainContext()) {414 checkThreadAndCall < Array<String> >(getMainContext()) {
379- ctx: JSContext => Array<String>.fromJSValue(ctx, arkts_object["items"])415+ ctx: JSContext => fromJSArray < String >(ctx, arkts_object["items"])
380 }416 }
381 }417 }
382 set(v) {418 set(v) {
383 checkThreadAndCall < Unit >(getMainContext()) {419 checkThreadAndCall < Unit >(getMainContext()) {
384- ctx: JSContext => arkts_object["items"] = v.toJSValue(ctx)420+ ctx: JSContext => arkts_object["items"] = toJSArray < String >(ctx, v)
385 }421 }
386 }422 }
387 423 
388 }424 }
389 425 
390 /**426 /**
391- * @brief add(item: string): void427+ * @brief add(item: string): void
392- */428+ */
393 public func add(item: String): Unit {429 public func add(item: String): Unit {
394 jsObjApiCall < Unit >( arkts_object, "add", { ctx =>[item.toJSValue(ctx)] })430 jsObjApiCall < Unit >( arkts_object, "add", { ctx =>[item.toJSValue(ctx)] })
395 }431 }
396 432 
397- func toJSValue(context: JSContext): JSValue {433+ public open func toJSValue(_: JSContext): JSValue {
398 arkts_object.toJSValue()434 arkts_object.toJSValue()
399 }435 }
400 436 
401- static func fromJSValue (context: JSContext, input: JSValue): List {437+ public static func fromJSValue(_: JSContext, input: JSValue): List {
402 List(input.asObject())438 List(input.asObject())
403 }439 }
404}440}
@@ -435,24 +471,28 @@ interface F extends C {
435Generated Cangjie code:471Generated Cangjie code:
436 472 
437```cangjie473```cangjie
474+/*interface A {
475+ p: number;
476+ }*/
477+ 
438public open class A {478public open class A {
439- 479+ public var p: Float64
440- protected A(public var p: Float64) {}480+ protected init(p: Float64) {
441- 481+ this.p = p
442- 482+ }
483+ 
443 public open func toJSValue(context: JSContext): JSValue {484 public open func toJSValue(context: JSContext): JSValue {
444 let obj = context.object()485 let obj = context.object()
445 obj["p"] = p.toJSValue(context)486 obj["p"] = p.toJSValue(context)
446 obj.toJSValue()487 obj.toJSValue()
447 }488 }
448- 489+ 
449 public static func fromJSValue(context: JSContext, input: JSValue): A {490 public static func fromJSValue(context: JSContext, input: JSValue): A {
450 let obj = input.asObject()491 let obj = input.asObject()
451 A(492 A(
452 Float64.fromJSValue(context, obj["p"])493 Float64.fromJSValue(context, obj["p"])
453 )494 )
454 }495 }
455-
456}496}
457 497 
458/*interface B {498/*interface B {
@@ -460,18 +500,20 @@ public open class A {
460 }*/500 }*/
461 501 
462public open class B <: A {502public open class B <: A {
463- 503+ public var p1: Float64
464- protected B(p: Float64,504+ protected init(p: Float64,
465- public var p1: Float64) { super(p) }505+ p1: Float64) {
466- 506+ super( p )
467- 507+ this.p1 = p1
508+ }
509+ 
468 public open func toJSValue(context: JSContext): JSValue {510 public open func toJSValue(context: JSContext): JSValue {
469 let obj = context.object()511 let obj = context.object()
470 obj["p"] = p.toJSValue(context)512 obj["p"] = p.toJSValue(context)
471 obj["p1"] = p1.toJSValue(context)513 obj["p1"] = p1.toJSValue(context)
472 obj.toJSValue()514 obj.toJSValue()
473 }515 }
474- 516+ 
475 public static func fromJSValue(context: JSContext, input: JSValue): B {517 public static func fromJSValue(context: JSContext, input: JSValue): B {
476 let obj = input.asObject()518 let obj = input.asObject()
477 B(519 B(
@@ -479,7 +521,6 @@ public open class B <: A {
479 Float64.fromJSValue(context, obj["p1"])521 Float64.fromJSValue(context, obj["p1"])
480 )522 )
481 }523 }
482-
483}524}
484 525 
485/*interface C {526/*interface C {
@@ -487,22 +528,20 @@ public open class B <: A {
487 }*/528 }*/
488 529 
489public open class C {530public open class C {
490- 531+ protected C(var arkts_object: JSObject) { }
491- protected C(public var arkts_object: JSObject) {}532+ 
492-
493-
494 /**533 /**
495 * @brief f(): void534 * @brief f(): void
496 */535 */
497 public func f(): Unit {536 public func f(): Unit {
498- jsObjApiCall < Unit >( arkts_object, "f", emptyArg)537+ jsObjApiCall < Unit >( arkts_object, "f", EMPTY_ARG)
499 }538 }
500- 539+ 
501- public open func toJSValue(context: JSContext): JSValue {540+ public open func toJSValue(_: JSContext): JSValue {
502 arkts_object.toJSValue()541 arkts_object.toJSValue()
503 }542 }
504- 543+ 
505- static func fromJSValue(context: JSContext, input: JSValue): C {544+ public static func fromJSValue(_: JSContext, input: JSValue): C {
506 C(input.asObject())545 C(input.asObject())
507 }546 }
508}547}
@@ -511,16 +550,13 @@ public open class C {
511 }*/550 }*/
512 551 
513public open class D <: C {552public open class D <: C {
514-
515 protected D(arkts_object: JSObject) { super(arkts_object) }553 protected D(arkts_object: JSObject) { super(arkts_object) }
516- 554+ 
517- 555+ public open func toJSValue(_: JSContext): JSValue {
518-
519- public open func toJSValue(context: JSContext): JSValue {
520 arkts_object.toJSValue()556 arkts_object.toJSValue()
521 }557 }
522- 558+ 
523- static func fromJSValue(context: JSContext, input: JSValue): D {559+ public static func fromJSValue(_: JSContext, input: JSValue): D {
524 D(input.asObject())560 D(input.asObject())
525 }561 }
526}562}
@@ -529,23 +565,22 @@ public open class D <: C {
529 }*/565 }*/
530 566 
531public open class E <: A {567public open class E <: A {
532- 568+ protected init(p: Float64) {
533- protected E(p: Float64) { super(p) }569+ super( p )
534- 570+ }
535- 571+ 
536 public open func toJSValue(context: JSContext): JSValue {572 public open func toJSValue(context: JSContext): JSValue {
537 let obj = context.object()573 let obj = context.object()
538 obj["p"] = p.toJSValue(context)574 obj["p"] = p.toJSValue(context)
539 obj.toJSValue()575 obj.toJSValue()
540 }576 }
541- 577+ 
542 public static func fromJSValue(context: JSContext, input: JSValue): E {578 public static func fromJSValue(context: JSContext, input: JSValue): E {
543 let obj = input.asObject()579 let obj = input.asObject()
544 E(580 E(
545 Float64.fromJSValue(context, obj["p"])581 Float64.fromJSValue(context, obj["p"])
546 )582 )
547 }583 }
548-
549}584}
550 585 
551/*interface F {586/*interface F {
@@ -553,22 +588,20 @@ public open class E <: A {
553 }*/588 }*/
554 589 
555public open class F <: C {590public open class F <: C {
556-
557 protected F(arkts_object: JSObject) { super(arkts_object) }591 protected F(arkts_object: JSObject) { super(arkts_object) }
558- 592+ 
559-
560 /**593 /**
561 * @brief g(): void594 * @brief g(): void
562 */595 */
563 public func g(): Unit {596 public func g(): Unit {
564- jsObjApiCall < Unit >( arkts_object, "g", emptyArg)597+ jsObjApiCall < Unit >( arkts_object, "g", EMPTY_ARG)
565 }598 }
566- 599+ 
567- public open func toJSValue(context: JSContext): JSValue {600+ public open func toJSValue(_: JSContext): JSValue {
568 arkts_object.toJSValue()601 arkts_object.toJSValue()
569 }602 }
570- 603+ 
571- static func fromJSValue(context: JSContext, input: JSValue): F {604+ public static func fromJSValue(_: JSContext, input: JSValue): F {
572 F(input.asObject())605 F(input.asObject())
573 }606 }
574}607}
@@ -593,20 +626,28 @@ interface UserProfile {
593Generated Cangjie code:626Generated Cangjie code:
594 627 
595```cangjie628```cangjie
629+/*interface AutoGenType0 {
630+ city: string;
631+ zipCode: string;
632+ }*/
596 633 
597public open class AutoGenType0 {634public open class AutoGenType0 {
598- 635+ public var city: String
599- protected AutoGenType0(public var : String,636+ public var zipCode: String
600- public var : String) {}637+ protected init(
601- 638+ city: String,
602- 639+ zipCode: String) {
640+ this.city = city
641+ this.zipCode = zipCode
642+ }
643+ 
603 public open func toJSValue(context: JSContext): JSValue {644 public open func toJSValue(context: JSContext): JSValue {
604 let obj = context.object()645 let obj = context.object()
605- obj["city"] = .toJSValue(context)646+ obj["city"] = city.toJSValue(context)
606- obj["zipCode"] = .toJSValue(context)647+ obj["zipCode"] = zipCode.toJSValue(context)
607 obj.toJSValue()648 obj.toJSValue()
608 }649 }
609- 650+ 
610 public static func fromJSValue(context: JSContext, input: JSValue): AutoGenType0 {651 public static func fromJSValue(context: JSContext, input: JSValue): AutoGenType0 {
611 let obj = input.asObject()652 let obj = input.asObject()
612 AutoGenType0(653 AutoGenType0(
@@ -614,17 +655,30 @@ public open class AutoGenType0 {
614 String.fromJSValue(context, obj["zipCode"])655 String.fromJSValue(context, obj["zipCode"])
615 )656 )
616 }657 }
617-
618}658}
619 659 
660+/*interface UserProfile {
661+ id: number;
662+ name: String;
663+ address: {
664+ city: String;
665+ zipCode: String;
666+ };
667+ }*/
620 668 
621public open class UserProfile {669public open class UserProfile {
622- 670+ public var id: Float64
623- protected UserProfile(public var id: Float64,671+ public var name: String
624- public var name: String,672+ public var address: AutoGenType0
625- public var address: AutoGenType0) {}673+ protected init(
626- 674+ id: Float64,
627- 675+ name: String,
676+ address: AutoGenType0) {
677+ this.id = id
678+ this.name = name
679+ this.address = address
680+ }
681+ 
628 public open func toJSValue(context: JSContext): JSValue {682 public open func toJSValue(context: JSContext): JSValue {
629 let obj = context.object()683 let obj = context.object()
630 obj["id"] = id.toJSValue(context)684 obj["id"] = id.toJSValue(context)
@@ -632,7 +686,7 @@ public open class UserProfile {
632 obj["address"] = address.toJSValue(context)686 obj["address"] = address.toJSValue(context)
633 obj.toJSValue()687 obj.toJSValue()
634 }688 }
635- 689+ 
636 public static func fromJSValue(context: JSContext, input: JSValue): UserProfile {690 public static func fromJSValue(context: JSContext, input: JSValue): UserProfile {
637 let obj = input.asObject()691 let obj = input.asObject()
638 UserProfile(692 UserProfile(
@@ -641,7 +695,6 @@ public open class UserProfile {
641 AutoGenType0.fromJSValue(context, obj["address"])695 AutoGenType0.fromJSValue(context, obj["address"])
642 )696 )
643 }697 }
644-
645}698}
646```699```
647 700 
@@ -729,6 +782,60 @@ Generated Cangjie code:
729 782 
730```cangjie783```cangjie
731public type ColorAlias = Colors784public type ColorAlias = Colors
785+ 
786+/***********ENUM***********/
787+ 
788+/* enum Colors {
789+ Red = RED,
790+ Green = GREEN,
791+ Blue = BLUE
792+ }*/
793+public enum Colors <: ToString & Equatable < Colors > {
794+ | Red
795+ | Green
796+ | Blue
797+ 
798+ func get(): String {
799+ match(this) {
800+ case Red => "RED"
801+ case Green => "GREEN"
802+ case Blue => "BLUE"
803+ }
804+ }
805+ 
806+ static func parse(val: String): Colors {
807+ match(val) {
808+ case "RED" => Red
809+ case "GREEN" => Green
810+ case "BLUE" => Blue
811+ case _ => throw IllegalArgumentException("unknown value ${val}")
812+ }
813+ }
814+ 
815+ static func tryParse(val: ?String): ?Colors {
816+ match(val) {
817+ case Some(v) => parse(v)
818+ case None => None
819+ }
820+ }
821+ 
822+ public func toString(): String {
823+ get()
824+ }
825+ 
826+ public override operator func ==(that: Colors): Bool {
827+ match((this, that)) {
828+ case(Red, Red) => true
829+ case(Green, Green) => true
830+ case(Blue, Blue) => true
831+ case _ => false
832+ }
833+ }
834+ 
835+ public override operator func !=(that: Colors): Bool {
836+ !(this == that)
837+ }
838+}
732```839```
733 840 
734#### Class Type Aliases841#### Class Type Aliases
@@ -749,6 +856,55 @@ Generated Cangjie code:
749 856 
750```cangjie857```cangjie
751public type AnimalAlias = Animal858public type AnimalAlias = Animal
859+ 
860+/*class DeclareKeyword Animal {
861+ name: String;
862+ constructor(name: string): void
863+ speak(): void
864+ }*/
865+ 
866+public class Animal {
867+ protected Animal(var arkts_object: JSObject) { }
868+ /**
869+ * @brief constructor(name: string): void
870+ */
871+ public init(name: String) {
872+ arkts_object = checkThreadAndCall < JSObject >(getMainContext()) {
873+ ctx =>
874+ let clazz = getClassConstructorObj("doc_dts_examples_ex_12_Animal", "Animal").toJSValue().asClass()
875+ clazz.new(name.toJSValue(ctx)).asObject()
876+ }
877+ }
878+ 
879+ public mut prop name: String {
880+ get() {
881+ checkThreadAndCall < String >(getMainContext()) {
882+ ctx: JSContext => String.fromJSValue(ctx, arkts_object["name"])
883+ }
884+ }
885+ set(v) {
886+ checkThreadAndCall < Unit >(getMainContext()) {
887+ ctx: JSContext => arkts_object["name"] = v.toJSValue(ctx)
888+ }
889+ }
890+ 
891+ }
892+ 
893+ /**
894+ * @brief speak(): void
895+ */
896+ public func speak(): Unit {
897+ jsObjApiCall < Unit >( arkts_object, "speak", EMPTY_ARG)
898+ }
899+ 
900+ func toJSValue(_: JSContext): JSValue {
901+ arkts_object.toJSValue()
902+ }
903+ 
904+ static func fromJSValue(_: JSContext, input: JSValue): Animal {
905+ Animal(input.asObject())
906+ }
907+}
752```908```
753 909 
754#### Type Aliases for Types Within Namespaces910#### Type Aliases for Types Within Namespaces
@@ -778,7 +934,7 @@ type MathOperation = (a: number, b: number) => number;
778Generated Cangjie code:934Generated Cangjie code:
779 935 
780```cangjie936```cangjie
781-public type MathOperation = (a: Float64, b: Float64) -> Float64937+public type MathOperation = (Float64, Float64) -> Float64
782```938```
783 939 
784#### Union Type Aliases940#### Union Type Aliases
@@ -802,6 +958,16 @@ public enum GreetingLike {
802 case NUMBER(x) => context.number(x).toJSValue()958 case NUMBER(x) => context.number(x).toJSValue()
803 }959 }
804 }960 }
961+ public static func fromJSValue(context: JSContext, input: JSValue): GreetingLike {
962+ 
963+ if (input.isString()) {
964+ return STRING(String.fromJSValue(context, input))
965+ }
966+ if (input.isNumber()) {
967+ return NUMBER(Float64.fromJSValue(context, input))
968+ }
969+ throw Exception("unsupport type!")
970+ }
805}971}
806```972```
807 973 
@@ -853,17 +1019,22 @@ declare class Greeter {
853Generated Cangjie code:1019Generated Cangjie code:
854 1020 
855```cangjie1021```cangjie
856-public class Greeter {1022+/*class DeclareKeyword Greeter {
1023+ greeting: String;
1024+ constructor(greeting: string): void
1025+ showGreeting(): void
1026+ }*/
857 1027 
858- protected Greeter(let arkts_object: JSObject) {}1028+public class Greeter {
1029+ protected Greeter(var arkts_object: JSObject) { }
859 /**1030 /**
860- * @brief constructor(greeting: string): void1031+ * @brief constructor(greeting: string): void
861- */1032+ */
862 public init(greeting: String) {1033 public init(greeting: String) {
863 arkts_object = checkThreadAndCall < JSObject >(getMainContext()) {1034 arkts_object = checkThreadAndCall < JSObject >(getMainContext()) {
864- __ctx =>1035+ ctx =>
865- let clazz = __ctx.global["Greeter"].asClass(__ctx)1036+ let clazz = getClassConstructorObj("_ark_interop_api", "Greeter").toJSValue().asClass()
866- clazz.new(greeting.toJSValue(__ctx)).asObject()1037+ clazz.new(greeting.toJSValue(ctx)).asObject()
867 }1038 }
868 }1039 }
869 1040 
@@ -882,22 +1053,20 @@ public class Greeter {
882 }1053 }
883 1054 
884 /**1055 /**
885- * @brief showGreeting(): void1056+ * @brief showGreeting(): void
886- */1057+ */
887 public func showGreeting(): Unit {1058 public func showGreeting(): Unit {
888- jsObjApiCall < Unit >( arkts_object, "showGreeting", emptyArg)1059+ jsObjApiCall < Unit >( arkts_object, "showGreeting", EMPTY_ARG)
889 }1060 }
890 1061 
891- func toJSValue(context: JSContext): JSValue {1062+ func toJSValue(_: JSContext): JSValue {
892 arkts_object.toJSValue()1063 arkts_object.toJSValue()
893 }1064 }
894 1065 
895- static func fromJSValue (context: JSContext, input: JSValue): Greeter {1066+ static func fromJSValue(_: JSContext, input: JSValue): Greeter {
896 Greeter(input.asObject())1067 Greeter(input.asObject())
897 }1068 }
898}1069}
899- 
900- 
901```1070```
902 1071 
903#### Static Members1072#### Static Members
@@ -917,37 +1086,40 @@ declare class MathUtils {
917Generated Cangjie code:1086Generated Cangjie code:
918 1087 
919```cangjie1088```cangjie
1089+/*class DeclareKeyword MathUtils {
1090+ StaticKeywordPI: number;
1091+ square(x: number): number
1092+ }*/
1093+ 
920public class MathUtils {1094public class MathUtils {
1095+ protected MathUtils(var arkts_object: JSObject) { }
921 1096 
922- protected MathUtils(let arkts_object: JSObject) {}1097+ public static mut prop PI: Float64 {
923- 
924- // Static property
925- public mut prop PI: Float64 {
926 get() {1098 get() {
927 checkThreadAndCall < Float64 >(getMainContext()) {1099 checkThreadAndCall < Float64 >(getMainContext()) {
928- ctx: JSContext => Float64.fromJSValue(ctx, getClassConstructorObj("test", "MathUtils")["PI"])1100+ ctx: JSContext => Float64.fromJSValue(ctx, getClassConstructorObj("_ark_interop_api", "MathUtils")["PI"])
929 }1101 }
930 }1102 }
931 set(v) {1103 set(v) {
932 checkThreadAndCall < Unit >(getMainContext()) {1104 checkThreadAndCall < Unit >(getMainContext()) {
933- ctx: JSContext => getClassConstructorObj("test", "MathUtils")["PI"] = v.toJSValue(ctx)1105+ ctx: JSContext => getClassConstructorObj("_ark_interop_api", "MathUtils")["PI"] = v.toJSValue(ctx)
934 }1106 }
935 }1107 }
936 1108 
937 }1109 }
938 1110 
939 /**1111 /**
940- * @brief square(x: number): number1112+ * @brief square(x: number): number
941- */1113+ */
942 public static func square(x: Float64): Float64 {1114 public static func square(x: Float64): Float64 {
943- jsObjApiCall < Float64 >(getClassConstructorObj("test", "MathUtils"), "square", { ctx =>[x.toJSValue(ctx)] })1115+ jsObjApiCall < Float64 >(getClassConstructorObj("_ark_interop_api", "MathUtils"), "square", { ctx =>[x.toJSValue(ctx)] })
944 }1116 }
945 1117 
946- func toJSValue(context: JSContext): JSValue {1118+ func toJSValue(_: JSContext): JSValue {
947 arkts_object.toJSValue()1119 arkts_object.toJSValue()
948 }1120 }
949 1121 
950- static func fromJSValue (context: JSContext, input: JSValue): MathUtils {1122+ static func fromJSValue(_: JSContext, input: JSValue): MathUtils {
951 MathUtils(input.asObject())1123 MathUtils(input.asObject())
952 }1124 }
953}1125}
@@ -968,15 +1140,17 @@ declare class Person {
968Generated Cangjie code:1140Generated Cangjie code:
969 1141 
970```cangjie1142```cangjie
971-public class Person {1143+/*class DeclareKeyword Person {
972- // No need to generate private member properties1144+ }*/
973- protected Person(let arkts_object: JSObject) {}
974 1145 
975- func toJSValue(context: JSContext): JSValue {1146+public class Person {
1147+ protected Person(var arkts_object: JSObject) { }
1148+ 
1149+ func toJSValue(_: JSContext): JSValue {
976 arkts_object.toJSValue()1150 arkts_object.toJSValue()
977 }1151 }
978 1152 
979- static func fromJSValue (context: JSContext, input: JSValue): Person {1153+ static func fromJSValue(_: JSContext, input: JSValue): Person {
980 Person(input.asObject())1154 Person(input.asObject())
981 }1155 }
982}1156}
@@ -999,11 +1173,14 @@ declare class AnimalProtect {
999Generated Cangjie code:1173Generated Cangjie code:
1000 1174 
1001```cangjie1175```cangjie
1176+/*class DeclareKeyword AnimalProtect {
1177+ ProtectedKeywordname: String;
1178+ makeSound(): void
1179+ }*/
1180+ 
1002public class AnimalProtect {1181public class AnimalProtect {
1182+ protected AnimalProtect(var arkts_object: JSObject) { }
1003 1183 
1004- protected AnimalProtect(let arkts_object: JSObject) {}
1005- 
1006- // Protected property
1007 public mut prop name: String {1184 public mut prop name: String {
1008 get() {1185 get() {
1009 checkThreadAndCall < String >(getMainContext()) {1186 checkThreadAndCall < String >(getMainContext()) {
@@ -1019,17 +1196,17 @@ public class AnimalProtect {
1019 }1196 }
1020 1197 
1021 /**1198 /**
1022- * @brief makeSound(): void1199+ * @brief makeSound(): void
1023- */1200+ */
1024 public func makeSound(): Unit {1201 public func makeSound(): Unit {
1025- jsObjApiCall < Unit >( arkts_object, "makeSound", emptyArg)1202+ jsObjApiCall < Unit >( arkts_object, "makeSound", EMPTY_ARG)
1026 }1203 }
1027 1204 
1028- func toJSValue(context: JSContext): JSValue {1205+ func toJSValue(_: JSContext): JSValue {
1029 arkts_object.toJSValue()1206 arkts_object.toJSValue()
1030 }1207 }
1031 1208 
1032- static func fromJSValue (context: JSContext, input: JSValue): AnimalProtect {1209+ static func fromJSValue(_: JSContext, input: JSValue): AnimalProtect {
1033 AnimalProtect(input.asObject())1210 AnimalProtect(input.asObject())
1034 }1211 }
1035}1212}
@@ -1050,11 +1227,14 @@ declare class Car {
1050Generated Cangjie code:1227Generated Cangjie code:
1051 1228 
1052```cangjie1229```cangjie
1230+/*class DeclareKeyword Car {
1231+ ReadonlyKeywordbrand: String;
1232+ name: String;
1233+ }*/
1234+ 
1053public class Car {1235public class Car {
1236+ protected Car(var arkts_object: JSObject) { }
1054 1237 
1055- protected Car(let arkts_object: JSObject) {}
1056- 
1057- // Readonly property
1058 public prop brand: String {1238 public prop brand: String {
1059 get() {1239 get() {
1060 checkThreadAndCall < String >(getMainContext()) {1240 checkThreadAndCall < String >(getMainContext()) {
@@ -1077,12 +1257,11 @@ public class Car {
1077 1257 
1078 }1258 }
1079 1259 
1080- 1260+ func toJSValue(_: JSContext): JSValue {
1081- func toJSValue(context: JSContext): JSValue {
1082 arkts_object.toJSValue()1261 arkts_object.toJSValue()
1083 }1262 }
1084 1263 
1085- static func fromJSValue (context: JSContext, input: JSValue): Car {1264+ static func fromJSValue(_: JSContext, input: JSValue): Car {
1086 Car(input.asObject())1265 Car(input.asObject())
1087 }1266 }
1088}1267}
@@ -1104,11 +1283,14 @@ declare class Box<T> {
1104Generated Cangjie code:1283Generated Cangjie code:
1105 1284 
1106```cangjie1285```cangjie
1107-public class Box<T> {1286+/*class DeclareKeyword Box {
1287+ value: T;
1288+ getValue(): T
1289+ }*/
1108 1290 
1109- protected Box(let arkts_object: JSObject) {}1291+public class Box<T> where T <: JSInteropType<T> {
1292+ protected Box(var arkts_object: JSObject) { }
1110 1293 
1111- // Property
1112 public mut prop value: T {1294 public mut prop value: T {
1113 get() {1295 get() {
1114 checkThreadAndCall < T >(getMainContext()) {1296 checkThreadAndCall < T >(getMainContext()) {
@@ -1124,19 +1306,17 @@ public class Box<T> {
1124 }1306 }
1125 1307 
1126 /**1308 /**
1127- * @brief getValue(): T1309+ * @brief getValue(): T
1128- */1310+ */
1129 public func getValue(): T {1311 public func getValue(): T {
1130- jsObjApiCall < T >( arkts_object, "getValue", emptyArg) {1312+ jsObjApiCall < T >( arkts_object, "getValue", EMPTY_ARG) { ctx, info => T.fromJSValue(ctx, info) }
1131- ctx, info => T.fromJSValue(ctx, info)
1132- }
1133 }1313 }
1134 1314 
1135- func toJSValue(context: JSContext): JSValue {1315+ func toJSValue(_: JSContext): JSValue {
1136 arkts_object.toJSValue()1316 arkts_object.toJSValue()
1137 }1317 }
1138 1318 
1139- static func fromJSValue <T>(context: JSContext, input: JSValue): Box<T> {1319+ static func fromJSValue(_: JSContext, input: JSValue): Box<T> {
1140 Box(input.asObject())1320 Box(input.asObject())
1141 }1321 }
1142}1322}
@@ -1156,22 +1336,25 @@ declare abstract class Shape {
1156Generated Cangjie code:1336Generated Cangjie code:
1157 1337 
1158```cangjie1338```cangjie
1159-public open class Shape {1339+/*class DeclareKeyword FirstContextualKeyword Shape {
1340+ getArea(): number
1341+ }*/
1160 1342 
1161- protected Shape(let arkts_object: JSObject) {}1343+public open class Shape {
1344+ protected Shape(var arkts_object: JSObject) { }
1162 1345 
1163 /**1346 /**
1164- * @brief getArea(): number1347+ * @brief getArea(): number
1165- */1348+ */
1166 public func getArea(): Float64 {1349 public func getArea(): Float64 {
1167- jsObjApiCall < Float64 >( arkts_object, "getArea", emptyArg)1350+ jsObjApiCall < Float64 >( arkts_object, "getArea", EMPTY_ARG)
1168 }1351 }
1169 1352 
1170- func toJSValue(context: JSContext): JSValue {1353+ public open func toJSValue(_: JSContext): JSValue {
1171 arkts_object.toJSValue()1354 arkts_object.toJSValue()
1172 }1355 }
1173 1356 
1174- static func fromJSValue (context: JSContext, input: JSValue): Shape {1357+ public static func fromJSValue(_: JSContext, input: JSValue): Shape {
1175 Shape(input.asObject())1358 Shape(input.asObject())
1176 }1359 }
1177}1360}
@@ -1196,56 +1379,50 @@ declare class Car implements Drivable {
1196Generated Cangjie code:1379Generated Cangjie code:
1197 1380 
1198```cangjie1381```cangjie
1199-public class Drivable {1382+/*interface Drivable {
1200- 1383+ start(): void
1201- protected Drivable(let arkts_object: JSObject) {}1384+ stop(): void
1385+ }*/
1202 1386 
1387+public open class Drivable {
1388+ protected Drivable(var arkts_object: JSObject) { }
1203 1389 
1204 /**1390 /**
1205- * @brief start(): void1391+ * @brief start(): void
1206- */1392+ */
1207 public func start(): Unit {1393 public func start(): Unit {
1208- jsObjApiCall < Unit >( arkts_object, "start", emptyArg)1394+ jsObjApiCall < Unit >( arkts_object, "start", EMPTY_ARG)
1209 }1395 }
1210 /**1396 /**
1211- * @brief stop(): void1397+ * @brief stop(): void
1212- */1398+ */
1213 public func stop(): Unit {1399 public func stop(): Unit {
1214- jsObjApiCall < Unit >( arkts_object, "stop", emptyArg)1400+ jsObjApiCall < Unit >( arkts_object, "stop", EMPTY_ARG)
1215 }1401 }
1216 1402 
1217- func toJSValue(context: JSContext): JSValue {1403+ public open func toJSValue(_: JSContext): JSValue {
1218 arkts_object.toJSValue()1404 arkts_object.toJSValue()
1219 }1405 }
1220 1406 
1221- static func fromJSValue (context: JSContext, input: JSValue): Drivable {1407+ public static func fromJSValue(_: JSContext, input: JSValue): Drivable {
1222 Drivable(input.asObject())1408 Drivable(input.asObject())
1223 }1409 }
1224}1410}
1225-public class Car1 <: Drivable {
1226 1411 
1227- protected Car1(arkts_object: JSObject) {}1412+/*class DeclareKeyword Car {
1413+ start(): void
1414+ stop(): void
1415+ }*/
1228 1416 
1417+public class Car <: Drivable {
1418+ protected Car(arkts_object: JSObject) { super(arkts_object) }
1229 1419 
1230- /**1420+ public func toJSValue(_: JSContext): JSValue {
1231- * @brief start(): void
1232- */
1233- public func start(): Unit {
1234- jsObjApiCall < Unit >( arkts_object, "start", emptyArg)
1235- }
1236- /**
1237- * @brief stop(): void
1238- */
1239- public func stop(): Unit {
1240- jsObjApiCall < Unit >( arkts_object, "stop", emptyArg)
1241- }
1242- 
1243- func toJSValue(context: JSContext): JSValue {
1244 arkts_object.toJSValue()1421 arkts_object.toJSValue()
1245 }1422 }
1246 1423 
1247- static func fromJSValue (context: JSContext, input: JSValue): Car1 {1424+ public static func fromJSValue(_: JSContext, input: JSValue): Car {
1248- Car1(input.asObject())1425+ Car(input.asObject())
1249 }1426 }
1250}1427}
1251```1428```
@@ -1271,18 +1448,22 @@ declare class Dog extends Animal {
1271Generated Cangjie code:1448Generated Cangjie code:
1272 1449 
1273```cangjie1450```cangjie
1274-public class Animal1 {1451+/*class DeclareKeyword Animal {
1452+ name: String;
1453+ constructor(name: string): void
1454+ move(distance: number): void
1455+ }*/
1275 1456 
1276- protected Animal1(let arkts_object: JSObject) {}1457+public open class Animal {
1458+ protected Animal(var arkts_object: JSObject) { }
1277 /**1459 /**
1278- * @brief constructor(name: string): void1460+ * @brief constructor(name: string): void
1279- */1461+ */
1280 public init(name: String) {1462 public init(name: String) {
1281 arkts_object = checkThreadAndCall < JSObject >(getMainContext()) {1463 arkts_object = checkThreadAndCall < JSObject >(getMainContext()) {
1282- __ctx =>1464+ ctx =>
1283- let module = getJSModule(__ctx, "test", None)1465+ let clazz = getClassConstructorObj("_ark_interop_api", "Animal").toJSValue().asClass()
1284- let clazz = module["Animal1"].asClass(__ctx)1466+ clazz.new(name.toJSValue(ctx)).asObject()
1285- clazz.new(name.toJSValue(__ctx)).asObject()
1286 }1467 }
1287 }1468 }
1288 1469 
@@ -1301,37 +1482,40 @@ public class Animal1 {
1301 }1482 }
1302 1483 
1303 /**1484 /**
1304- * @brief move(distance: number): void1485+ * @brief move(distance: number): void
1305- */1486+ */
1306 public func move(distance: Float64): Unit {1487 public func move(distance: Float64): Unit {
1307 jsObjApiCall < Unit >( arkts_object, "move", { ctx =>[distance.toJSValue(ctx)] })1488 jsObjApiCall < Unit >( arkts_object, "move", { ctx =>[distance.toJSValue(ctx)] })
1308 }1489 }
1309 1490 
1310- func toJSValue(context: JSContext): JSValue {1491+ public open func toJSValue(_: JSContext): JSValue {
1311 arkts_object.toJSValue()1492 arkts_object.toJSValue()
1312 }1493 }
1313 1494 
1314- static func fromJSValue (context: JSContext, input: JSValue): Animal1 {1495+ public static func fromJSValue(_: JSContext, input: JSValue): Animal {
1315- Animal1(input.asObject())1496+ Animal(input.asObject())
1316 }1497 }
1317}1498}
1318-public class Dog <: Animal1 {
1319 1499 
1320- protected Dog(arkts_object: JSObject) {}1500+/*class DeclareKeyword Dog {
1501+ bark(): void
1502+ }*/
1321 1503 
1504+public class Dog <: Animal {
1505+ protected Dog(arkts_object: JSObject) { super(arkts_object) }
1322 1506 
1323 /**1507 /**
1324- * @brief bark(): void1508+ * @brief bark(): void
1325- */1509+ */
1326 public func bark(): Unit {1510 public func bark(): Unit {
1327- jsObjApiCall < Unit >( arkts_object, "bark", emptyArg)1511+ jsObjApiCall < Unit >( arkts_object, "bark", EMPTY_ARG)
1328 }1512 }
1329 1513 
1330- func toJSValue(context: JSContext): JSValue {1514+ public func toJSValue(_: JSContext): JSValue {
1331 arkts_object.toJSValue()1515 arkts_object.toJSValue()
1332 }1516 }
1333 1517 
1334- static func fromJSValue (context: JSContext, input: JSValue): Dog {1518+ public static func fromJSValue(_: JSContext, input: JSValue): Dog {
1335 Dog(input.asObject())1519 Dog(input.asObject())
1336 }1520 }
1337}1521}
@@ -1355,37 +1539,39 @@ declare class Calculator {
1355Generated Cangjie code:1539Generated Cangjie code:
1356 1540 
1357```cangjie1541```cangjie
1542+/*class DeclareKeyword Calculator {
1543+ add(x: number, y: number): number
1544+ add(x: string, y: string): String
1545+ add(x: any, y: any): any
1546+ }*/
1547+ 
1358public class Calculator {1548public class Calculator {
1359- 1549+ protected Calculator(var arkts_object: JSObject) { }
1360- protected Calculator(let arkts_object: JSObject) {}
1361- 
1362 1550 
1363 /**1551 /**
1364- * @brief add(x: number,y: number): number1552+ * @brief add(x: number, y: number): number
1365- */1553+ */
1366 public func add(x: Float64, y: Float64): Float64 {1554 public func add(x: Float64, y: Float64): Float64 {
1367 jsObjApiCall < Float64 >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })1555 jsObjApiCall < Float64 >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })
1368 }1556 }
1369 /**1557 /**
1370- * @brief add(x: string,y: string): String1558+ * @brief add(x: string, y: string): String
1371- */1559+ */
1372 public func add(x: String, y: String): String {1560 public func add(x: String, y: String): String {
1373 jsObjApiCall < String >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })1561 jsObjApiCall < String >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })
1374 }1562 }
1375 /**1563 /**
1376- * @brief add(x: any,y: any): any1564+ * @brief add(x: any, y: any): any
1377- */1565+ */
1378- public func add(x: Any, y: Any): any {1566+ public func add(x: JSValue/* FIXME: `any` */, y: JSValue/* FIXME: `any` */): JSValue/* FIXME: `any` */ {
1379- jsObjApiCall < any >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] }) {1567+ jsObjApiCall < JSValue/* FIXME: `any` */ >( arkts_object, "add", { ctx =>[x, y] }) { ctx, info => info }
1380- ctx, info => any.fromJSValue(ctx, info)
1381- }
1382 }1568 }
1383 1569 
1384- func toJSValue(context: JSContext): JSValue {1570+ func toJSValue(_: JSContext): JSValue {
1385 arkts_object.toJSValue()1571 arkts_object.toJSValue()
1386 }1572 }
1387 1573 
1388- static func fromJSValue (context: JSContext, input: JSValue): Calculator {1574+ static func fromJSValue(_: JSContext, input: JSValue): Calculator {
1389 Calculator(input.asObject())1575 Calculator(input.asObject())
1390 }1576 }
1391}1577}
@@ -1446,6 +1632,13 @@ declare enum Colors {
1446Generated Cangjie code:1632Generated Cangjie code:
1447 1633 
1448```cangjie1634```cangjie
1635+/***********ENUM***********/
1636+ 
1637+/* enum Colors {
1638+ Red = RED,
1639+ Green = GREEN,
1640+ Blue = BLUE
1641+ }*/
1449public enum Colors <: ToString & Equatable < Colors > {1642public enum Colors <: ToString & Equatable < Colors > {
1450 | Red1643 | Red
1451 | Green1644 | Green
@@ -1510,6 +1703,13 @@ declare enum Status {
1510Generated Cangjie code:1703Generated Cangjie code:
1511 1704 
1512```cangjie1705```cangjie
1706+/***********ENUM***********/
1707+ 
1708+/* enum Status {
1709+ Pending,
1710+ Approved,
1711+ Rejected
1712+ }*/
1513public enum Status <: ToString & Equatable < Status > {1713public enum Status <: ToString & Equatable < Status > {
1514 | Pending1714 | Pending
1515 | Approved1715 | Approved
@@ -1578,6 +1778,13 @@ declare const enum Status {
1578Generated Cangjie code:1778Generated Cangjie code:
1579 1779 
1580```cangjie1780```cangjie
1781+/***********ENUM***********/
1782+ 
1783+/* enum Status {
1784+ Pending = 3,
1785+ Approved = 4,
1786+ Rejected = 5
1787+ }*/
1581public enum Status <: ToString & Equatable < Status > {1788public enum Status <: ToString & Equatable < Status > {
1582 | Pending1789 | Pending
1583 | Approved1790 | Approved
@@ -1645,6 +1852,12 @@ declare enum Response {
1645Generated Cangjie code:1852Generated Cangjie code:
1646 1853 
1647```cangjie1854```cangjie
1855+/***********ENUM***********/
1856+ 
1857+/* enum Response {
1858+ No = 0,
1859+ Yes = YES
1860+ }*/
1648public enum Response <: ToString & Equatable < Response > {1861public enum Response <: ToString & Equatable < Response > {
1649 | No1862 | No
1650 | Yes1863 | Yes
@@ -1757,27 +1970,64 @@ interface BasicTypes {
1757Generated Cangjie code:1970Generated Cangjie code:
1758 1971 
1759```cangjie1972```cangjie
1760-public class BasicTypes {
1761 1973 
1762- protected BasicTypes(public var numberKeyword: Float64,1974+/*interface BasicTypes {
1763- public var stringKeyword: String,1975+ numberKeyword: number;
1764- public var booleanKeyword: Bool,1976+ stringKeyword: String;
1765- public var bigintKeyword: BigInt,1977+ booleanKeyword: boolean;
1766- public var objectKeyword: JSValue/* FIXME: `object` */,1978+ bigintKeyword: bigint;
1767- public var symbolKeyword: JSValue/* FIXME: `symbol` */,1979+ objectKeyword: object;
1768- public var voidKeyword: Unit,1980+ symbolKeyword: symbol;
1769- public var undefinedKeyword: JSValue/* FIXME: `undefined` */,1981+ voidKeyword: void;
1770- public var anyKeyword: JSValue/* FIXME: `any` */,1982+ undefinedKeyword: undefined;
1771- public var unknownKeyword: JSValue/* FIXME: `unknown` */,1983+ anyKeyword: any;
1772- public var neverKeyword: JSValue/* FIXME: `never` */) {}1984+ unknownKeyword: unknown;
1985+ neverKeyword: never;
1986+ }*/
1773 1987 
1988+public open class BasicTypes {
1989+ public var numberKeyword: Float64
1990+ public var stringKeyword: String
1991+ public var booleanKeyword: Bool
1992+ public var bigintKeyword: BigInt
1993+ public var objectKeyword: JSValue/* FIXME: `object` */
1994+ public var symbolKeyword: JSValue/* FIXME: `symbol` */
1995+ public var voidKeyword: Unit
1996+ public var undefinedKeyword: JSValue/* FIXME: `undefined` */
1997+ public var anyKeyword: JSValue/* FIXME: `any` */
1998+ public var unknownKeyword: JSValue/* FIXME: `unknown` */
1999+ public var neverKeyword: JSValue/* FIXME: `never` */
2000+ protected init(
2001+ numberKeyword: Float64,
2002+ stringKeyword: String,
2003+ booleanKeyword: Bool,
2004+ bigintKeyword: BigInt,
2005+ objectKeyword: JSValue/* FIXME: `object` */,
2006+ symbolKeyword: JSValue/* FIXME: `symbol` */,
2007+ voidKeyword: Unit,
2008+ undefinedKeyword: JSValue/* FIXME: `undefined` */,
2009+ anyKeyword: JSValue/* FIXME: `any` */,
2010+ unknownKeyword: JSValue/* FIXME: `unknown` */,
2011+ neverKeyword: JSValue/* FIXME: `never` */) {
2012+ this.numberKeyword = numberKeyword
2013+ this.stringKeyword = stringKeyword
2014+ this.booleanKeyword = booleanKeyword
2015+ this.bigintKeyword = bigintKeyword
2016+ this.objectKeyword = objectKeyword
2017+ this.symbolKeyword = symbolKeyword
2018+ this.voidKeyword = voidKeyword
2019+ this.undefinedKeyword = undefinedKeyword
2020+ this.anyKeyword = anyKeyword
2021+ this.unknownKeyword = unknownKeyword
2022+ this.neverKeyword = neverKeyword
2023+ }
1774 2024 
1775- public func toJSValue(context: JSContext): JSValue {2025+ public open func toJSValue(context: JSContext): JSValue {
1776 let obj = context.object()2026 let obj = context.object()
1777 obj["numberKeyword"] = numberKeyword.toJSValue(context)2027 obj["numberKeyword"] = numberKeyword.toJSValue(context)
1778 obj["stringKeyword"] = stringKeyword.toJSValue(context)2028 obj["stringKeyword"] = stringKeyword.toJSValue(context)
1779 obj["booleanKeyword"] = booleanKeyword.toJSValue(context)2029 obj["booleanKeyword"] = booleanKeyword.toJSValue(context)
1780- obj["bigintKeyword"] = context.bigint(bigintKeyword).toJSValue(context)2030+ obj["bigintKeyword"] = context.bigint(bigintKeyword).toJSValue()
1781 obj["objectKeyword"] = objectKeyword2031 obj["objectKeyword"] = objectKeyword
1782 obj["symbolKeyword"] = symbolKeyword2032 obj["symbolKeyword"] = symbolKeyword
1783 obj["voidKeyword"] = voidKeyword.toJSValue(context)2033 obj["voidKeyword"] = voidKeyword.toJSValue(context)
@@ -1788,23 +2038,22 @@ public class BasicTypes {
1788 obj.toJSValue()2038 obj.toJSValue()
1789 }2039 }
1790 2040 
1791- public static func fromJSValue (context: JSContext, input: JSValue): BasicTypes {2041+ public static func fromJSValue(context: JSContext, input: JSValue): BasicTypes {
1792 let obj = input.asObject()2042 let obj = input.asObject()
1793 BasicTypes(2043 BasicTypes(
1794 Float64.fromJSValue(context, obj["numberKeyword"]),2044 Float64.fromJSValue(context, obj["numberKeyword"]),
1795 String.fromJSValue(context, obj["stringKeyword"]),2045 String.fromJSValue(context, obj["stringKeyword"]),
1796 Bool.fromJSValue(context, obj["booleanKeyword"]),2046 Bool.fromJSValue(context, obj["booleanKeyword"]),
1797- obj["bigintKeyword"].asBigInt(context).toBigInt(),2047+ obj["bigintKeyword"].asBigInt().toBigInt(),
1798- JSValue/* FIXME: `object` */.fromJSValue(context, obj["objectKeyword"]),2048+ obj["objectKeyword"],
1799- JSValue/* FIXME: `symbol` */.fromJSValue(context, obj["symbolKeyword"]),2049+ obj["symbolKeyword"],
1800 Unit.fromJSValue(context, obj["voidKeyword"]),2050 Unit.fromJSValue(context, obj["voidKeyword"]),
1801- JSValue/* FIXME: `undefined` */.fromJSValue(context, obj["undefinedKeyword"]),2051+ obj["undefinedKeyword"],
1802- JSValue/* FIXME: `any` */.fromJSValue(context, obj["anyKeyword"]),2052+ obj["anyKeyword"],
1803- JSValue/* FIXME: `unknown` */.fromJSValue(context, obj["unknownKeyword"]),2053+ obj["unknownKeyword"],
1804- JSValue/* FIXME: `never` */.fromJSValue(context, obj["neverKeyword"])2054+ obj["neverKeyword"]
1805 )2055 )
1806 }2056 }
1807- 
1808}2057}
1809```2058```
1810 2059 
@@ -1835,33 +2084,47 @@ interface arrayInterface {
1835Generated Cangjie code:2084Generated Cangjie code:
1836 2085 
1837```cangjie2086```cangjie
1838-public class arrayInterface {2087+/*interface arrayInterface {
2088+ arrayType1: number[];
2089+ arrayType2: Uint8Array;
2090+ arrayType3: ArrayBuffer;
2091+ arrayType4: Float32Array;
2092+ }*/
1839 2093 
1840- protected arrayInterface(public var arrayType1: Array<Float64>,2094+public open class arrayInterface {
1841- public var arrayType2: Array<UInt8>,2095+ public var arrayType1: Array<Float64>
1842- public var arrayType3: Array<UInt8>,2096+ public var arrayType2: Array<UInt8>
1843- public var arrayType4: Array<Float32>) {}2097+ public var arrayType3: Array<UInt8>
2098+ public var arrayType4: Array<Float32>
2099+ protected init(
2100+ arrayType1: Array<Float64>,
2101+ arrayType2: Array<UInt8>,
2102+ arrayType3: Array<UInt8>,
2103+ arrayType4: Array<Float32>) {
2104+ this.arrayType1 = arrayType1
2105+ this.arrayType2 = arrayType2
2106+ this.arrayType3 = arrayType3
2107+ this.arrayType4 = arrayType4
2108+ }
1844 2109 
1845- 2110+ public open func toJSValue(context: JSContext): JSValue {
1846- public func toJSValue(context: JSContext): JSValue {
1847 let obj = context.object()2111 let obj = context.object()
1848- obj["arrayType1"] = toJSArray(context, arrayType1)2112+ obj["arrayType1"] = toJSArray < Float64 >(context, arrayType1)
1849- obj["arrayType2"] = toJSArray(context, arrayType2, { ctx: JSContext, val: UInt8 => val.toJSValue(ctx) })2113+ obj["arrayType2"] = toJSArray < UInt8 >(context, arrayType2, { ctx: JSContext, val: UInt8 => val.toJSValue(ctx) })
1850- obj["arrayType3"] = toJSArray(context, arrayType3, { ctx: JSContext, val: UInt8 => val.toJSValue(ctx) })2114+ obj["arrayType3"] = toJSArray < UInt8 >(context, arrayType3, { ctx: JSContext, val: UInt8 => val.toJSValue(ctx) })
1851- obj["arrayType4"] = toJSArray(context, arrayType4, { ctx: JSContext, val: Float32 => val.toJSValue(ctx) })2115+ obj["arrayType4"] = toJSArray < Float32 >(context, arrayType4, { ctx: JSContext, val: Float32 => val.toJSValue(ctx) })
1852 obj.toJSValue()2116 obj.toJSValue()
1853 }2117 }
1854 2118 
1855- public static func fromJSValue (context: JSContext, input: JSValue): arrayInterface {2119+ public static func fromJSValue(context: JSContext, input: JSValue): arrayInterface {
1856 let obj = input.asObject()2120 let obj = input.asObject()
1857 arrayInterface(2121 arrayInterface(
1858 fromJSArray < Float64 >(context, obj["arrayType1"]),2122 fromJSArray < Float64 >(context, obj["arrayType1"]),
1859- fromJSArray(context, obj["arrayType2"], { ctx: JSContext, val: JSValue => UInt8.fromJSValue(ctx, val) }),2123+ fromJSArray < UInt8 >(context, obj["arrayType2"], { ctx: JSContext, val: JSValue => UInt8.fromJSValue(ctx, val) }),
1860- fromJSArray(context, obj["arrayType3"], { ctx: JSContext, val: JSValue => UInt8.fromJSValue(ctx, val) }),2124+ fromJSArray < UInt8 >(context, obj["arrayType3"], { ctx: JSContext, val: JSValue => UInt8.fromJSValue(ctx, val) }),
1861- fromJSArray(context, obj["arrayType4"], { ctx: JSContext, val: JSValue => Float32.fromJSValue(ctx, val) })2125+ fromJSArray < Float32 >(context, obj["arrayType4"], { ctx: JSContext, val: JSValue => Float32.fromJSValue(ctx, val) })
1862 )2126 )
1863 }2127 }
1864- 
1865}2128}
1866```2129```
1867 2130 
@@ -1889,46 +2152,64 @@ interface TestListener {
1889Generated Cangjie code:2152Generated Cangjie code:
1890 2153 
1891```cangjie2154```cangjie
1892-public class TestListener {2155+/*interface TestListener {
2156+ onStart?: () => void;
2157+ onDestroy?: () => void;
2158+ onError?: (code: ErrorCode, msg: String) => void;
2159+ onTouch?: () => void;
2160+ onEvent?: (e: EventType) => void;
2161+ }*/
1893 2162 
1894- protected TestListener(public var onStart!: Option<() -> Unit> = None,2163+public open class TestListener {
1895- public var onDestroy!: Option<() -> Unit> = None,2164+ public var onStart: Option<() -> Unit> = None
1896- public var onError!: Option<(code: ErrorCode, msg: String) -> Unit> = None,2165+ public var onDestroy: Option<() -> Unit> = None
1897- public var onTouch!: Option<() -> Unit> = None,2166+ public var onError: Option<(JSValue/* FIXME: `ErrorCode` */, String) -> Unit> = None
1898- public var onEvent!: Option<(e: EventType) -> Unit> = None) {}2167+ public var onTouch: Option<() -> Unit> = None
2168+ public var onEvent: Option<(JSValue/* FIXME: `EventType` */) -> Unit> = None
2169+ protected init(
2170+ onStart!: Option<() -> Unit> = None,
2171+ onDestroy!: Option<() -> Unit> = None,
2172+ onError!: Option<(JSValue/* FIXME: `ErrorCode` */, String) -> Unit> = None,
2173+ onTouch!: Option<() -> Unit> = None,
2174+ onEvent!: Option<(JSValue/* FIXME: `EventType` */) -> Unit> = None) {
2175+ this.onStart = onStart
2176+ this.onDestroy = onDestroy
2177+ this.onError = onError
2178+ this.onTouch = onTouch
2179+ this.onEvent = onEvent
2180+ }
1899 2181 
1900- 2182+ public open func toJSValue(context: JSContext): JSValue {
1901- public func toJSValue(context: JSContext): JSValue {
1902 let obj = context.object()2183 let obj = context.object()
1903- if(let Some(v) <- onStart) {2184+ if (let Some(v) <- onStart) {
1904 obj["onStart"] = context.function({ ctx, _ =>2185 obj["onStart"] = context.function({ ctx, _ =>
1905 v()2186 v()
1906 ctx.undefined().toJSValue()2187 ctx.undefined().toJSValue()
1907 }).toJSValue()2188 }).toJSValue()
1908 }2189 }
1909- if(let Some(v) <- onDestroy) {2190+ if (let Some(v) <- onDestroy) {
1910 obj["onDestroy"] = context.function({ ctx, _ =>2191 obj["onDestroy"] = context.function({ ctx, _ =>
1911 v()2192 v()
1912 ctx.undefined().toJSValue()2193 ctx.undefined().toJSValue()
1913 }).toJSValue()2194 }).toJSValue()
1914 }2195 }
1915- if(let Some(v) <- onError) {2196+ if (let Some(v) <- onError) {
1916 obj["onError"] = context.function({ ctx, info =>2197 obj["onError"] = context.function({ ctx, info =>
1917- let p0 = ErrorCode.fromJSValue(ctx, info[0])2198+ let p0 = info[0]
1918 let p1 = String.fromJSValue(ctx, info[1])2199 let p1 = String.fromJSValue(ctx, info[1])
1919 v(p0, p1)2200 v(p0, p1)
1920 ctx.undefined().toJSValue()2201 ctx.undefined().toJSValue()
1921 }).toJSValue()2202 }).toJSValue()
1922 }2203 }
1923- if(let Some(v) <- onTouch) {2204+ if (let Some(v) <- onTouch) {
1924 obj["onTouch"] = context.function({ ctx, _ =>2205 obj["onTouch"] = context.function({ ctx, _ =>
1925 v()2206 v()
1926 ctx.undefined().toJSValue()2207 ctx.undefined().toJSValue()
1927 }).toJSValue()2208 }).toJSValue()
1928 }2209 }
1929- if(let Some(v) <- onEvent) {2210+ if (let Some(v) <- onEvent) {
1930 obj["onEvent"] = context.function({ ctx, info =>2211 obj["onEvent"] = context.function({ ctx, info =>
1931- let p0 = EventType.parse(Int32.fromJSValue(ctx, info[0]))2212+ let p0 = info[0]
1932 v(p0)2213 v(p0)
1933 ctx.undefined().toJSValue()2214 ctx.undefined().toJSValue()
1934 }).toJSValue()2215 }).toJSValue()
@@ -1936,10 +2217,10 @@ public class TestListener {
1936 obj.toJSValue()2217 obj.toJSValue()
1937 }2218 }
1938 2219 
1939- public static func fromJSValue (context: JSContext, input: JSValue): TestListener {2220+ public static func fromJSValue(context: JSContext, input: JSValue): TestListener {
1940 let obj = input.asObject()2221 let obj = input.asObject()
1941 TestListener(2222 TestListener(
1942- onStart: if(obj["onStart"].isUndefined()) {2223+ onStart: if (obj["onStart"].isUndefined()) {
1943 None2224 None
1944 } else {2225 } else {
1945 { =>2226 { =>
@@ -1948,7 +2229,7 @@ public class TestListener {
1948 })2229 })
1949 }2230 }
1950 },2231 },
1951- onDestroy: if(obj["onDestroy"].isUndefined()) {2232+ onDestroy: if (obj["onDestroy"].isUndefined()) {
1952 None2233 None
1953 } else {2234 } else {
1954 { =>2235 { =>
@@ -1957,18 +2238,18 @@ public class TestListener {
1957 })2238 })
1958 }2239 }
1959 },2240 },
1960- onError: if(obj["onError"].isUndefined()) {2241+ onError: if (obj["onError"].isUndefined()) {
1961 None2242 None
1962 } else {2243 } else {
1963- { code: ErrorCode, msg: String =>2244+ { code: JSValue/* FIXME: `ErrorCode` */, msg: String =>
1964 checkThreadAndCall < Unit >(context, { ctx =>2245 checkThreadAndCall < Unit >(context, { ctx =>
1965- let arg0 = code.toJSValue(ctx)2246+ let arg0 = code
1966 let arg1 = msg.toJSValue(ctx)2247 let arg1 = msg.toJSValue(ctx)
1967 obj["onError"].asFunction().call([arg0, arg1])2248 obj["onError"].asFunction().call([arg0, arg1])
1968 })2249 })
1969 }2250 }
1970 },2251 },
1971- onTouch: if(obj["onTouch"].isUndefined()) {2252+ onTouch: if (obj["onTouch"].isUndefined()) {
1972 None2253 None
1973 } else {2254 } else {
1974 { =>2255 { =>
@@ -1977,19 +2258,18 @@ public class TestListener {
1977 })2258 })
1978 }2259 }
1979 },2260 },
1980- onEvent: if(obj["onEvent"].isUndefined()) {2261+ onEvent: if (obj["onEvent"].isUndefined()) {
1981 None2262 None
1982 } else {2263 } else {
1983- { e: EventType =>2264+ { e: JSValue/* FIXME: `EventType` */ =>
1984 checkThreadAndCall < Unit >(context, { ctx =>2265 checkThreadAndCall < Unit >(context, { ctx =>
1985- let arg0 = e.get().toJSValue(ctx)2266+ let arg0 = e
1986 obj["onEvent"].asFunction().call([arg0])2267 obj["onEvent"].asFunction().call([arg0])
1987 })2268 })
1988 }2269 }
1989 }2270 }
1990 )2271 )
1991 }2272 }
1992- 
1993}2273}
1994```2274```
1995 2275 
@@ -2008,35 +2288,39 @@ interface MyListener {
2008Generated Cangjie code:2288Generated Cangjie code:
2009 2289 
2010```cangjie2290```cangjie
2011-public class MyListener {2291+/*interface MyListener {
2292+ on(key: string, param: boolean, cb: (r: Record<string, string>) => void): void
2293+ }*/
2294+ 
2295+public open class MyListener {
2012 let callbackManager = CallbackManager < String, JSValue >()2296 let callbackManager = CallbackManager < String, JSValue >()
2013- protected MyListener(let arkts_object: JSObject) {}2297+ 
2298+ protected MyListener(var arkts_object: JSObject) { }
2014 2299 
2015 /**2300 /**
2016- * @brief on(key: string,param: boolean,cb: (r: Record<string, string>) => void): void2301+ * @brief on(key: string, param: boolean, cb: (r: Record<string, string>) => void): void
2017- */2302+ */
2018- public func on(key: String, param: Bool, cb: Callback1Argument<Record>): Unit {2303+ public func on(key: String, param: Bool, cb: Callback1Argument<HashMap<String, String>>): Unit {
2019- let key = key.toString()2304+ let keyString = key.toString()
2020- if(callbackManager.findCallbackObject(key, cb).isSome()) {2305+ if (callbackManager.findCallbackObject(keyString, cb).isSome()) {
2021 return2306 return
2022 }2307 }
2023 let jsCallback = checkThreadAndCall < JSValue >(getMainContext()) {2308 let jsCallback = checkThreadAndCall < JSValue >(getMainContext()) {
2024- __ctx => __ctx.function {2309+ ctx => ctx.function {
2025- __ctx: JSContext, info: JSCallInfo =>2310+ ctx: JSContext, info: JSCallInfo =>
2026- let arg0 = Record<stringstring>.fromJSValue(__ctx, info[0])2311+ let arg0 = record2Hashmap<String>(ctx, info[0], { context, i => String.fromJSValue(context, i) })
2027 cb.invoke(arg0)2312 cb.invoke(arg0)
2028- __ctx.undefined().toJSValue()2313+ ctx.undefined().toJSValue()
2029 }.toJSValue()2314 }.toJSValue()
2030 }2315 }
2031- callbackManager.put(key,(cb, jsCallback))2316+ callbackManager.put(keyString,(cb, jsCallback))
2032- jsObjApiCall < Unit >( arkts_object, "on", { __ctx =>[key.toJSValue(__ctx), param.toJSValue(__ctx), jsCallback] })2317+ jsObjApiCall < Unit >( arkts_object, "on", { ctx =>[keyString.toJSValue(ctx), param.toJSValue(ctx), jsCallback] })
2033 }2318 }
2034- 2319+ public open func toJSValue(_: JSContext): JSValue {
2035- func toJSValue(context: JSContext): JSValue {
2036 arkts_object.toJSValue()2320 arkts_object.toJSValue()
2037 }2321 }
2038 2322 
2039- static func fromJSValue (context: JSContext, input: JSValue): MyListener {2323+ public static func fromJSValue(_: JSContext, input: JSValue): MyListener {
2040 MyListener(input.asObject())2324 MyListener(input.asObject())
2041 }2325 }
2042}2326}
@@ -2058,13 +2342,22 @@ interface Optionals {
2058Generated Cangjie code:2342Generated Cangjie code:
2059 2343 
2060```cangjie2344```cangjie
2061-public class Optionals {2345+/*interface Optionals {
2346+ optionalParam10: (a: number, b?: String) => void;
2347+ optionalField1?: number;
2348+ }*/
2062 2349 
2063- protected Optionals(public var optionalParam10: (a: Float64, b: ?String) -> Unit,2350+public open class Optionals {
2064- public var optionalField1!: Option<Float64> = None) {}2351+ public var optionalParam10: (Float64, ?String) -> Unit
2352+ public var optionalField1: Option<Float64> = None
2353+ protected init(
2354+ optionalParam10: (Float64, ?String) -> Unit,
2355+ optionalField1!: Option<Float64> = None) {
2356+ this.optionalParam10 = optionalParam10
2357+ this.optionalField1 = optionalField1
2358+ }
2065 2359 
2066- 2360+ public open func toJSValue(context: JSContext): JSValue {
2067- public func toJSValue(context: JSContext): JSValue {
2068 let obj = context.object()2361 let obj = context.object()
2069 obj["optionalParam10"] = context.function({ ctx, info =>2362 obj["optionalParam10"] = context.function({ ctx, info =>
2070 let p0 = Float64.fromJSValue(ctx, info[0])2363 let p0 = Float64.fromJSValue(ctx, info[0])
@@ -2072,30 +2365,33 @@ public class Optionals {
2072 optionalParam10(p0, p1)2365 optionalParam10(p0, p1)
2073 ctx.undefined().toJSValue()2366 ctx.undefined().toJSValue()
2074 }).toJSValue()2367 }).toJSValue()
2075- if(let Some(v) <- optionalField1) {2368+ if (let Some(v) <- optionalField1) {
2076 obj["optionalField1"] = v.toJSValue(context)2369 obj["optionalField1"] = v.toJSValue(context)
2077 }2370 }
2078 obj.toJSValue()2371 obj.toJSValue()
2079 }2372 }
2080 2373 
2081- public static func fromJSValue (context: JSContext, input: JSValue): Optionals {2374+ public static func fromJSValue(context: JSContext, input: JSValue): Optionals {
2082 let obj = input.asObject()2375 let obj = input.asObject()
2083 Optionals(2376 Optionals(
2084 { a: Float64, b:?String =>2377 { a: Float64, b:?String =>
2085 checkThreadAndCall < Unit >(context, { ctx =>2378 checkThreadAndCall < Unit >(context, { ctx =>
2086 let arg0 = a.toJSValue(ctx)2379 let arg0 = a.toJSValue(ctx)
2087- let arg1 = b?.toJSValue(ctx)2380+ let arg1 = match(b) {
2381+ case None => ctx.undefined().toJSValue()
2382+ case _ => b.getOrThrow().toJSValue(ctx)
2383+ }
2088 obj["optionalParam10"].asFunction().call([arg0, arg1])2384 obj["optionalParam10"].asFunction().call([arg0, arg1])
2089 })2385 })
2090 },2386 },
2091- optionalField1: if(obj["optionalField1"].isUndefined()) {2387+ optionalField1:
2092- None2388+ if (obj["optionalField1"].isNull()) {
2389+ None < Float64 >
2093 } else {2390 } else {
2094 Float64.fromJSValue(context, obj["optionalField1"])2391 Float64.fromJSValue(context, obj["optionalField1"])
2095 }2392 }
2096 )2393 )
2097 }2394 }
2098- 
2099}2395}
2100```2396```
2101 2397 
@@ -2118,30 +2414,114 @@ Current type is not supported and will be converted to JSValue by default.
2118Generated Cangjie code:2414Generated Cangjie code:
2119 2415 
2120```cangjie2416```cangjie
2121-public class ObjectTypes<U, T> {2417+/*interface AutoGenType0 {
2418+ x: number;
2419+ y: U;
2420+ }*/
2122 2421 
2123- protected ObjectTypes(public var typeLiteral10: JSValue/* FIXME: `{ x: number; y: U }` */,2422+public open class AutoGenType0<U> where U <: JSInteropType<U> {
2124- public var typeLiteral20: JSValue/* FIXME: `{ [number]: string; [symbol]: T }` */,2423+ public var x: Float64
2125- public var typeLiteral30: JSValue/* FIXME: `{ () => void; (number: any) => string }` */) {}2424+ public var y: U
2425+ protected init(
2426+ x: Float64,
2427+ y: U) {
2428+ this.x = x
2429+ this.y = y
2430+ }
2126 2431 
2127- 2432+ public open func toJSValue(context: JSContext): JSValue {
2128- public func toJSValue(context: JSContext): JSValue {
2129 let obj = context.object()2433 let obj = context.object()
2130- obj["typeLiteral10"] = typeLiteral102434+ obj["x"] = x.toJSValue(context)
2131- obj["typeLiteral20"] = typeLiteral202435+ obj["y"] = y.toJSValue(context)
2132- obj["typeLiteral30"] = typeLiteral30
2133 obj.toJSValue()2436 obj.toJSValue()
2134 }2437 }
2135 2438 
2136- public static func fromJSValue <U, T>(context: JSContext, input: JSValue): ObjectTypes<U, T> {2439+ public static func fromJSValue(context: JSContext, input: JSValue): AutoGenType0<U> {
2137 let obj = input.asObject()2440 let obj = input.asObject()
2138- ObjectTypes(2441+ AutoGenType0(
2139- JSValue/* FIXME: `{ x: number; y: U }` */.fromJSValue(context, obj["typeLiteral10"]),2442+ Float64.fromJSValue(context, obj["x"]),
2140- JSValue/* FIXME: `{ [number]: string; [symbol]: T }` */.fromJSValue(context, obj["typeLiteral20"]),2443+ U.fromJSValue(context, obj["y"])
2141- JSValue/* FIXME: `{ () => void; (number: any) => string }` */.fromJSValue(context, obj["typeLiteral30"])
2142 )2444 )
2143 }2445 }
2446+}
2144 2447 
2448+/*interface AutoGenType1 {
2449+ }*/
2450+ 
2451+public open class AutoGenType1 {
2452+ protected init() {
2453+ }
2454+ 
2455+ public open func toJSValue(context: JSContext): JSValue {
2456+ let obj = context.object()
2457+ 
2458+ obj.toJSValue()
2459+ }
2460+ 
2461+ public static func fromJSValue(context: JSContext, input: JSValue): AutoGenType1 {
2462+ let obj = input.asObject()
2463+ AutoGenType1(
2464+ 
2465+ )
2466+ }
2467+}
2468+ 
2469+/*interface AutoGenType2 {
2470+ }*/
2471+ 
2472+public open class AutoGenType2 {
2473+ protected init() {
2474+ }
2475+ 
2476+ public open func toJSValue(context: JSContext): JSValue {
2477+ let obj = context.object()
2478+ 
2479+ obj.toJSValue()
2480+ }
2481+ 
2482+ public static func fromJSValue(context: JSContext, input: JSValue): AutoGenType2 {
2483+ let obj = input.asObject()
2484+ AutoGenType2(
2485+ 
2486+ )
2487+ }
2488+}
2489+ 
2490+/*interface ObjectTypes {
2491+ typeLiteral10: { x: number; y: U; };
2492+ typeLiteral20: { [p: number]: String; [p: symbol]: T };
2493+ typeLiteral30: { (): void; (number): String };
2494+ }*/
2495+ 
2496+public open class ObjectTypes<U, T> where U <: JSInteropType<U>, T <: JSInteropType<T> {
2497+ public var typeLiteral10: AutoGenType0<U>
2498+ public var typeLiteral20: AutoGenType1
2499+ public var typeLiteral30: AutoGenType2
2500+ protected init(
2501+ typeLiteral10: AutoGenType0<U>,
2502+ typeLiteral20: AutoGenType1,
2503+ typeLiteral30: AutoGenType2) {
2504+ this.typeLiteral10 = typeLiteral10
2505+ this.typeLiteral20 = typeLiteral20
2506+ this.typeLiteral30 = typeLiteral30
2507+ }
2508+ 
2509+ public open func toJSValue(context: JSContext): JSValue {
2510+ let obj = context.object()
2511+ obj["typeLiteral10"] = typeLiteral10.toJSValue(context)
2512+ obj["typeLiteral20"] = typeLiteral20.toJSValue(context)
2513+ obj["typeLiteral30"] = typeLiteral30.toJSValue(context)
2514+ obj.toJSValue()
2515+ }
2516+ 
2517+ public static func fromJSValue(context: JSContext, input: JSValue): ObjectTypes<U, T> {
2518+ let obj = input.asObject()
2519+ ObjectTypes(
2520+ AutoGenType0<U>.fromJSValue(context, obj["typeLiteral10"]),
2521+ AutoGenType1.fromJSValue(context, obj["typeLiteral20"]),
2522+ AutoGenType2.fromJSValue(context, obj["typeLiteral30"])
2523+ )
2524+ }
2145}2525}
2146```2526```
2147 2527 
@@ -2158,7 +2538,7 @@ tupleType: [number, number, string];
2158Generated Cangjie code:2538Generated Cangjie code:
2159 2539 
2160```cangjie2540```cangjie
2161-public var tupleType: Tuple<Float64, Float64, String>2541+public var tupleType: (Float64, Float64, String)
2162```2542```
2163 2543 
2164### Union Types2544### Union Types
@@ -2192,21 +2572,36 @@ public enum ARK1 {
2192 case STRING(x) => context.string(x).toJSValue()2572 case STRING(x) => context.string(x).toJSValue()
2193 case BOOLEAN(x) => context.boolean(x).toJSValue()2573 case BOOLEAN(x) => context.boolean(x).toJSValue()
2194 case BYTEARRAY(x) => context.global["Uint8Array"].asClass().new(x.toJSValue(context))2574 case BYTEARRAY(x) => context.global["Uint8Array"].asClass().new(x.toJSValue(context))
2195- case FLOAT32ARRAY(x) => let buffer = context.arrayBuffer(acquireArrayRawData(x), x.size, { pt => releaseArrayRawData(pt)})2575+ case FLOAT32ARRAY(x) => context.global["Float32Array"].asClass().new(context.arrayBuffer(x).toJSValue())
2196-context.global["Float32Array"].asClass().new(buffer.toJSValue())
2197 case BIGINT(x) => context.bigint(x).toJSValue()2576 case BIGINT(x) => context.bigint(x).toJSValue()
2198 }2577 }
2199 }2578 }
2200-}2579+ public static func fromJSValue(context: JSContext, input: JSValue): ARK1 {
2201 2580 
2202-public enum ARK2 {2581+ if (input.isNull()) {
2203- | ARK1(x)2582+ return NULL
2204- | VOID(Unit)
2205- 
2206- public func toJSValue(context: JSContext): JSValue {
2207- match(this) {
2208- case ARK1(x) => x.toJSValue(context)
2209 }2583 }
2584+ if (input.isNumber()) {
2585+ return NUMBER(Float64.fromJSValue(context, input))
2586+ }
2587+ if (input.isString()) {
2588+ return STRING(String.fromJSValue(context, input))
2589+ }
2590+ if (input.isBoolean()) {
2591+ return BOOLEAN(Bool.fromJSValue(context, input))
2592+ }
2593+ if (instanceof(input, "Uint8Array")) {
2594+ let jsArray: JSValue = context.global["Uint8Array"].asObject().callMethod("from", [input])
2595+ return BYTEARRAY(fromJSArray<UInt8>(context, jsArray))
2596+ }
2597+ if (instanceof(input, "Float32Array")) {
2598+ let jsArray: JSValue = context.global["Float32Array"].asObject().callMethod("from", [input])
2599+ return FLOAT32ARRAY(fromJSArray<Float32>(context, jsArray))
2600+ }
2601+ if (input.isBigInt()) {
2602+ return BIGINT(input.toBigInt())
2603+ }
2604+ throw Exception("unsupport type!")
2210 }2605 }
2211}2606}
2212```2607```
@@ -2222,7 +2617,7 @@ typeReference21: Promise<T>;
2222Generated Cangjie code:2617Generated Cangjie code:
2223 2618 
2224```cangjie2619```cangjie
2225-public var typeReference21: Promise<T>,2620+public var typeReference21: JSValue/* FIXME: `Promise<T>` */
2226```2621```
2227 2622 
2228### Intersection Types2623### Intersection Types
@@ -2240,24 +2635,28 @@ Current type is not supported and will be converted to JSValue by default.
2240Generated Cangjie code:2635Generated Cangjie code:
2241 2636 
2242```cangjie2637```cangjie
2243-public class IntersectionTypes<U, T> {2638+/*interface IntersectionTypes {
2639+ intersectionType: object & Record<U, T>;
2640+ }*/
2244 2641 
2245- protected IntersectionTypes(public var intersectionType: JSValue/* FIXME: `object & HashMap<U, T>` */) {}2642+public open class IntersectionTypes<U, T> where U <: JSInteropType<U>, T <: JSInteropType<T> {
2643+ public var intersectionType: JSValue/* FIXME: `object & HashMap<U, T>` */
2644+ protected init(intersectionType: JSValue/* FIXME: `object & HashMap<U, T>` */) {
2645+ this.intersectionType = intersectionType
2646+ }
2246 2647 
2247- 2648+ public open func toJSValue(context: JSContext): JSValue {
2248- public func toJSValue(context: JSContext): JSValue {
2249 let obj = context.object()2649 let obj = context.object()
2250 obj["intersectionType"] = intersectionType2650 obj["intersectionType"] = intersectionType
2251 obj.toJSValue()2651 obj.toJSValue()
2252 }2652 }
2253 2653 
2254- public static func fromJSValue <U, T>(context: JSContext, input: JSValue): IntersectionTypes<U, T> {2654+ public static func fromJSValue(context: JSContext, input: JSValue): IntersectionTypes<U, T> {
2255 let obj = input.asObject()2655 let obj = input.asObject()
2256 IntersectionTypes(2656 IntersectionTypes(
2257- JSValue/* FIXME: `object & HashMap<U, T>` */.fromJSValue(context, obj["intersectionType"])2657+ obj["intersectionType"]
2258 )2658 )
2259 }2659 }
2260- 
2261}2660}
2262```2661```
2263 2662 
@@ -2290,6 +2689,9 @@ declare module './exportAlias' {
2290Generated Cangjie Code:2689Generated Cangjie Code:
2291 2690 
2292```cangjie2691```cangjie
2692+import ohos.ark_interop.*
2693+import ohos.ark_interop_helper.*
2694+import ohos.base.*
2293/***********IMPORT***********/2695/***********IMPORT***********/
2294/*FIXME: Import details need to be verified and rewritten by user.*/2696/*FIXME: Import details need to be verified and rewritten by user.*/
2295/*import { a } from '@umeng/common';*/2697/*import { a } from '@umeng/common';*/
@@ -2309,7 +2711,6 @@ Generated Cangjie Code:
2309/*FIXME: Import details need to be verified and rewritten by user.*/2711/*FIXME: Import details need to be verified and rewritten by user.*/
2310/*import { ExportedInterface } from './exportAlias';*/2712/*import { ExportedInterface } from './exportAlias';*/
2311 2713 
2312- 
2313/*2714/*
2314 2715 
2315public const value1 = 0/* FIXME: Initialization is required */2716public const value1 = 0/* FIXME: Initialization is required */
@@ -2321,40 +2722,40 @@ public const value2 = 0/* FIXME: Initialization is required */
2321 2722 
2322/***********METHOD***********/2723/***********METHOD***********/
2323/**2724/**
2324- * @brief createSub(): Inheritances.SubClass2725+ * @brief createSub(): Inheritances.SubClass
2325- */2726+ */
2326public func createSub(): JSValue/* FIXME: `Inheritances.SubClass` */ {2727public func createSub(): JSValue/* FIXME: `Inheritances.SubClass` */ {
2327- hmsGlobalApiCall < JSValue/* FIXME: `Inheritances.SubClass` */ >( "my_module_imports", "createSub", emptyArg) {2728+ hmsGlobalApiCall < JSValue/* FIXME: `Inheritances.SubClass` */ >( "_ark_interop_api", "createSub", EMPTY_ARG) { ctx, info => info }
2328- ctx, info => info
2329- }
2330}2729}
2331 2730 
2332- 
2333-/***********OBJECT***********/
2334- 
2335/*interface ExportedInterface {2731/*interface ExportedInterface {
2336 myOption?: String;2732 myOption?: String;
2337 }*/2733 }*/
2338 2734 
2339public open class ExportedInterface {2735public open class ExportedInterface {
2340- 2736+ public var myOption: Option<String> = None
2341- protected ExportedInterface(public var myOption!: Option<String> = None) {}2737+ protected init(myOption!: Option<String> = None) {
2342- 2738+ this.myOption = myOption
2343- 2739+ }
2740+ 
2344 public open func toJSValue(context: JSContext): JSValue {2741 public open func toJSValue(context: JSContext): JSValue {
2345 let obj = context.object()2742 let obj = context.object()
2346- if(let Some(v) <- myOption) {2743+ if (let Some(v) <- myOption) {
2347 obj["myOption"] = v.toJSValue(context)2744 obj["myOption"] = v.toJSValue(context)
2348 }2745 }
2349 obj.toJSValue()2746 obj.toJSValue()
2350 }2747 }
2351- 2748+ 
2352 public static func fromJSValue(context: JSContext, input: JSValue): ExportedInterface {2749 public static func fromJSValue(context: JSContext, input: JSValue): ExportedInterface {
2353 let obj = input.asObject()2750 let obj = input.asObject()
2354 ExportedInterface(2751 ExportedInterface(
2355- myOption: Option < String >.fromJSValue(context, obj["myOption"])2752+ myOption:
2753+ if (obj["myOption"].isNull()) {
2754+ None < String >
2755+ } else {
2756+ String.fromJSValue(context, obj["myOption"])
2757+ }
2356 )2758 )
2357 }2759 }
2358-
2359}2760}
2360```2761```
@@ -75,8 +75,9 @@ hle -b ${CANGJIE_HOME}/tools/dtsparser/node_modules/.bin/cjbind -c --module-name
75 75 
76其中`-b`参数用于指定 cjbind 二进制文件的路径,cjbind 下载地址如下:76其中`-b`参数用于指定 cjbind 二进制文件的路径,cjbind 下载地址如下:
77 77 
78-- Linux: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v0.2.7/cjbind-linux-x64>78+- Linux-x64: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v1.1.0-alpha.53.1/cjbind-linux-x64>
79-- Windows: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v0.2.7/cjbind-windows-x64.exe>79+- Linux-arm64: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v1.1.0-alpha.53.1/cjbind-linux-arm64>
80-- macOS: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v0.2.7/cjbind-darwin-arm64>80+- Windows-x64: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v1.1.0-alpha.53.1/cjbind-windows-x64.exe>
81+- macOS-arm64: <https://gitcode.com/Cangjie-SIG/cjbind-cangjie/releases/download/v1.1.0-alpha.53.1/cjbind-darwin-arm64>
81 82 
82`--clang-args`参数是会被直接传递给 clang 的参数,在参数值内可用 -I 指定头文件搜索路径。系统头文件路径程序会自动搜索,用户自定义的头文件路径需要显式指定。83`--clang-args`参数是会被直接传递给 clang 的参数,在参数值内可用 -I 指定头文件搜索路径。系统头文件路径程序会自动搜索,用户自定义的头文件路径需要显式指定。
@@ -42,9 +42,9 @@ import ohos.base.*
42 42 
43/***********METHOD***********/43/***********METHOD***********/
44/**44/**
45-* @brief greeter(fn: (a: string) => void): void45+ * @brief greeter(fn: (a: string) => void): void
46-*/46+ */
47-public func greeter(fn: (a: String) -> Unit): Unit {47+public func greeter(fn: (String) -> Unit): Unit {
48 hmsGlobalApiCall < Unit >( "_ark_interop_api", "greeter", { ctx =>[ctx.function({ ctx, info =>48 hmsGlobalApiCall < Unit >( "_ark_interop_api", "greeter", { ctx =>[ctx.function({ ctx, info =>
49 let p0 = String.fromJSValue(ctx, info[0])49 let p0 = String.fromJSValue(ctx, info[0])
50 fn(p0)50 fn(p0)
@@ -53,12 +53,11 @@ public func greeter(fn: (a: String) -> Unit): Unit {
53}53}
54 54 
55/**55/**
56-* @brief printToConsole(s: string): void56+ * @brief printToConsole(s: string): void
57-*/57+ */
58public func printToConsole(s: String): Unit {58public func printToConsole(s: String): Unit {
59 hmsGlobalApiCall < Unit >( "_ark_interop_api", "printToConsole", { ctx =>[s.toJSValue(ctx)] })59 hmsGlobalApiCall < Unit >( "_ark_interop_api", "printToConsole", { ctx =>[s.toJSValue(ctx)] })
60}60}
61- 
62```61```
63 62 
64泛型函数示例:63泛型函数示例:
@@ -72,15 +71,17 @@ declare function testMultiGenericT<T, M>(t: T, m: M): T;
72生成的仓颉代码:71生成的仓颉代码:
73 72 
74```cangjie73```cangjie
75-/**74+import ohos.ark_interop.*
76- * @brief testMultiGenericT(t: T, m: M): T75+import ohos.ark_interop_helper.*
77- */76+import ohos.base.*
78-public func testMultiGenericT < T, M >(t: T, m: M): T where T <: JSInteropType<T>, M <: JSInteropType<M> {
79- hmsGlobalApiCall < T >( "my_module_genericFunction", "testMultiGenericT", { ctx =>[t.toJSValue(ctx), m.toJSValue(ctx)] }) {
80- ctx, info => T.fromJSValue(ctx, info)
81- }
82-}
83 77 
78+/***********METHOD***********/
79+/**
80+ * @brief testMultiGenericT(t: T, m: M): T
81+ */
82+public func testMultiGenericT < T, M >(t: T, m: M): T where T <: JSInteropType<T>, M <: JSInteropType<M> {
83+ hmsGlobalApiCall < T >( "_ark_interop_api", "testMultiGenericT", { ctx =>[t.toJSValue(ctx), m.toJSValue(ctx)] }) { ctx, info => T.fromJSValue(ctx, info) }
84+}
84```85```
85 86 
86### 全局变量87### 全局变量
@@ -100,11 +101,11 @@ declare let qoo: number;
100生成的仓颉代码:101生成的仓颉代码:
101 102 
102```cangjie103```cangjie
103-public const foo = !!!!!check in dts!!!!!104+public const foo = 0/* FIXME: Initialization is required */
104 105 
105-public const goo = !!!!!check in dts!!!!!106+public const goo = 0/* FIXME: Initialization is required */
106 107 
107-public const qoo = !!!!!check in dts!!!!!108+public const qoo = 0/* FIXME: Initialization is required */
108```109```
109 110 
110### 接口111### 接口
@@ -127,42 +128,55 @@ interface GreetingSettings {
127生成的仓颉代码:128生成的仓颉代码:
128 129 
129```cangjie130```cangjie
130-public class GreetingSettings {131+/*interface GreetingSettings {
132+ greeting: String;
133+ duration?: number;
134+ color?: String;
135+ }*/
131 136 
132- protected GreetingSettings(public var greeting: String,137+public open class GreetingSettings {
133- public var duration!: Option<Float64> = None,138+ public var greeting: String
134- public var color!: Option<String> = None) {}139+ public var duration: Option<Float64> = None
140+ public var color: Option<String> = None
141+ protected init(
142+ greeting: String,
143+ duration!: Option<Float64> = None,
144+ color!: Option<String> = None) {
145+ this.greeting = greeting
146+ this.duration = duration
147+ this.color = color
148+ }
135 149 
136- 150+ public open func toJSValue(context: JSContext): JSValue {
137- public func toJSValue(context: JSContext): JSValue {
138 let obj = context.object()151 let obj = context.object()
139 obj["greeting"] = greeting.toJSValue(context)152 obj["greeting"] = greeting.toJSValue(context)
140- if(let Some(v) <- duration) {153+ if (let Some(v) <- duration) {
141 obj["duration"] = v.toJSValue(context)154 obj["duration"] = v.toJSValue(context)
142 }155 }
143- if(let Some(v) <- color) {156+ if (let Some(v) <- color) {
144 obj["color"] = v.toJSValue(context)157 obj["color"] = v.toJSValue(context)
145 }158 }
146 obj.toJSValue()159 obj.toJSValue()
147 }160 }
148 161 
149- public static func fromJSValue (context: JSContext, input: JSValue): GreetingSettings {162+ public static func fromJSValue(context: JSContext, input: JSValue): GreetingSettings {
150 let obj = input.asObject()163 let obj = input.asObject()
151 GreetingSettings(164 GreetingSettings(
152 String.fromJSValue(context, obj["greeting"]),165 String.fromJSValue(context, obj["greeting"]),
153- duration: if(obj["duration"].isUndefined()) {166+ duration:
154- None167+ if (obj["duration"].isNull()) {
168+ None < Float64 >
155 } else {169 } else {
156 Float64.fromJSValue(context, obj["duration"])170 Float64.fromJSValue(context, obj["duration"])
157 },171 },
158- color: if(obj["color"].isUndefined()) {172+ color:
159- None173+ if (obj["color"].isNull()) {
174+ None < String >
160 } else {175 } else {
161 String.fromJSValue(context, obj["color"])176 String.fromJSValue(context, obj["color"])
162 }177 }
163 )178 )
164 }179 }
165- 
166}180}
167```181```
168 182 
@@ -180,30 +194,35 @@ interface Product {
180生成的仓颉代码:194生成的仓颉代码:
181 195 
182```cangjie196```cangjie
183-public class Product {197+/*interface Product {
198+ price?: number;
199+ }*/
184 200 
185- protected Product(public var price!: Option<Float64> = None) {}201+public open class Product {
202+ public var price: Option<Float64> = None
203+ protected init(price!: Option<Float64> = None) {
204+ this.price = price
205+ }
186 206 
187- 207+ public open func toJSValue(context: JSContext): JSValue {
188- public func toJSValue(context: JSContext): JSValue {
189 let obj = context.object()208 let obj = context.object()
190- if(let Some(v) <- price) {209+ if (let Some(v) <- price) {
191 obj["price"] = v.toJSValue(context)210 obj["price"] = v.toJSValue(context)
192 }211 }
193 obj.toJSValue()212 obj.toJSValue()
194 }213 }
195 214 
196- public static func fromJSValue (context: JSContext, input: JSValue): Product {215+ public static func fromJSValue(context: JSContext, input: JSValue): Product {
197 let obj = input.asObject()216 let obj = input.asObject()
198 Product(217 Product(
199- price: if(obj["price"].isUndefined()) {218+ price:
200- None219+ if (obj["price"].isNull()) {
220+ None < Float64 >
201 } else {221 } else {
202 Float64.fromJSValue(context, obj["price"])222 Float64.fromJSValue(context, obj["price"])
203 }223 }
204 )224 )
205 }225 }
206- 
207}226}
208```227```
209 228 
@@ -222,27 +241,35 @@ interface Point {
222生成的仓颉代码:241生成的仓颉代码:
223 242 
224```cangjie243```cangjie
225-public class Point {244+/*interface Point {
245+ ReadonlyKeywordx: number;
246+ ReadonlyKeywordy: number;
247+ }*/
226 248 
227- protected Point(public let x: Float64,249+public open class Point {
228- public let y: Float64) {}250+ public let x: Float64
251+ public let y: Float64
252+ protected init(
253+ x: Float64,
254+ y: Float64) {
255+ this.x = x
256+ this.y = y
257+ }
229 258 
230- 259+ public open func toJSValue(context: JSContext): JSValue {
231- public func toJSValue(context: JSContext): JSValue {
232 let obj = context.object()260 let obj = context.object()
233 obj["x"] = x.toJSValue(context)261 obj["x"] = x.toJSValue(context)
234 obj["y"] = y.toJSValue(context)262 obj["y"] = y.toJSValue(context)
235 obj.toJSValue()263 obj.toJSValue()
236 }264 }
237 265 
238- public static func fromJSValue (context: JSContext, input: JSValue): Point {266+ public static func fromJSValue(context: JSContext, input: JSValue): Point {
239 let obj = input.asObject()267 let obj = input.asObject()
240 Point(268 Point(
241 Float64.fromJSValue(context, obj["x"]),269 Float64.fromJSValue(context, obj["x"]),
242 Float64.fromJSValue(context, obj["y"])270 Float64.fromJSValue(context, obj["y"])
243 )271 )
244 }272 }
245- 
246}273}
247```274```
248 275 
@@ -274,10 +301,13 @@ interface Person {
274生成的仓颉代码:301生成的仓颉代码:
275 302 
276```cangjie303```cangjie
277-public class Person {304+/*interface Person {
278- 305+ name: String;
279- protected Person(let arkts_object: JSObject) {}306+ greet(): String
307+ }*/
280 308 
309+public open class Person {
310+ protected Person(var arkts_object: JSObject) { }
281 311 
282 public mut prop name: String {312 public mut prop name: String {
283 get() {313 get() {
@@ -294,17 +324,17 @@ public class Person {
294 }324 }
295 325 
296 /**326 /**
297- * @brief greet(): String327+ * @brief greet(): String
298- */328+ */
299 public func greet(): String {329 public func greet(): String {
300- jsObjApiCall < String >( arkts_object, "greet", emptyArg)330+ jsObjApiCall < String >( arkts_object, "greet", EMPTY_ARG)
301 }331 }
302 332 
303- func toJSValue(context: JSContext): JSValue {333+ public open func toJSValue(_: JSContext): JSValue {
304 arkts_object.toJSValue()334 arkts_object.toJSValue()
305 }335 }
306 336 
307- static func fromJSValue (context: JSContext, input: JSValue): Person {337+ public static func fromJSValue(_: JSContext, input: JSValue): Person {
308 Person(input.asObject())338 Person(input.asObject())
309 }339 }
310}340}
@@ -325,29 +355,32 @@ interface Calculator {
325生成的仓颉代码:355生成的仓颉代码:
326 356 
327```cangjie357```cangjie
328-public class Calculator {358+/*interface Calculator {
329- 359+ add(x: number, y: number): number
330- protected Calculator(let arkts_object: JSObject) {}360+ add(x: string, y: string): String
361+ }*/
331 362 
363+public open class Calculator {
364+ protected Calculator(var arkts_object: JSObject) { }
332 365 
333 /**366 /**
334- * @brief add(x: number,y: number): number367+ * @brief add(x: number, y: number): number
335- */368+ */
336 public func add(x: Float64, y: Float64): Float64 {369 public func add(x: Float64, y: Float64): Float64 {
337 jsObjApiCall < Float64 >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })370 jsObjApiCall < Float64 >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })
338 }371 }
339 /**372 /**
340- * @brief add(x: string,y: string): String373+ * @brief add(x: string, y: string): String
341- */374+ */
342 public func add(x: String, y: String): String {375 public func add(x: String, y: String): String {
343 jsObjApiCall < String >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })376 jsObjApiCall < String >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })
344 }377 }
345 378 
346- func toJSValue(context: JSContext): JSValue {379+ public open func toJSValue(_: JSContext): JSValue {
347 arkts_object.toJSValue()380 arkts_object.toJSValue()
348 }381 }
349 382 
350- static func fromJSValue (context: JSContext, input: JSValue): Calculator {383+ public static func fromJSValue(_: JSContext, input: JSValue): Calculator {
351 Calculator(input.asObject())384 Calculator(input.asObject())
352 }385 }
353}386}
@@ -368,37 +401,40 @@ interface List {
368生成的仓颉代码:401生成的仓颉代码:
369 402 
370```cangjie403```cangjie
371-public class List {404+/*interface List {
372- 405+ items: String[];
373- protected List(let arkts_object: JSObject) {}406+ add(item: string): void
407+ }*/
374 408 
409+public open class List {
410+ protected List(var arkts_object: JSObject) { }
375 411 
376 public mut prop items: Array<String> {412 public mut prop items: Array<String> {
377 get() {413 get() {
378 checkThreadAndCall < Array<String> >(getMainContext()) {414 checkThreadAndCall < Array<String> >(getMainContext()) {
379- ctx: JSContext => Array<String>.fromJSValue(ctx, arkts_object["items"])415+ ctx: JSContext => fromJSArray < String >(ctx, arkts_object["items"])
380 }416 }
381 }417 }
382 set(v) {418 set(v) {
383 checkThreadAndCall < Unit >(getMainContext()) {419 checkThreadAndCall < Unit >(getMainContext()) {
384- ctx: JSContext => arkts_object["items"] = v.toJSValue(ctx)420+ ctx: JSContext => arkts_object["items"] = toJSArray < String >(ctx, v)
385 }421 }
386 }422 }
387 423 
388 }424 }
389 425 
390 /**426 /**
391- * @brief add(item: string): void427+ * @brief add(item: string): void
392- */428+ */
393 public func add(item: String): Unit {429 public func add(item: String): Unit {
394 jsObjApiCall < Unit >( arkts_object, "add", { ctx =>[item.toJSValue(ctx)] })430 jsObjApiCall < Unit >( arkts_object, "add", { ctx =>[item.toJSValue(ctx)] })
395 }431 }
396 432 
397- func toJSValue(context: JSContext): JSValue {433+ public open func toJSValue(_: JSContext): JSValue {
398 arkts_object.toJSValue()434 arkts_object.toJSValue()
399 }435 }
400 436 
401- static func fromJSValue (context: JSContext, input: JSValue): List {437+ public static func fromJSValue(_: JSContext, input: JSValue): List {
402 List(input.asObject())438 List(input.asObject())
403 }439 }
404}440}
@@ -435,24 +471,28 @@ interface F extends C {
435生成的仓颉代码:471生成的仓颉代码:
436 472 
437```cangjie473```cangjie
474+/*interface A {
475+ p: number;
476+ }*/
477+ 
438public open class A {478public open class A {
439- 479+ public var p: Float64
440- protected A(public var p: Float64) {}480+ protected init(p: Float64) {
441- 481+ this.p = p
442- 482+ }
483+ 
443 public open func toJSValue(context: JSContext): JSValue {484 public open func toJSValue(context: JSContext): JSValue {
444 let obj = context.object()485 let obj = context.object()
445 obj["p"] = p.toJSValue(context)486 obj["p"] = p.toJSValue(context)
446 obj.toJSValue()487 obj.toJSValue()
447 }488 }
448- 489+ 
449 public static func fromJSValue(context: JSContext, input: JSValue): A {490 public static func fromJSValue(context: JSContext, input: JSValue): A {
450 let obj = input.asObject()491 let obj = input.asObject()
451 A(492 A(
452 Float64.fromJSValue(context, obj["p"])493 Float64.fromJSValue(context, obj["p"])
453 )494 )
454 }495 }
455-
456}496}
457 497 
458/*interface B {498/*interface B {
@@ -460,18 +500,20 @@ public open class A {
460 }*/500 }*/
461 501 
462public open class B <: A {502public open class B <: A {
463- 503+ public var p1: Float64
464- protected B(p: Float64,504+ protected init(p: Float64,
465- public var p1: Float64) { super(p) }505+ p1: Float64) {
466- 506+ super( p )
467- 507+ this.p1 = p1
508+ }
509+ 
468 public open func toJSValue(context: JSContext): JSValue {510 public open func toJSValue(context: JSContext): JSValue {
469 let obj = context.object()511 let obj = context.object()
470 obj["p"] = p.toJSValue(context)512 obj["p"] = p.toJSValue(context)
471 obj["p1"] = p1.toJSValue(context)513 obj["p1"] = p1.toJSValue(context)
472 obj.toJSValue()514 obj.toJSValue()
473 }515 }
474- 516+ 
475 public static func fromJSValue(context: JSContext, input: JSValue): B {517 public static func fromJSValue(context: JSContext, input: JSValue): B {
476 let obj = input.asObject()518 let obj = input.asObject()
477 B(519 B(
@@ -479,7 +521,6 @@ public open class B <: A {
479 Float64.fromJSValue(context, obj["p1"])521 Float64.fromJSValue(context, obj["p1"])
480 )522 )
481 }523 }
482-
483}524}
484 525 
485/*interface C {526/*interface C {
@@ -487,22 +528,20 @@ public open class B <: A {
487 }*/528 }*/
488 529 
489public open class C {530public open class C {
490- 531+ protected C(var arkts_object: JSObject) { }
491- protected C(public var arkts_object: JSObject) {}532+ 
492-
493-
494 /**533 /**
495 * @brief f(): void534 * @brief f(): void
496 */535 */
497 public func f(): Unit {536 public func f(): Unit {
498- jsObjApiCall < Unit >( arkts_object, "f", emptyArg)537+ jsObjApiCall < Unit >( arkts_object, "f", EMPTY_ARG)
499 }538 }
500- 539+ 
501- public open func toJSValue(context: JSContext): JSValue {540+ public open func toJSValue(_: JSContext): JSValue {
502 arkts_object.toJSValue()541 arkts_object.toJSValue()
503 }542 }
504- 543+ 
505- static func fromJSValue(context: JSContext, input: JSValue): C {544+ public static func fromJSValue(_: JSContext, input: JSValue): C {
506 C(input.asObject())545 C(input.asObject())
507 }546 }
508}547}
@@ -511,16 +550,13 @@ public open class C {
511 }*/550 }*/
512 551 
513public open class D <: C {552public open class D <: C {
514-
515 protected D(arkts_object: JSObject) { super(arkts_object) }553 protected D(arkts_object: JSObject) { super(arkts_object) }
516- 554+ 
517- 555+ public open func toJSValue(_: JSContext): JSValue {
518-
519- public open func toJSValue(context: JSContext): JSValue {
520 arkts_object.toJSValue()556 arkts_object.toJSValue()
521 }557 }
522- 558+ 
523- static func fromJSValue(context: JSContext, input: JSValue): D {559+ public static func fromJSValue(_: JSContext, input: JSValue): D {
524 D(input.asObject())560 D(input.asObject())
525 }561 }
526}562}
@@ -529,23 +565,22 @@ public open class D <: C {
529 }*/565 }*/
530 566 
531public open class E <: A {567public open class E <: A {
532- 568+ protected init(p: Float64) {
533- protected E(p: Float64) { super(p) }569+ super( p )
534- 570+ }
535- 571+ 
536 public open func toJSValue(context: JSContext): JSValue {572 public open func toJSValue(context: JSContext): JSValue {
537 let obj = context.object()573 let obj = context.object()
538 obj["p"] = p.toJSValue(context)574 obj["p"] = p.toJSValue(context)
539 obj.toJSValue()575 obj.toJSValue()
540 }576 }
541- 577+ 
542 public static func fromJSValue(context: JSContext, input: JSValue): E {578 public static func fromJSValue(context: JSContext, input: JSValue): E {
543 let obj = input.asObject()579 let obj = input.asObject()
544 E(580 E(
545 Float64.fromJSValue(context, obj["p"])581 Float64.fromJSValue(context, obj["p"])
546 )582 )
547 }583 }
548-
549}584}
550 585 
551/*interface F {586/*interface F {
@@ -553,22 +588,20 @@ public open class E <: A {
553 }*/588 }*/
554 589 
555public open class F <: C {590public open class F <: C {
556-
557 protected F(arkts_object: JSObject) { super(arkts_object) }591 protected F(arkts_object: JSObject) { super(arkts_object) }
558- 592+ 
559-
560 /**593 /**
561 * @brief g(): void594 * @brief g(): void
562 */595 */
563 public func g(): Unit {596 public func g(): Unit {
564- jsObjApiCall < Unit >( arkts_object, "g", emptyArg)597+ jsObjApiCall < Unit >( arkts_object, "g", EMPTY_ARG)
565 }598 }
566- 599+ 
567- public open func toJSValue(context: JSContext): JSValue {600+ public open func toJSValue(_: JSContext): JSValue {
568 arkts_object.toJSValue()601 arkts_object.toJSValue()
569 }602 }
570- 603+ 
571- static func fromJSValue(context: JSContext, input: JSValue): F {604+ public static func fromJSValue(_: JSContext, input: JSValue): F {
572 F(input.asObject())605 F(input.asObject())
573 }606 }
574}607}
@@ -593,20 +626,28 @@ interface UserProfile {
593生成的仓颉代码:626生成的仓颉代码:
594 627 
595```cangjie628```cangjie
629+/*interface AutoGenType0 {
630+ city: string;
631+ zipCode: string;
632+ }*/
596 633 
597public open class AutoGenType0 {634public open class AutoGenType0 {
598- 635+ public var city: String
599- protected AutoGenType0(public var : String,636+ public var zipCode: String
600- public var : String) {}637+ protected init(
601- 638+ city: String,
602- 639+ zipCode: String) {
640+ this.city = city
641+ this.zipCode = zipCode
642+ }
643+ 
603 public open func toJSValue(context: JSContext): JSValue {644 public open func toJSValue(context: JSContext): JSValue {
604 let obj = context.object()645 let obj = context.object()
605- obj["city"] = .toJSValue(context)646+ obj["city"] = city.toJSValue(context)
606- obj["zipCode"] = .toJSValue(context)647+ obj["zipCode"] = zipCode.toJSValue(context)
607 obj.toJSValue()648 obj.toJSValue()
608 }649 }
609- 650+ 
610 public static func fromJSValue(context: JSContext, input: JSValue): AutoGenType0 {651 public static func fromJSValue(context: JSContext, input: JSValue): AutoGenType0 {
611 let obj = input.asObject()652 let obj = input.asObject()
612 AutoGenType0(653 AutoGenType0(
@@ -614,17 +655,30 @@ public open class AutoGenType0 {
614 String.fromJSValue(context, obj["zipCode"])655 String.fromJSValue(context, obj["zipCode"])
615 )656 )
616 }657 }
617-
618}658}
619 659 
660+/*interface UserProfile {
661+ id: number;
662+ name: String;
663+ address: {
664+ city: String;
665+ zipCode: String;
666+ };
667+ }*/
620 668 
621public open class UserProfile {669public open class UserProfile {
622- 670+ public var id: Float64
623- protected UserProfile(public var id: Float64,671+ public var name: String
624- public var name: String,672+ public var address: AutoGenType0
625- public var address: AutoGenType0) {}673+ protected init(
626- 674+ id: Float64,
627- 675+ name: String,
676+ address: AutoGenType0) {
677+ this.id = id
678+ this.name = name
679+ this.address = address
680+ }
681+ 
628 public open func toJSValue(context: JSContext): JSValue {682 public open func toJSValue(context: JSContext): JSValue {
629 let obj = context.object()683 let obj = context.object()
630 obj["id"] = id.toJSValue(context)684 obj["id"] = id.toJSValue(context)
@@ -632,7 +686,7 @@ public open class UserProfile {
632 obj["address"] = address.toJSValue(context)686 obj["address"] = address.toJSValue(context)
633 obj.toJSValue()687 obj.toJSValue()
634 }688 }
635- 689+ 
636 public static func fromJSValue(context: JSContext, input: JSValue): UserProfile {690 public static func fromJSValue(context: JSContext, input: JSValue): UserProfile {
637 let obj = input.asObject()691 let obj = input.asObject()
638 UserProfile(692 UserProfile(
@@ -641,7 +695,6 @@ public open class UserProfile {
641 AutoGenType0.fromJSValue(context, obj["address"])695 AutoGenType0.fromJSValue(context, obj["address"])
642 )696 )
643 }697 }
644-
645}698}
646```699```
647 700 
@@ -729,6 +782,60 @@ type ColorAlias = Colors;
729 782 
730```cangjie783```cangjie
731public type ColorAlias = Colors784public type ColorAlias = Colors
785+ 
786+/***********ENUM***********/
787+ 
788+/* enum Colors {
789+ Red = RED,
790+ Green = GREEN,
791+ Blue = BLUE
792+ }*/
793+public enum Colors <: ToString & Equatable < Colors > {
794+ | Red
795+ | Green
796+ | Blue
797+ 
798+ func get(): String {
799+ match(this) {
800+ case Red => "RED"
801+ case Green => "GREEN"
802+ case Blue => "BLUE"
803+ }
804+ }
805+ 
806+ static func parse(val: String): Colors {
807+ match(val) {
808+ case "RED" => Red
809+ case "GREEN" => Green
810+ case "BLUE" => Blue
811+ case _ => throw IllegalArgumentException("unknown value ${val}")
812+ }
813+ }
814+ 
815+ static func tryParse(val: ?String): ?Colors {
816+ match(val) {
817+ case Some(v) => parse(v)
818+ case None => None
819+ }
820+ }
821+ 
822+ public func toString(): String {
823+ get()
824+ }
825+ 
826+ public override operator func ==(that: Colors): Bool {
827+ match((this, that)) {
828+ case(Red, Red) => true
829+ case(Green, Green) => true
830+ case(Blue, Blue) => true
831+ case _ => false
832+ }
833+ }
834+ 
835+ public override operator func !=(that: Colors): Bool {
836+ !(this == that)
837+ }
838+}
732```839```
733 840 
734#### class 类型别名841#### class 类型别名
@@ -749,6 +856,55 @@ public type ColorAlias = Colors
749 856 
750```cangjie857```cangjie
751public type AnimalAlias = Animal858public type AnimalAlias = Animal
859+ 
860+/*class DeclareKeyword Animal {
861+ name: String;
862+ constructor(name: string): void
863+ speak(): void
864+ }*/
865+ 
866+public class Animal {
867+ protected Animal(var arkts_object: JSObject) { }
868+ /**
869+ * @brief constructor(name: string): void
870+ */
871+ public init(name: String) {
872+ arkts_object = checkThreadAndCall < JSObject >(getMainContext()) {
873+ ctx =>
874+ let clazz = getClassConstructorObj("doc_dts_examples_ex_12_Animal", "Animal").toJSValue().asClass()
875+ clazz.new(name.toJSValue(ctx)).asObject()
876+ }
877+ }
878+ 
879+ public mut prop name: String {
880+ get() {
881+ checkThreadAndCall < String >(getMainContext()) {
882+ ctx: JSContext => String.fromJSValue(ctx, arkts_object["name"])
883+ }
884+ }
885+ set(v) {
886+ checkThreadAndCall < Unit >(getMainContext()) {
887+ ctx: JSContext => arkts_object["name"] = v.toJSValue(ctx)
888+ }
889+ }
890+ 
891+ }
892+ 
893+ /**
894+ * @brief speak(): void
895+ */
896+ public func speak(): Unit {
897+ jsObjApiCall < Unit >( arkts_object, "speak", EMPTY_ARG)
898+ }
899+ 
900+ func toJSValue(_: JSContext): JSValue {
901+ arkts_object.toJSValue()
902+ }
903+ 
904+ static func fromJSValue(_: JSContext, input: JSValue): Animal {
905+ Animal(input.asObject())
906+ }
907+}
752```908```
753 909 
754#### 命名空间中的类型的类型别名910#### 命名空间中的类型的类型别名
@@ -778,7 +934,7 @@ type MathOperation = (a: number, b: number) => number;
778生成的仓颉代码:934生成的仓颉代码:
779 935 
780```cangjie936```cangjie
781-public type MathOperation = (a: Float64, b: Float64) -> Float64937+public type MathOperation = (Float64, Float64) -> Float64
782```938```
783 939 
784#### 联合类型别名940#### 联合类型别名
@@ -802,6 +958,16 @@ public enum GreetingLike {
802 case NUMBER(x) => context.number(x).toJSValue()958 case NUMBER(x) => context.number(x).toJSValue()
803 }959 }
804 }960 }
961+ public static func fromJSValue(context: JSContext, input: JSValue): GreetingLike {
962+ 
963+ if (input.isString()) {
964+ return STRING(String.fromJSValue(context, input))
965+ }
966+ if (input.isNumber()) {
967+ return NUMBER(Float64.fromJSValue(context, input))
968+ }
969+ throw Exception("unsupport type!")
970+ }
805}971}
806```972```
807 973 
@@ -853,17 +1019,22 @@ declare class Greeter {
853生成的仓颉代码:1019生成的仓颉代码:
854 1020 
855```cangjie1021```cangjie
856-public class Greeter {1022+/*class DeclareKeyword Greeter {
1023+ greeting: String;
1024+ constructor(greeting: string): void
1025+ showGreeting(): void
1026+ }*/
857 1027 
858- protected Greeter(let arkts_object: JSObject) {}1028+public class Greeter {
1029+ protected Greeter(var arkts_object: JSObject) { }
859 /**1030 /**
860- * @brief constructor(greeting: string): void1031+ * @brief constructor(greeting: string): void
861- */1032+ */
862 public init(greeting: String) {1033 public init(greeting: String) {
863 arkts_object = checkThreadAndCall < JSObject >(getMainContext()) {1034 arkts_object = checkThreadAndCall < JSObject >(getMainContext()) {
864- __ctx =>1035+ ctx =>
865- let clazz = __ctx.global["Greeter"].asClass(__ctx)1036+ let clazz = getClassConstructorObj("_ark_interop_api", "Greeter").toJSValue().asClass()
866- clazz.new(greeting.toJSValue(__ctx)).asObject()1037+ clazz.new(greeting.toJSValue(ctx)).asObject()
867 }1038 }
868 }1039 }
869 1040 
@@ -882,22 +1053,20 @@ public class Greeter {
882 }1053 }
883 1054 
884 /**1055 /**
885- * @brief showGreeting(): void1056+ * @brief showGreeting(): void
886- */1057+ */
887 public func showGreeting(): Unit {1058 public func showGreeting(): Unit {
888- jsObjApiCall < Unit >( arkts_object, "showGreeting", emptyArg)1059+ jsObjApiCall < Unit >( arkts_object, "showGreeting", EMPTY_ARG)
889 }1060 }
890 1061 
891- func toJSValue(context: JSContext): JSValue {1062+ func toJSValue(_: JSContext): JSValue {
892 arkts_object.toJSValue()1063 arkts_object.toJSValue()
893 }1064 }
894 1065 
895- static func fromJSValue (context: JSContext, input: JSValue): Greeter {1066+ static func fromJSValue(_: JSContext, input: JSValue): Greeter {
896 Greeter(input.asObject())1067 Greeter(input.asObject())
897 }1068 }
898}1069}
899- 
900- 
901```1070```
902 1071 
903#### 静态成员1072#### 静态成员
@@ -917,37 +1086,40 @@ declare class MathUtils {
917生成的仓颉代码:1086生成的仓颉代码:
918 1087 
919```cangjie1088```cangjie
1089+/*class DeclareKeyword MathUtils {
1090+ StaticKeywordPI: number;
1091+ square(x: number): number
1092+ }*/
1093+ 
920public class MathUtils {1094public class MathUtils {
1095+ protected MathUtils(var arkts_object: JSObject) { }
921 1096 
922- protected MathUtils(let arkts_object: JSObject) {}1097+ public static mut prop PI: Float64 {
923- 
924- // 静态属性
925- public mut prop PI: Float64 {
926 get() {1098 get() {
927 checkThreadAndCall < Float64 >(getMainContext()) {1099 checkThreadAndCall < Float64 >(getMainContext()) {
928- ctx: JSContext => Float64.fromJSValue(ctx, getClassConstructorObj("test", "MathUtils")["PI"])1100+ ctx: JSContext => Float64.fromJSValue(ctx, getClassConstructorObj("_ark_interop_api", "MathUtils")["PI"])
929 }1101 }
930 }1102 }
931 set(v) {1103 set(v) {
932 checkThreadAndCall < Unit >(getMainContext()) {1104 checkThreadAndCall < Unit >(getMainContext()) {
933- ctx: JSContext => getClassConstructorObj("test", "MathUtils")["PI"] = v.toJSValue(ctx)1105+ ctx: JSContext => getClassConstructorObj("_ark_interop_api", "MathUtils")["PI"] = v.toJSValue(ctx)
934 }1106 }
935 }1107 }
936 1108 
937 }1109 }
938 1110 
939 /**1111 /**
940- * @brief square(x: number): number1112+ * @brief square(x: number): number
941- */1113+ */
942 public static func square(x: Float64): Float64 {1114 public static func square(x: Float64): Float64 {
943- jsObjApiCall < Float64 >(getClassConstructorObj("test", "MathUtils"), "square", { ctx =>[x.toJSValue(ctx)] })1115+ jsObjApiCall < Float64 >(getClassConstructorObj("_ark_interop_api", "MathUtils"), "square", { ctx =>[x.toJSValue(ctx)] })
944 }1116 }
945 1117 
946- func toJSValue(context: JSContext): JSValue {1118+ func toJSValue(_: JSContext): JSValue {
947 arkts_object.toJSValue()1119 arkts_object.toJSValue()
948 }1120 }
949 1121 
950- static func fromJSValue (context: JSContext, input: JSValue): MathUtils {1122+ static func fromJSValue(_: JSContext, input: JSValue): MathUtils {
951 MathUtils(input.asObject())1123 MathUtils(input.asObject())
952 }1124 }
953}1125}
@@ -968,15 +1140,17 @@ declare class Person {
968生成的仓颉代码:1140生成的仓颉代码:
969 1141 
970```cangjie1142```cangjie
971-public class Person {1143+/*class DeclareKeyword Person {
972- // 不需要生成私有成员属性1144+ }*/
973- protected Person(let arkts_object: JSObject) {}
974 1145 
975- func toJSValue(context: JSContext): JSValue {1146+public class Person {
1147+ protected Person(var arkts_object: JSObject) { }
1148+ 
1149+ func toJSValue(_: JSContext): JSValue {
976 arkts_object.toJSValue()1150 arkts_object.toJSValue()
977 }1151 }
978 1152 
979- static func fromJSValue (context: JSContext, input: JSValue): Person {1153+ static func fromJSValue(_: JSContext, input: JSValue): Person {
980 Person(input.asObject())1154 Person(input.asObject())
981 }1155 }
982}1156}
@@ -999,11 +1173,14 @@ declare class AnimalProtect {
999生成的仓颉代码:1173生成的仓颉代码:
1000 1174 
1001```cangjie1175```cangjie
1176+/*class DeclareKeyword AnimalProtect {
1177+ ProtectedKeywordname: String;
1178+ makeSound(): void
1179+ }*/
1180+ 
1002public class AnimalProtect {1181public class AnimalProtect {
1182+ protected AnimalProtect(var arkts_object: JSObject) { }
1003 1183 
1004- protected AnimalProtect(let arkts_object: JSObject) {}
1005- 
1006- // 受保护属性
1007 public mut prop name: String {1184 public mut prop name: String {
1008 get() {1185 get() {
1009 checkThreadAndCall < String >(getMainContext()) {1186 checkThreadAndCall < String >(getMainContext()) {
@@ -1019,17 +1196,17 @@ public class AnimalProtect {
1019 }1196 }
1020 1197 
1021 /**1198 /**
1022- * @brief makeSound(): void1199+ * @brief makeSound(): void
1023- */1200+ */
1024 public func makeSound(): Unit {1201 public func makeSound(): Unit {
1025- jsObjApiCall < Unit >( arkts_object, "makeSound", emptyArg)1202+ jsObjApiCall < Unit >( arkts_object, "makeSound", EMPTY_ARG)
1026 }1203 }
1027 1204 
1028- func toJSValue(context: JSContext): JSValue {1205+ func toJSValue(_: JSContext): JSValue {
1029 arkts_object.toJSValue()1206 arkts_object.toJSValue()
1030 }1207 }
1031 1208 
1032- static func fromJSValue (context: JSContext, input: JSValue): AnimalProtect {1209+ static func fromJSValue(_: JSContext, input: JSValue): AnimalProtect {
1033 AnimalProtect(input.asObject())1210 AnimalProtect(input.asObject())
1034 }1211 }
1035}1212}
@@ -1050,11 +1227,14 @@ declare class Car {
1050生成的仓颉代码:1227生成的仓颉代码:
1051 1228 
1052```cangjie1229```cangjie
1230+/*class DeclareKeyword Car {
1231+ ReadonlyKeywordbrand: String;
1232+ name: String;
1233+ }*/
1234+ 
1053public class Car {1235public class Car {
1236+ protected Car(var arkts_object: JSObject) { }
1054 1237 
1055- protected Car(let arkts_object: JSObject) {}
1056- 
1057- // 只读属性
1058 public prop brand: String {1238 public prop brand: String {
1059 get() {1239 get() {
1060 checkThreadAndCall < String >(getMainContext()) {1240 checkThreadAndCall < String >(getMainContext()) {
@@ -1077,12 +1257,11 @@ public class Car {
1077 1257 
1078 }1258 }
1079 1259 
1080- 1260+ func toJSValue(_: JSContext): JSValue {
1081- func toJSValue(context: JSContext): JSValue {
1082 arkts_object.toJSValue()1261 arkts_object.toJSValue()
1083 }1262 }
1084 1263 
1085- static func fromJSValue (context: JSContext, input: JSValue): Car {1264+ static func fromJSValue(_: JSContext, input: JSValue): Car {
1086 Car(input.asObject())1265 Car(input.asObject())
1087 }1266 }
1088}1267}
@@ -1104,11 +1283,14 @@ declare class Box<T> {
1104生成的仓颉代码:1283生成的仓颉代码:
1105 1284 
1106```cangjie1285```cangjie
1107-public class Box<T> {1286+/*class DeclareKeyword Box {
1287+ value: T;
1288+ getValue(): T
1289+ }*/
1108 1290 
1109- protected Box(let arkts_object: JSObject) {}1291+public class Box<T> where T <: JSInteropType<T> {
1292+ protected Box(var arkts_object: JSObject) { }
1110 1293 
1111- // 属性
1112 public mut prop value: T {1294 public mut prop value: T {
1113 get() {1295 get() {
1114 checkThreadAndCall < T >(getMainContext()) {1296 checkThreadAndCall < T >(getMainContext()) {
@@ -1124,19 +1306,17 @@ public class Box<T> {
1124 }1306 }
1125 1307 
1126 /**1308 /**
1127- * @brief getValue(): T1309+ * @brief getValue(): T
1128- */1310+ */
1129 public func getValue(): T {1311 public func getValue(): T {
1130- jsObjApiCall < T >( arkts_object, "getValue", emptyArg) {1312+ jsObjApiCall < T >( arkts_object, "getValue", EMPTY_ARG) { ctx, info => T.fromJSValue(ctx, info) }
1131- ctx, info => T.fromJSValue(ctx, info)
1132- }
1133 }1313 }
1134 1314 
1135- func toJSValue(context: JSContext): JSValue {1315+ func toJSValue(_: JSContext): JSValue {
1136 arkts_object.toJSValue()1316 arkts_object.toJSValue()
1137 }1317 }
1138 1318 
1139- static func fromJSValue <T>(context: JSContext, input: JSValue): Box<T> {1319+ static func fromJSValue(_: JSContext, input: JSValue): Box<T> {
1140 Box(input.asObject())1320 Box(input.asObject())
1141 }1321 }
1142}1322}
@@ -1156,22 +1336,25 @@ declare abstract class Shape {
1156生成的仓颉代码:1336生成的仓颉代码:
1157 1337 
1158```cangjie1338```cangjie
1159-public open class Shape {1339+/*class DeclareKeyword FirstContextualKeyword Shape {
1340+ getArea(): number
1341+ }*/
1160 1342 
1161- protected Shape(let arkts_object: JSObject) {}1343+public open class Shape {
1344+ protected Shape(var arkts_object: JSObject) { }
1162 1345 
1163 /**1346 /**
1164- * @brief getArea(): number1347+ * @brief getArea(): number
1165- */1348+ */
1166 public func getArea(): Float64 {1349 public func getArea(): Float64 {
1167- jsObjApiCall < Float64 >( arkts_object, "getArea", emptyArg)1350+ jsObjApiCall < Float64 >( arkts_object, "getArea", EMPTY_ARG)
1168 }1351 }
1169 1352 
1170- func toJSValue(context: JSContext): JSValue {1353+ public open func toJSValue(_: JSContext): JSValue {
1171 arkts_object.toJSValue()1354 arkts_object.toJSValue()
1172 }1355 }
1173 1356 
1174- static func fromJSValue (context: JSContext, input: JSValue): Shape {1357+ public static func fromJSValue(_: JSContext, input: JSValue): Shape {
1175 Shape(input.asObject())1358 Shape(input.asObject())
1176 }1359 }
1177}1360}
@@ -1196,56 +1379,50 @@ declare class Car implements Drivable {
1196生成的仓颉代码:1379生成的仓颉代码:
1197 1380 
1198```cangjie1381```cangjie
1199-public class Drivable {1382+/*interface Drivable {
1200- 1383+ start(): void
1201- protected Drivable(let arkts_object: JSObject) {}1384+ stop(): void
1385+ }*/
1202 1386 
1387+public open class Drivable {
1388+ protected Drivable(var arkts_object: JSObject) { }
1203 1389 
1204 /**1390 /**
1205- * @brief start(): void1391+ * @brief start(): void
1206- */1392+ */
1207 public func start(): Unit {1393 public func start(): Unit {
1208- jsObjApiCall < Unit >( arkts_object, "start", emptyArg)1394+ jsObjApiCall < Unit >( arkts_object, "start", EMPTY_ARG)
1209 }1395 }
1210 /**1396 /**
1211- * @brief stop(): void1397+ * @brief stop(): void
1212- */1398+ */
1213 public func stop(): Unit {1399 public func stop(): Unit {
1214- jsObjApiCall < Unit >( arkts_object, "stop", emptyArg)1400+ jsObjApiCall < Unit >( arkts_object, "stop", EMPTY_ARG)
1215 }1401 }
1216 1402 
1217- func toJSValue(context: JSContext): JSValue {1403+ public open func toJSValue(_: JSContext): JSValue {
1218 arkts_object.toJSValue()1404 arkts_object.toJSValue()
1219 }1405 }
1220 1406 
1221- static func fromJSValue (context: JSContext, input: JSValue): Drivable {1407+ public static func fromJSValue(_: JSContext, input: JSValue): Drivable {
1222 Drivable(input.asObject())1408 Drivable(input.asObject())
1223 }1409 }
1224}1410}
1225-public class Car1 <: Drivable {
1226 1411 
1227- protected Car1(arkts_object: JSObject) {}1412+/*class DeclareKeyword Car {
1413+ start(): void
1414+ stop(): void
1415+ }*/
1228 1416 
1417+public class Car <: Drivable {
1418+ protected Car(arkts_object: JSObject) { super(arkts_object) }
1229 1419 
1230- /**1420+ public func toJSValue(_: JSContext): JSValue {
1231- * @brief start(): void
1232- */
1233- public func start(): Unit {
1234- jsObjApiCall < Unit >( arkts_object, "start", emptyArg)
1235- }
1236- /**
1237- * @brief stop(): void
1238- */
1239- public func stop(): Unit {
1240- jsObjApiCall < Unit >( arkts_object, "stop", emptyArg)
1241- }
1242- 
1243- func toJSValue(context: JSContext): JSValue {
1244 arkts_object.toJSValue()1421 arkts_object.toJSValue()
1245 }1422 }
1246 1423 
1247- static func fromJSValue (context: JSContext, input: JSValue): Car1 {1424+ public static func fromJSValue(_: JSContext, input: JSValue): Car {
1248- Car1(input.asObject())1425+ Car(input.asObject())
1249 }1426 }
1250}1427}
1251```1428```
@@ -1271,18 +1448,22 @@ declare class Dog extends Animal {
1271生成的仓颉代码:1448生成的仓颉代码:
1272 1449 
1273```cangjie1450```cangjie
1274-public class Animal1 {1451+/*class DeclareKeyword Animal {
1452+ name: String;
1453+ constructor(name: string): void
1454+ move(distance: number): void
1455+ }*/
1275 1456 
1276- protected Animal1(let arkts_object: JSObject) {}1457+public open class Animal {
1458+ protected Animal(var arkts_object: JSObject) { }
1277 /**1459 /**
1278- * @brief constructor(name: string): void1460+ * @brief constructor(name: string): void
1279- */1461+ */
1280 public init(name: String) {1462 public init(name: String) {
1281 arkts_object = checkThreadAndCall < JSObject >(getMainContext()) {1463 arkts_object = checkThreadAndCall < JSObject >(getMainContext()) {
1282- __ctx =>1464+ ctx =>
1283- let module = getJSModule(__ctx, "test", None)1465+ let clazz = getClassConstructorObj("_ark_interop_api", "Animal").toJSValue().asClass()
1284- let clazz = module["Animal1"].asClass(__ctx)1466+ clazz.new(name.toJSValue(ctx)).asObject()
1285- clazz.new(name.toJSValue(__ctx)).asObject()
1286 }1467 }
1287 }1468 }
1288 1469 
@@ -1301,37 +1482,40 @@ public class Animal1 {
1301 }1482 }
1302 1483 
1303 /**1484 /**
1304- * @brief move(distance: number): void1485+ * @brief move(distance: number): void
1305- */1486+ */
1306 public func move(distance: Float64): Unit {1487 public func move(distance: Float64): Unit {
1307 jsObjApiCall < Unit >( arkts_object, "move", { ctx =>[distance.toJSValue(ctx)] })1488 jsObjApiCall < Unit >( arkts_object, "move", { ctx =>[distance.toJSValue(ctx)] })
1308 }1489 }
1309 1490 
1310- func toJSValue(context: JSContext): JSValue {1491+ public open func toJSValue(_: JSContext): JSValue {
1311 arkts_object.toJSValue()1492 arkts_object.toJSValue()
1312 }1493 }
1313 1494 
1314- static func fromJSValue (context: JSContext, input: JSValue): Animal1 {1495+ public static func fromJSValue(_: JSContext, input: JSValue): Animal {
1315- Animal1(input.asObject())1496+ Animal(input.asObject())
1316 }1497 }
1317}1498}
1318-public class Dog <: Animal1 {
1319 1499 
1320- protected Dog(arkts_object: JSObject) {}1500+/*class DeclareKeyword Dog {
1501+ bark(): void
1502+ }*/
1321 1503 
1504+public class Dog <: Animal {
1505+ protected Dog(arkts_object: JSObject) { super(arkts_object) }
1322 1506 
1323 /**1507 /**
1324- * @brief bark(): void1508+ * @brief bark(): void
1325- */1509+ */
1326 public func bark(): Unit {1510 public func bark(): Unit {
1327- jsObjApiCall < Unit >( arkts_object, "bark", emptyArg)1511+ jsObjApiCall < Unit >( arkts_object, "bark", EMPTY_ARG)
1328 }1512 }
1329 1513 
1330- func toJSValue(context: JSContext): JSValue {1514+ public func toJSValue(_: JSContext): JSValue {
1331 arkts_object.toJSValue()1515 arkts_object.toJSValue()
1332 }1516 }
1333 1517 
1334- static func fromJSValue (context: JSContext, input: JSValue): Dog {1518+ public static func fromJSValue(_: JSContext, input: JSValue): Dog {
1335 Dog(input.asObject())1519 Dog(input.asObject())
1336 }1520 }
1337}1521}
@@ -1355,37 +1539,39 @@ declare class Calculator {
1355生成的仓颉代码:1539生成的仓颉代码:
1356 1540 
1357```cangjie1541```cangjie
1542+/*class DeclareKeyword Calculator {
1543+ add(x: number, y: number): number
1544+ add(x: string, y: string): String
1545+ add(x: any, y: any): any
1546+ }*/
1547+ 
1358public class Calculator {1548public class Calculator {
1359- 1549+ protected Calculator(var arkts_object: JSObject) { }
1360- protected Calculator(let arkts_object: JSObject) {}
1361- 
1362 1550 
1363 /**1551 /**
1364- * @brief add(x: number,y: number): number1552+ * @brief add(x: number, y: number): number
1365- */1553+ */
1366 public func add(x: Float64, y: Float64): Float64 {1554 public func add(x: Float64, y: Float64): Float64 {
1367 jsObjApiCall < Float64 >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })1555 jsObjApiCall < Float64 >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })
1368 }1556 }
1369 /**1557 /**
1370- * @brief add(x: string,y: string): String1558+ * @brief add(x: string, y: string): String
1371- */1559+ */
1372 public func add(x: String, y: String): String {1560 public func add(x: String, y: String): String {
1373 jsObjApiCall < String >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })1561 jsObjApiCall < String >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] })
1374 }1562 }
1375 /**1563 /**
1376- * @brief add(x: any,y: any): any1564+ * @brief add(x: any, y: any): any
1377- */1565+ */
1378- public func add(x: Any, y: Any): any {1566+ public func add(x: JSValue/* FIXME: `any` */, y: JSValue/* FIXME: `any` */): JSValue/* FIXME: `any` */ {
1379- jsObjApiCall < any >( arkts_object, "add", { ctx =>[x.toJSValue(ctx), y.toJSValue(ctx)] }) {1567+ jsObjApiCall < JSValue/* FIXME: `any` */ >( arkts_object, "add", { ctx =>[x, y] }) { ctx, info => info }
1380- ctx, info => any.fromJSValue(ctx, info)
1381- }
1382 }1568 }
1383 1569 
1384- func toJSValue(context: JSContext): JSValue {1570+ func toJSValue(_: JSContext): JSValue {
1385 arkts_object.toJSValue()1571 arkts_object.toJSValue()
1386 }1572 }
1387 1573 
1388- static func fromJSValue (context: JSContext, input: JSValue): Calculator {1574+ static func fromJSValue(_: JSContext, input: JSValue): Calculator {
1389 Calculator(input.asObject())1575 Calculator(input.asObject())
1390 }1576 }
1391}1577}
@@ -1446,6 +1632,13 @@ declare enum Colors {
1446生成的仓颉代码:1632生成的仓颉代码:
1447 1633 
1448```cangjie1634```cangjie
1635+/***********ENUM***********/
1636+ 
1637+/* enum Colors {
1638+ Red = RED,
1639+ Green = GREEN,
1640+ Blue = BLUE
1641+ }*/
1449public enum Colors <: ToString & Equatable < Colors > {1642public enum Colors <: ToString & Equatable < Colors > {
1450 | Red1643 | Red
1451 | Green1644 | Green
@@ -1510,6 +1703,13 @@ declare enum Status {
1510生成的仓颉代码:1703生成的仓颉代码:
1511 1704 
1512```cangjie1705```cangjie
1706+/***********ENUM***********/
1707+ 
1708+/* enum Status {
1709+ Pending,
1710+ Approved,
1711+ Rejected
1712+ }*/
1513public enum Status <: ToString & Equatable < Status > {1713public enum Status <: ToString & Equatable < Status > {
1514 | Pending1714 | Pending
1515 | Approved1715 | Approved
@@ -1578,6 +1778,13 @@ declare const enum Status {
1578生成的仓颉代码:1778生成的仓颉代码:
1579 1779 
1580```cangjie1780```cangjie
1781+/***********ENUM***********/
1782+ 
1783+/* enum Status {
1784+ Pending = 3,
1785+ Approved = 4,
1786+ Rejected = 5
1787+ }*/
1581public enum Status <: ToString & Equatable < Status > {1788public enum Status <: ToString & Equatable < Status > {
1582 | Pending1789 | Pending
1583 | Approved1790 | Approved
@@ -1645,6 +1852,12 @@ declare enum Response {
1645生成的仓颉代码:1852生成的仓颉代码:
1646 1853 
1647```cangjie1854```cangjie
1855+/***********ENUM***********/
1856+ 
1857+/* enum Response {
1858+ No = 0,
1859+ Yes = YES
1860+ }*/
1648public enum Response <: ToString & Equatable < Response > {1861public enum Response <: ToString & Equatable < Response > {
1649 | No1862 | No
1650 | Yes1863 | Yes
@@ -1757,26 +1970,63 @@ interface BasicTypes {
1757生成的仓颉代码:1970生成的仓颉代码:
1758 1971 
1759```cangjie1972```cangjie
1760-public class BasicTypes {1973+/*interface BasicTypes {
1974+ numberKeyword: number;
1975+ stringKeyword: String;
1976+ booleanKeyword: boolean;
1977+ bigintKeyword: bigint;
1978+ objectKeyword: object;
1979+ symbolKeyword: symbol;
1980+ voidKeyword: void;
1981+ undefinedKeyword: undefined;
1982+ anyKeyword: any;
1983+ unknownKeyword: unknown;
1984+ neverKeyword: never;
1985+ }*/
1761 1986 
1762- protected BasicTypes(public var numberKeyword: Float64,1987+public open class BasicTypes {
1763- public var stringKeyword: String,1988+ public var numberKeyword: Float64
1764- public var booleanKeyword: Bool,1989+ public var stringKeyword: String
1765- public var bigintKeyword: BigInt,1990+ public var booleanKeyword: Bool
1766- public var objectKeyword: JSValue/* FIXME: `object` */,1991+ public var bigintKeyword: BigInt
1767- public var symbolKeyword: JSValue/* FIXME: `symbol` */,1992+ public var objectKeyword: JSValue/* FIXME: `object` */
1768- public var voidKeyword: Unit,1993+ public var symbolKeyword: JSValue/* FIXME: `symbol` */
1769- public var undefinedKeyword: JSValue/* FIXME: `undefined` */,1994+ public var voidKeyword: Unit
1770- public var anyKeyword: JSValue/* FIXME: `any` */,1995+ public var undefinedKeyword: JSValue/* FIXME: `undefined` */
1771- public var unknownKeyword: JSValue/* FIXME: `unknown` */,1996+ public var anyKeyword: JSValue/* FIXME: `any` */
1772- public var neverKeyword: JSValue/* FIXME: `never` */) {}1997+ public var unknownKeyword: JSValue/* FIXME: `unknown` */
1998+ public var neverKeyword: JSValue/* FIXME: `never` */
1999+ protected init(
2000+ numberKeyword: Float64,
2001+ stringKeyword: String,
2002+ booleanKeyword: Bool,
2003+ bigintKeyword: BigInt,
2004+ objectKeyword: JSValue/* FIXME: `object` */,
2005+ symbolKeyword: JSValue/* FIXME: `symbol` */,
2006+ voidKeyword: Unit,
2007+ undefinedKeyword: JSValue/* FIXME: `undefined` */,
2008+ anyKeyword: JSValue/* FIXME: `any` */,
2009+ unknownKeyword: JSValue/* FIXME: `unknown` */,
2010+ neverKeyword: JSValue/* FIXME: `never` */) {
2011+ this.numberKeyword = numberKeyword
2012+ this.stringKeyword = stringKeyword
2013+ this.booleanKeyword = booleanKeyword
2014+ this.bigintKeyword = bigintKeyword
2015+ this.objectKeyword = objectKeyword
2016+ this.symbolKeyword = symbolKeyword
2017+ this.voidKeyword = voidKeyword
2018+ this.undefinedKeyword = undefinedKeyword
2019+ this.anyKeyword = anyKeyword
2020+ this.unknownKeyword = unknownKeyword
2021+ this.neverKeyword = neverKeyword
2022+ }
1773 2023 
1774- public func toJSValue(context: JSContext): JSValue {2024+ public open func toJSValue(context: JSContext): JSValue {
1775 let obj = context.object()2025 let obj = context.object()
1776 obj["numberKeyword"] = numberKeyword.toJSValue(context)2026 obj["numberKeyword"] = numberKeyword.toJSValue(context)
1777 obj["stringKeyword"] = stringKeyword.toJSValue(context)2027 obj["stringKeyword"] = stringKeyword.toJSValue(context)
1778 obj["booleanKeyword"] = booleanKeyword.toJSValue(context)2028 obj["booleanKeyword"] = booleanKeyword.toJSValue(context)
1779- obj["bigintKeyword"] = context.bigint(bigintKeyword).toJSValue(context)2029+ obj["bigintKeyword"] = context.bigint(bigintKeyword).toJSValue()
1780 obj["objectKeyword"] = objectKeyword2030 obj["objectKeyword"] = objectKeyword
1781 obj["symbolKeyword"] = symbolKeyword2031 obj["symbolKeyword"] = symbolKeyword
1782 obj["voidKeyword"] = voidKeyword.toJSValue(context)2032 obj["voidKeyword"] = voidKeyword.toJSValue(context)
@@ -1787,23 +2037,22 @@ public class BasicTypes {
1787 obj.toJSValue()2037 obj.toJSValue()
1788 }2038 }
1789 2039 
1790- public static func fromJSValue (context: JSContext, input: JSValue): BasicTypes {2040+ public static func fromJSValue(context: JSContext, input: JSValue): BasicTypes {
1791 let obj = input.asObject()2041 let obj = input.asObject()
1792 BasicTypes(2042 BasicTypes(
1793 Float64.fromJSValue(context, obj["numberKeyword"]),2043 Float64.fromJSValue(context, obj["numberKeyword"]),
1794 String.fromJSValue(context, obj["stringKeyword"]),2044 String.fromJSValue(context, obj["stringKeyword"]),
1795 Bool.fromJSValue(context, obj["booleanKeyword"]),2045 Bool.fromJSValue(context, obj["booleanKeyword"]),
1796- obj["bigintKeyword"].asBigInt(context).toBigInt(),2046+ obj["bigintKeyword"].asBigInt().toBigInt(),
1797- JSValue/* FIXME: `object` */.fromJSValue(context, obj["objectKeyword"]),2047+ obj["objectKeyword"],
1798- JSValue/* FIXME: `symbol` */.fromJSValue(context, obj["symbolKeyword"]),2048+ obj["symbolKeyword"],
1799 Unit.fromJSValue(context, obj["voidKeyword"]),2049 Unit.fromJSValue(context, obj["voidKeyword"]),
1800- JSValue/* FIXME: `undefined` */.fromJSValue(context, obj["undefinedKeyword"]),2050+ obj["undefinedKeyword"],
1801- JSValue/* FIXME: `any` */.fromJSValue(context, obj["anyKeyword"]),2051+ obj["anyKeyword"],
1802- JSValue/* FIXME: `unknown` */.fromJSValue(context, obj["unknownKeyword"]),2052+ obj["unknownKeyword"],
1803- JSValue/* FIXME: `never` */.fromJSValue(context, obj["neverKeyword"])2053+ obj["neverKeyword"]
1804 )2054 )
1805 }2055 }
1806- 
1807}2056}
1808```2057```
1809 2058 
@@ -1834,33 +2083,47 @@ interface arrayInterface {
1834生成的仓颉代码:2083生成的仓颉代码:
1835 2084 
1836```cangjie2085```cangjie
1837-public class arrayInterface {2086+/*interface arrayInterface {
2087+ arrayType1: number[];
2088+ arrayType2: Uint8Array;
2089+ arrayType3: ArrayBuffer;
2090+ arrayType4: Float32Array;
2091+ }*/
1838 2092 
1839- protected arrayInterface(public var arrayType1: Array<Float64>,2093+public open class arrayInterface {
1840- public var arrayType2: Array<UInt8>,2094+ public var arrayType1: Array<Float64>
1841- public var arrayType3: Array<UInt8>,2095+ public var arrayType2: Array<UInt8>
1842- public var arrayType4: Array<Float32>) {}2096+ public var arrayType3: Array<UInt8>
2097+ public var arrayType4: Array<Float32>
2098+ protected init(
2099+ arrayType1: Array<Float64>,
2100+ arrayType2: Array<UInt8>,
2101+ arrayType3: Array<UInt8>,
2102+ arrayType4: Array<Float32>) {
2103+ this.arrayType1 = arrayType1
2104+ this.arrayType2 = arrayType2
2105+ this.arrayType3 = arrayType3
2106+ this.arrayType4 = arrayType4
2107+ }
1843 2108 
1844- 2109+ public open func toJSValue(context: JSContext): JSValue {
1845- public func toJSValue(context: JSContext): JSValue {
1846 let obj = context.object()2110 let obj = context.object()
1847- obj["arrayType1"] = toJSArray(context, arrayType1)2111+ obj["arrayType1"] = toJSArray < Float64 >(context, arrayType1)
1848- obj["arrayType2"] = toJSArray(context, arrayType2, { ctx: JSContext, val: UInt8 => val.toJSValue(ctx) })2112+ obj["arrayType2"] = toJSArray < UInt8 >(context, arrayType2, { ctx: JSContext, val: UInt8 => val.toJSValue(ctx) })
1849- obj["arrayType3"] = toJSArray(context, arrayType3, { ctx: JSContext, val: UInt8 => val.toJSValue(ctx) })2113+ obj["arrayType3"] = toJSArray < UInt8 >(context, arrayType3, { ctx: JSContext, val: UInt8 => val.toJSValue(ctx) })
1850- obj["arrayType4"] = toJSArray(context, arrayType4, { ctx: JSContext, val: Float32 => val.toJSValue(ctx) })2114+ obj["arrayType4"] = toJSArray < Float32 >(context, arrayType4, { ctx: JSContext, val: Float32 => val.toJSValue(ctx) })
1851 obj.toJSValue()2115 obj.toJSValue()
1852 }2116 }
1853 2117 
1854- public static func fromJSValue (context: JSContext, input: JSValue): arrayInterface {2118+ public static func fromJSValue(context: JSContext, input: JSValue): arrayInterface {
1855 let obj = input.asObject()2119 let obj = input.asObject()
1856 arrayInterface(2120 arrayInterface(
1857 fromJSArray < Float64 >(context, obj["arrayType1"]),2121 fromJSArray < Float64 >(context, obj["arrayType1"]),
1858- fromJSArray(context, obj["arrayType2"], { ctx: JSContext, val: JSValue => UInt8.fromJSValue(ctx, val) }),2122+ fromJSArray < UInt8 >(context, obj["arrayType2"], { ctx: JSContext, val: JSValue => UInt8.fromJSValue(ctx, val) }),
1859- fromJSArray(context, obj["arrayType3"], { ctx: JSContext, val: JSValue => UInt8.fromJSValue(ctx, val) }),2123+ fromJSArray < UInt8 >(context, obj["arrayType3"], { ctx: JSContext, val: JSValue => UInt8.fromJSValue(ctx, val) }),
1860- fromJSArray(context, obj["arrayType4"], { ctx: JSContext, val: JSValue => Float32.fromJSValue(ctx, val) })2124+ fromJSArray < Float32 >(context, obj["arrayType4"], { ctx: JSContext, val: JSValue => Float32.fromJSValue(ctx, val) })
1861 )2125 )
1862 }2126 }
1863- 
1864}2127}
1865```2128```
1866 2129 
@@ -1888,46 +2151,64 @@ interface TestListener {
1888生成的仓颉代码:2151生成的仓颉代码:
1889 2152 
1890```cangjie2153```cangjie
1891-public class TestListener {2154+/*interface TestListener {
2155+ onStart?: () => void;
2156+ onDestroy?: () => void;
2157+ onError?: (code: ErrorCode, msg: String) => void;
2158+ onTouch?: () => void;
2159+ onEvent?: (e: EventType) => void;
2160+ }*/
1892 2161 
1893- protected TestListener(public var onStart!: Option<() -> Unit> = None,2162+public open class TestListener {
1894- public var onDestroy!: Option<() -> Unit> = None,2163+ public var onStart: Option<() -> Unit> = None
1895- public var onError!: Option<(code: ErrorCode, msg: String) -> Unit> = None,2164+ public var onDestroy: Option<() -> Unit> = None
1896- public var onTouch!: Option<() -> Unit> = None,2165+ public var onError: Option<(JSValue/* FIXME: `ErrorCode` */, String) -> Unit> = None
1897- public var onEvent!: Option<(e: EventType) -> Unit> = None) {}2166+ public var onTouch: Option<() -> Unit> = None
2167+ public var onEvent: Option<(JSValue/* FIXME: `EventType` */) -> Unit> = None
2168+ protected init(
2169+ onStart!: Option<() -> Unit> = None,
2170+ onDestroy!: Option<() -> Unit> = None,
2171+ onError!: Option<(JSValue/* FIXME: `ErrorCode` */, String) -> Unit> = None,
2172+ onTouch!: Option<() -> Unit> = None,
2173+ onEvent!: Option<(JSValue/* FIXME: `EventType` */) -> Unit> = None) {
2174+ this.onStart = onStart
2175+ this.onDestroy = onDestroy
2176+ this.onError = onError
2177+ this.onTouch = onTouch
2178+ this.onEvent = onEvent
2179+ }
1898 2180 
1899- 2181+ public open func toJSValue(context: JSContext): JSValue {
1900- public func toJSValue(context: JSContext): JSValue {
1901 let obj = context.object()2182 let obj = context.object()
1902- if(let Some(v) <- onStart) {2183+ if (let Some(v) <- onStart) {
1903 obj["onStart"] = context.function({ ctx, _ =>2184 obj["onStart"] = context.function({ ctx, _ =>
1904 v()2185 v()
1905 ctx.undefined().toJSValue()2186 ctx.undefined().toJSValue()
1906 }).toJSValue()2187 }).toJSValue()
1907 }2188 }
1908- if(let Some(v) <- onDestroy) {2189+ if (let Some(v) <- onDestroy) {
1909 obj["onDestroy"] = context.function({ ctx, _ =>2190 obj["onDestroy"] = context.function({ ctx, _ =>
1910 v()2191 v()
1911 ctx.undefined().toJSValue()2192 ctx.undefined().toJSValue()
1912 }).toJSValue()2193 }).toJSValue()
1913 }2194 }
1914- if(let Some(v) <- onError) {2195+ if (let Some(v) <- onError) {
1915 obj["onError"] = context.function({ ctx, info =>2196 obj["onError"] = context.function({ ctx, info =>
1916- let p0 = ErrorCode.fromJSValue(ctx, info[0])2197+ let p0 = info[0]
1917 let p1 = String.fromJSValue(ctx, info[1])2198 let p1 = String.fromJSValue(ctx, info[1])
1918 v(p0, p1)2199 v(p0, p1)
1919 ctx.undefined().toJSValue()2200 ctx.undefined().toJSValue()
1920 }).toJSValue()2201 }).toJSValue()
1921 }2202 }
1922- if(let Some(v) <- onTouch) {2203+ if (let Some(v) <- onTouch) {
1923 obj["onTouch"] = context.function({ ctx, _ =>2204 obj["onTouch"] = context.function({ ctx, _ =>
1924 v()2205 v()
1925 ctx.undefined().toJSValue()2206 ctx.undefined().toJSValue()
1926 }).toJSValue()2207 }).toJSValue()
1927 }2208 }
1928- if(let Some(v) <- onEvent) {2209+ if (let Some(v) <- onEvent) {
1929 obj["onEvent"] = context.function({ ctx, info =>2210 obj["onEvent"] = context.function({ ctx, info =>
1930- let p0 = EventType.parse(Int32.fromJSValue(ctx, info[0]))2211+ let p0 = info[0]
1931 v(p0)2212 v(p0)
1932 ctx.undefined().toJSValue()2213 ctx.undefined().toJSValue()
1933 }).toJSValue()2214 }).toJSValue()
@@ -1935,10 +2216,10 @@ public class TestListener {
1935 obj.toJSValue()2216 obj.toJSValue()
1936 }2217 }
1937 2218 
1938- public static func fromJSValue (context: JSContext, input: JSValue): TestListener {2219+ public static func fromJSValue(context: JSContext, input: JSValue): TestListener {
1939 let obj = input.asObject()2220 let obj = input.asObject()
1940 TestListener(2221 TestListener(
1941- onStart: if(obj["onStart"].isUndefined()) {2222+ onStart: if (obj["onStart"].isUndefined()) {
1942 None2223 None
1943 } else {2224 } else {
1944 { =>2225 { =>
@@ -1947,7 +2228,7 @@ public class TestListener {
1947 })2228 })
1948 }2229 }
1949 },2230 },
1950- onDestroy: if(obj["onDestroy"].isUndefined()) {2231+ onDestroy: if (obj["onDestroy"].isUndefined()) {
1951 None2232 None
1952 } else {2233 } else {
1953 { =>2234 { =>
@@ -1956,18 +2237,18 @@ public class TestListener {
1956 })2237 })
1957 }2238 }
1958 },2239 },
1959- onError: if(obj["onError"].isUndefined()) {2240+ onError: if (obj["onError"].isUndefined()) {
1960 None2241 None
1961 } else {2242 } else {
1962- { code: ErrorCode, msg: String =>2243+ { code: JSValue/* FIXME: `ErrorCode` */, msg: String =>
1963 checkThreadAndCall < Unit >(context, { ctx =>2244 checkThreadAndCall < Unit >(context, { ctx =>
1964- let arg0 = code.toJSValue(ctx)2245+ let arg0 = code
1965 let arg1 = msg.toJSValue(ctx)2246 let arg1 = msg.toJSValue(ctx)
1966 obj["onError"].asFunction().call([arg0, arg1])2247 obj["onError"].asFunction().call([arg0, arg1])
1967 })2248 })
1968 }2249 }
1969 },2250 },
1970- onTouch: if(obj["onTouch"].isUndefined()) {2251+ onTouch: if (obj["onTouch"].isUndefined()) {
1971 None2252 None
1972 } else {2253 } else {
1973 { =>2254 { =>
@@ -1976,19 +2257,18 @@ public class TestListener {
1976 })2257 })
1977 }2258 }
1978 },2259 },
1979- onEvent: if(obj["onEvent"].isUndefined()) {2260+ onEvent: if (obj["onEvent"].isUndefined()) {
1980 None2261 None
1981 } else {2262 } else {
1982- { e: EventType =>2263+ { e: JSValue/* FIXME: `EventType` */ =>
1983 checkThreadAndCall < Unit >(context, { ctx =>2264 checkThreadAndCall < Unit >(context, { ctx =>
1984- let arg0 = e.get().toJSValue(ctx)2265+ let arg0 = e
1985 obj["onEvent"].asFunction().call([arg0])2266 obj["onEvent"].asFunction().call([arg0])
1986 })2267 })
1987 }2268 }
1988 }2269 }
1989 )2270 )
1990 }2271 }
1991- 
1992}2272}
1993```2273```
1994 2274 
@@ -2007,35 +2287,39 @@ interface MyListener {
2007生成的仓颉代码:2287生成的仓颉代码:
2008 2288 
2009```cangjie2289```cangjie
2010-public class MyListener {2290+/*interface MyListener {
2291+ on(key: string, param: boolean, cb: (r: Record<string, string>) => void): void
2292+ }*/
2293+ 
2294+public open class MyListener {
2011 let callbackManager = CallbackManager < String, JSValue >()2295 let callbackManager = CallbackManager < String, JSValue >()
2012- protected MyListener(let arkts_object: JSObject) {}2296+ 
2297+ protected MyListener(var arkts_object: JSObject) { }
2013 2298 
2014 /**2299 /**
2015- * @brief on(key: string,param: boolean,cb: (r: Record<string, string>) => void): void2300+ * @brief on(key: string, param: boolean, cb: (r: Record<string, string>) => void): void
2016- */2301+ */
2017- public func on(key: String, param: Bool, cb: Callback1Argument<Record>): Unit {2302+ public func on(key: String, param: Bool, cb: Callback1Argument<HashMap<String, String>>): Unit {
2018- let key = key.toString()2303+ let keyString = key.toString()
2019- if(callbackManager.findCallbackObject(key, cb).isSome()) {2304+ if (callbackManager.findCallbackObject(keyString, cb).isSome()) {
2020 return2305 return
2021 }2306 }
2022 let jsCallback = checkThreadAndCall < JSValue >(getMainContext()) {2307 let jsCallback = checkThreadAndCall < JSValue >(getMainContext()) {
2023- __ctx => __ctx.function {2308+ ctx => ctx.function {
2024- __ctx: JSContext, info: JSCallInfo =>2309+ ctx: JSContext, info: JSCallInfo =>
2025- let arg0 = Record<stringstring>.fromJSValue(__ctx, info[0])2310+ let arg0 = record2Hashmap<String>(ctx, info[0], { context, i => String.fromJSValue(context, i) })
2026 cb.invoke(arg0)2311 cb.invoke(arg0)
2027- __ctx.undefined().toJSValue()2312+ ctx.undefined().toJSValue()
2028 }.toJSValue()2313 }.toJSValue()
2029 }2314 }
2030- callbackManager.put(key,(cb, jsCallback))2315+ callbackManager.put(keyString,(cb, jsCallback))
2031- jsObjApiCall < Unit >( arkts_object, "on", { __ctx =>[key.toJSValue(__ctx), param.toJSValue(__ctx), jsCallback] })2316+ jsObjApiCall < Unit >( arkts_object, "on", { ctx =>[keyString.toJSValue(ctx), param.toJSValue(ctx), jsCallback] })
2032 }2317 }
2033- 2318+ public open func toJSValue(_: JSContext): JSValue {
2034- func toJSValue(context: JSContext): JSValue {
2035 arkts_object.toJSValue()2319 arkts_object.toJSValue()
2036 }2320 }
2037 2321 
2038- static func fromJSValue (context: JSContext, input: JSValue): MyListener {2322+ public static func fromJSValue(_: JSContext, input: JSValue): MyListener {
2039 MyListener(input.asObject())2323 MyListener(input.asObject())
2040 }2324 }
2041}2325}
@@ -2057,13 +2341,22 @@ interface Optionals {
2057生成的仓颉代码:2341生成的仓颉代码:
2058 2342 
2059```cangjie2343```cangjie
2060-public class Optionals {2344+/*interface Optionals {
2345+ optionalParam10: (a: number, b?: String) => void;
2346+ optionalField1?: number;
2347+ }*/
2061 2348 
2062- protected Optionals(public var optionalParam10: (a: Float64, b: ?String) -> Unit,2349+public open class Optionals {
2063- public var optionalField1!: Option<Float64> = None) {}2350+ public var optionalParam10: (Float64, ?String) -> Unit
2351+ public var optionalField1: Option<Float64> = None
2352+ protected init(
2353+ optionalParam10: (Float64, ?String) -> Unit,
2354+ optionalField1!: Option<Float64> = None) {
2355+ this.optionalParam10 = optionalParam10
2356+ this.optionalField1 = optionalField1
2357+ }
2064 2358 
2065- 2359+ public open func toJSValue(context: JSContext): JSValue {
2066- public func toJSValue(context: JSContext): JSValue {
2067 let obj = context.object()2360 let obj = context.object()
2068 obj["optionalParam10"] = context.function({ ctx, info =>2361 obj["optionalParam10"] = context.function({ ctx, info =>
2069 let p0 = Float64.fromJSValue(ctx, info[0])2362 let p0 = Float64.fromJSValue(ctx, info[0])
@@ -2071,30 +2364,33 @@ public class Optionals {
2071 optionalParam10(p0, p1)2364 optionalParam10(p0, p1)
2072 ctx.undefined().toJSValue()2365 ctx.undefined().toJSValue()
2073 }).toJSValue()2366 }).toJSValue()
2074- if(let Some(v) <- optionalField1) {2367+ if (let Some(v) <- optionalField1) {
2075 obj["optionalField1"] = v.toJSValue(context)2368 obj["optionalField1"] = v.toJSValue(context)
2076 }2369 }
2077 obj.toJSValue()2370 obj.toJSValue()
2078 }2371 }
2079 2372 
2080- public static func fromJSValue (context: JSContext, input: JSValue): Optionals {2373+ public static func fromJSValue(context: JSContext, input: JSValue): Optionals {
2081 let obj = input.asObject()2374 let obj = input.asObject()
2082 Optionals(2375 Optionals(
2083 { a: Float64, b:?String =>2376 { a: Float64, b:?String =>
2084 checkThreadAndCall < Unit >(context, { ctx =>2377 checkThreadAndCall < Unit >(context, { ctx =>
2085 let arg0 = a.toJSValue(ctx)2378 let arg0 = a.toJSValue(ctx)
2086- let arg1 = b?.toJSValue(ctx)2379+ let arg1 = match(b) {
2380+ case None => ctx.undefined().toJSValue()
2381+ case _ => b.getOrThrow().toJSValue(ctx)
2382+ }
2087 obj["optionalParam10"].asFunction().call([arg0, arg1])2383 obj["optionalParam10"].asFunction().call([arg0, arg1])
2088 })2384 })
2089 },2385 },
2090- optionalField1: if(obj["optionalField1"].isUndefined()) {2386+ optionalField1:
2091- None2387+ if (obj["optionalField1"].isNull()) {
2388+ None < Float64 >
2092 } else {2389 } else {
2093 Float64.fromJSValue(context, obj["optionalField1"])2390 Float64.fromJSValue(context, obj["optionalField1"])
2094 }2391 }
2095 )2392 )
2096 }2393 }
2097- 
2098}2394}
2099```2395```
2100 2396 
@@ -2117,30 +2413,114 @@ interface ObjectTypes<U, T> {
2117生成的仓颉代码:2413生成的仓颉代码:
2118 2414 
2119```cangjie2415```cangjie
2120-public class ObjectTypes<U, T> {2416+/*interface AutoGenType0 {
2417+ x: number;
2418+ y: U;
2419+ }*/
2121 2420 
2122- protected ObjectTypes(public var typeLiteral10: JSValue/* FIXME: `{ x: number; y: U }` */,2421+public open class AutoGenType0<U> where U <: JSInteropType<U> {
2123- public var typeLiteral20: JSValue/* FIXME: `{ [number]: string; [symbol]: T }` */,2422+ public var x: Float64
2124- public var typeLiteral30: JSValue/* FIXME: `{ () => void; (number: any) => string }` */) {}2423+ public var y: U
2424+ protected init(
2425+ x: Float64,
2426+ y: U) {
2427+ this.x = x
2428+ this.y = y
2429+ }
2125 2430 
2126- 2431+ public open func toJSValue(context: JSContext): JSValue {
2127- public func toJSValue(context: JSContext): JSValue {
2128 let obj = context.object()2432 let obj = context.object()
2129- obj["typeLiteral10"] = typeLiteral102433+ obj["x"] = x.toJSValue(context)
2130- obj["typeLiteral20"] = typeLiteral202434+ obj["y"] = y.toJSValue(context)
2131- obj["typeLiteral30"] = typeLiteral30
2132 obj.toJSValue()2435 obj.toJSValue()
2133 }2436 }
2134 2437 
2135- public static func fromJSValue <U, T>(context: JSContext, input: JSValue): ObjectTypes<U, T> {2438+ public static func fromJSValue(context: JSContext, input: JSValue): AutoGenType0<U> {
2136 let obj = input.asObject()2439 let obj = input.asObject()
2137- ObjectTypes(2440+ AutoGenType0(
2138- JSValue/* FIXME: `{ x: number; y: U }` */.fromJSValue(context, obj["typeLiteral10"]),2441+ Float64.fromJSValue(context, obj["x"]),
2139- JSValue/* FIXME: `{ [number]: string; [symbol]: T }` */.fromJSValue(context, obj["typeLiteral20"]),2442+ U.fromJSValue(context, obj["y"])
2140- JSValue/* FIXME: `{ () => void; (number: any) => string }` */.fromJSValue(context, obj["typeLiteral30"])
2141 )2443 )
2142 }2444 }
2445+}
2143 2446 
2447+/*interface AutoGenType1 {
2448+ }*/
2449+ 
2450+public open class AutoGenType1 {
2451+ protected init() {
2452+ }
2453+ 
2454+ public open func toJSValue(context: JSContext): JSValue {
2455+ let obj = context.object()
2456+ 
2457+ obj.toJSValue()
2458+ }
2459+ 
2460+ public static func fromJSValue(context: JSContext, input: JSValue): AutoGenType1 {
2461+ let obj = input.asObject()
2462+ AutoGenType1(
2463+ 
2464+ )
2465+ }
2466+}
2467+ 
2468+/*interface AutoGenType2 {
2469+ }*/
2470+ 
2471+public open class AutoGenType2 {
2472+ protected init() {
2473+ }
2474+ 
2475+ public open func toJSValue(context: JSContext): JSValue {
2476+ let obj = context.object()
2477+ 
2478+ obj.toJSValue()
2479+ }
2480+ 
2481+ public static func fromJSValue(context: JSContext, input: JSValue): AutoGenType2 {
2482+ let obj = input.asObject()
2483+ AutoGenType2(
2484+ 
2485+ )
2486+ }
2487+}
2488+ 
2489+/*interface ObjectTypes {
2490+ typeLiteral10: { x: number; y: U; };
2491+ typeLiteral20: { [p: number]: String; [p: symbol]: T };
2492+ typeLiteral30: { (): void; (number): String };
2493+ }*/
2494+ 
2495+public open class ObjectTypes<U, T> where U <: JSInteropType<U>, T <: JSInteropType<T> {
2496+ public var typeLiteral10: AutoGenType0<U>
2497+ public var typeLiteral20: AutoGenType1
2498+ public var typeLiteral30: AutoGenType2
2499+ protected init(
2500+ typeLiteral10: AutoGenType0<U>,
2501+ typeLiteral20: AutoGenType1,
2502+ typeLiteral30: AutoGenType2) {
2503+ this.typeLiteral10 = typeLiteral10
2504+ this.typeLiteral20 = typeLiteral20
2505+ this.typeLiteral30 = typeLiteral30
2506+ }
2507+ 
2508+ public open func toJSValue(context: JSContext): JSValue {
2509+ let obj = context.object()
2510+ obj["typeLiteral10"] = typeLiteral10.toJSValue(context)
2511+ obj["typeLiteral20"] = typeLiteral20.toJSValue(context)
2512+ obj["typeLiteral30"] = typeLiteral30.toJSValue(context)
2513+ obj.toJSValue()
2514+ }
2515+ 
2516+ public static func fromJSValue(context: JSContext, input: JSValue): ObjectTypes<U, T> {
2517+ let obj = input.asObject()
2518+ ObjectTypes(
2519+ AutoGenType0<U>.fromJSValue(context, obj["typeLiteral10"]),
2520+ AutoGenType1.fromJSValue(context, obj["typeLiteral20"]),
2521+ AutoGenType2.fromJSValue(context, obj["typeLiteral30"])
2522+ )
2523+ }
2144}2524}
2145```2525```
2146 2526 
@@ -2157,7 +2537,7 @@ tupleType: [number, number, string];
2157生成的仓颉代码:2537生成的仓颉代码:
2158 2538 
2159```cangjie2539```cangjie
2160-public var tupleType: Tuple<Float64, Float64, String>2540+public var tupleType: (Float64, Float64, String)
2161```2541```
2162 2542 
2163### Union 类型2543### Union 类型
@@ -2191,21 +2571,36 @@ public enum ARK1 {
2191 case STRING(x) => context.string(x).toJSValue()2571 case STRING(x) => context.string(x).toJSValue()
2192 case BOOLEAN(x) => context.boolean(x).toJSValue()2572 case BOOLEAN(x) => context.boolean(x).toJSValue()
2193 case BYTEARRAY(x) => context.global["Uint8Array"].asClass().new(x.toJSValue(context))2573 case BYTEARRAY(x) => context.global["Uint8Array"].asClass().new(x.toJSValue(context))
2194- case FLOAT32ARRAY(x) => let buffer = context.arrayBuffer(acquireArrayRawData(x), x.size, { pt => releaseArrayRawData(pt)})2574+ case FLOAT32ARRAY(x) => context.global["Float32Array"].asClass().new(context.arrayBuffer(x).toJSValue())
2195-context.global["Float32Array"].asClass().new(buffer.toJSValue())
2196 case BIGINT(x) => context.bigint(x).toJSValue()2575 case BIGINT(x) => context.bigint(x).toJSValue()
2197 }2576 }
2198 }2577 }
2199-}2578+ public static func fromJSValue(context: JSContext, input: JSValue): ARK1 {
2200 2579 
2201-public enum ARK2 {2580+ if (input.isNull()) {
2202- | ARK1(x)2581+ return NULL
2203- | VOID(Unit)
2204- 
2205- public func toJSValue(context: JSContext): JSValue {
2206- match(this) {
2207- case ARK1(x) => x.toJSValue(context)
2208 }2582 }
2583+ if (input.isNumber()) {
2584+ return NUMBER(Float64.fromJSValue(context, input))
2585+ }
2586+ if (input.isString()) {
2587+ return STRING(String.fromJSValue(context, input))
2588+ }
2589+ if (input.isBoolean()) {
2590+ return BOOLEAN(Bool.fromJSValue(context, input))
2591+ }
2592+ if (instanceof(input, "Uint8Array")) {
2593+ let jsArray: JSValue = context.global["Uint8Array"].asObject().callMethod("from", [input])
2594+ return BYTEARRAY(fromJSArray<UInt8>(context, jsArray))
2595+ }
2596+ if (instanceof(input, "Float32Array")) {
2597+ let jsArray: JSValue = context.global["Float32Array"].asObject().callMethod("from", [input])
2598+ return FLOAT32ARRAY(fromJSArray<Float32>(context, jsArray))
2599+ }
2600+ if (input.isBigInt()) {
2601+ return BIGINT(input.toBigInt())
2602+ }
2603+ throw Exception("unsupport type!")
2209 }2604 }
2210}2605}
2211```2606```
@@ -2221,7 +2616,7 @@ typeReference21: Promise<T>;
2221生成的仓颉代码:2616生成的仓颉代码:
2222 2617 
2223```cangjie2618```cangjie
2224-public var typeReference21: Promise<T>,2619+public var typeReference21: JSValue/* FIXME: `Promise<T>` */
2225```2620```
2226 2621 
2227### 交叉类型2622### 交叉类型
@@ -2239,24 +2634,28 @@ interface IntersectionTypes<U, T> {
2239生成的仓颉代码:2634生成的仓颉代码:
2240 2635 
2241```cangjie2636```cangjie
2242-public class IntersectionTypes<U, T> {2637+/*interface IntersectionTypes {
2638+ intersectionType: object & Record<U, T>;
2639+ }*/
2243 2640 
2244- protected IntersectionTypes(public var intersectionType: JSValue/* FIXME: `object & HashMap<U, T>` */) {}2641+public open class IntersectionTypes<U, T> where U <: JSInteropType<U>, T <: JSInteropType<T> {
2642+ public var intersectionType: JSValue/* FIXME: `object & HashMap<U, T>` */
2643+ protected init(intersectionType: JSValue/* FIXME: `object & HashMap<U, T>` */) {
2644+ this.intersectionType = intersectionType
2645+ }
2245 2646 
2246- 2647+ public open func toJSValue(context: JSContext): JSValue {
2247- public func toJSValue(context: JSContext): JSValue {
2248 let obj = context.object()2648 let obj = context.object()
2249 obj["intersectionType"] = intersectionType2649 obj["intersectionType"] = intersectionType
2250 obj.toJSValue()2650 obj.toJSValue()
2251 }2651 }
2252 2652 
2253- public static func fromJSValue <U, T>(context: JSContext, input: JSValue): IntersectionTypes<U, T> {2653+ public static func fromJSValue(context: JSContext, input: JSValue): IntersectionTypes<U, T> {
2254 let obj = input.asObject()2654 let obj = input.asObject()
2255 IntersectionTypes(2655 IntersectionTypes(
2256- JSValue/* FIXME: `object & HashMap<U, T>` */.fromJSValue(context, obj["intersectionType"])2656+ obj["intersectionType"]
2257 )2657 )
2258 }2658 }
2259- 
2260}2659}
2261```2660```
2262 2661 
@@ -2289,6 +2688,9 @@ declare module './exportAlias' {
2289生成的仓颉代码:2688生成的仓颉代码:
2290 2689 
2291```cangjie2690```cangjie
2691+import ohos.ark_interop.*
2692+import ohos.ark_interop_helper.*
2693+import ohos.base.*
2292/***********IMPORT***********/2694/***********IMPORT***********/
2293/*FIXME: Import details need to be verified and rewritten by user.*/2695/*FIXME: Import details need to be verified and rewritten by user.*/
2294/*import { a } from '@umeng/common';*/2696/*import { a } from '@umeng/common';*/
@@ -2308,7 +2710,6 @@ declare module './exportAlias' {
2308/*FIXME: Import details need to be verified and rewritten by user.*/2710/*FIXME: Import details need to be verified and rewritten by user.*/
2309/*import { ExportedInterface } from './exportAlias';*/2711/*import { ExportedInterface } from './exportAlias';*/
2310 2712 
2311- 
2312/*2713/*
2313 2714 
2314public const value1 = 0/* FIXME: Initialization is required */2715public const value1 = 0/* FIXME: Initialization is required */
@@ -2320,40 +2721,40 @@ public const value2 = 0/* FIXME: Initialization is required */
2320 2721 
2321/***********METHOD***********/2722/***********METHOD***********/
2322/**2723/**
2323- * @brief createSub(): Inheritances.SubClass2724+ * @brief createSub(): Inheritances.SubClass
2324- */2725+ */
2325public func createSub(): JSValue/* FIXME: `Inheritances.SubClass` */ {2726public func createSub(): JSValue/* FIXME: `Inheritances.SubClass` */ {
2326- hmsGlobalApiCall < JSValue/* FIXME: `Inheritances.SubClass` */ >( "my_module_imports", "createSub", emptyArg) {2727+ hmsGlobalApiCall < JSValue/* FIXME: `Inheritances.SubClass` */ >( "_ark_interop_api", "createSub", EMPTY_ARG) { ctx, info => info }
2327- ctx, info => info
2328- }
2329}2728}
2330 2729 
2331- 
2332-/***********OBJECT***********/
2333- 
2334/*interface ExportedInterface {2730/*interface ExportedInterface {
2335 myOption?: String;2731 myOption?: String;
2336 }*/2732 }*/
2337 2733 
2338public open class ExportedInterface {2734public open class ExportedInterface {
2339- 2735+ public var myOption: Option<String> = None
2340- protected ExportedInterface(public var myOption!: Option<String> = None) {}2736+ protected init(myOption!: Option<String> = None) {
2341- 2737+ this.myOption = myOption
2342- 2738+ }
2739+ 
2343 public open func toJSValue(context: JSContext): JSValue {2740 public open func toJSValue(context: JSContext): JSValue {
2344 let obj = context.object()2741 let obj = context.object()
2345- if(let Some(v) <- myOption) {2742+ if (let Some(v) <- myOption) {
2346 obj["myOption"] = v.toJSValue(context)2743 obj["myOption"] = v.toJSValue(context)
2347 }2744 }
2348 obj.toJSValue()2745 obj.toJSValue()
2349 }2746 }
2350- 2747+ 
2351 public static func fromJSValue(context: JSContext, input: JSValue): ExportedInterface {2748 public static func fromJSValue(context: JSContext, input: JSValue): ExportedInterface {
2352 let obj = input.asObject()2749 let obj = input.asObject()
2353 ExportedInterface(2750 ExportedInterface(
2354- myOption: Option < String >.fromJSValue(context, obj["myOption"])2751+ myOption:
2752+ if (obj["myOption"].isNull()) {
2753+ None < String >
2754+ } else {
2755+ String.fromJSValue(context, obj["myOption"])
2756+ }
2355 )2757 )
2356 }2758 }
2357-
2358}2759}
2359```2760```