diff --git a/test262/es2021_tests.txt b/test262/es2021_tests.txt index c467b241f54c9117143f5e5da77adcaae2878e05..2289914d5045510a7c4dd660f0f0e272a7f145b6 100644 --- a/test262/es2021_tests.txt +++ b/test262/es2021_tests.txt @@ -423,3 +423,43 @@ built-ins/RegExp/named-groups/string-replace-undefined.js built-ins/RegExp/named-groups/unicode-match.js built-ins/RegExp/named-groups/string-replace-unclosed.js built-ins/RegExp/named-groups/unicode-references.js +built-ins/AsyncGeneratorFunction/name.js +built-ins/AsyncGeneratorFunction/length.js +built-ins/AsyncGeneratorFunction/prototype/constructor.js +built-ins/AsyncGeneratorFunction/prototype/prop-desc.js +built-ins/AsyncGeneratorFunction/prototype/Symbol.toStringTag.js +built-ins/AsyncGeneratorFunction/prototype/not-callable.js +built-ins/AsyncGeneratorFunction/prototype/prototype.js +built-ins/AsyncGeneratorFunction/prototype/extensibility.js +built-ins/AsyncGeneratorFunction/extensibility.js +built-ins/AsyncGeneratorPrototype/Symbol.toStringTag.js +built-ins/AsyncGeneratorPrototype/throw/return-rejected-promise.js +built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart-promise.js +built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-return.js +built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally-throw.js +built-ins/AsyncGeneratorPrototype/throw/prop-desc.js +built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-promise.js +built-ins/AsyncGeneratorPrototype/throw/throw-state-completed.js +built-ins/AsyncGeneratorPrototype/throw/throw-suspendedStart.js +built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-catch.js +built-ins/AsyncGeneratorPrototype/throw/name.js +built-ins/AsyncGeneratorPrototype/throw/length.js +built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield.js +built-ins/AsyncGeneratorPrototype/next/request-queue-promise-resolve-order.js +built-ins/AsyncGeneratorPrototype/next/request-queue-order.js +built-ins/AsyncGeneratorPrototype/next/prop-desc.js +built-ins/AsyncGeneratorPrototype/next/iterator-result-prototype.js +built-ins/AsyncGeneratorPrototype/next/name.js +built-ins/AsyncGeneratorPrototype/next/length.js +built-ins/AsyncGeneratorPrototype/next/request-queue-await-order.js +built-ins/AsyncGeneratorPrototype/next/return-promise.js +built-ins/AsyncGeneratorPrototype/return/return-suspendedStart.js +built-ins/AsyncGeneratorPrototype/return/prop-desc.js +built-ins/AsyncGeneratorPrototype/return/return-suspendedYield.js +built-ins/AsyncGeneratorPrototype/return/iterator-result-prototype.js +built-ins/AsyncGeneratorPrototype/return/name.js +built-ins/AsyncGeneratorPrototype/return/return-state-completed.js +built-ins/AsyncGeneratorPrototype/return/length.js +built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-promise.js +built-ins/AsyncGeneratorPrototype/return/return-promise.js +built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-promise.js \ No newline at end of file diff --git a/test262/skip_tests.json b/test262/skip_tests.json index e8b3a705d72b752deae9ecb47e3722f627a62fd9..0cedeafeb848469da51d402a6e11f52f037e90cf 100644 --- a/test262/skip_tests.json +++ b/test262/skip_tests.json @@ -1589,5 +1589,43 @@ "built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-cell.js", "built-ins/WeakRef/prototype/deref/gc-cleanup-not-prevented-with-wr-deref.js" ] + }, + { + "reason": "asyncgenerator constructor not yet supported", + "files": [ + "built-ins/AsyncGeneratorFunction/invoked-as-constructor-no-arguments.js", + "built-ins/AsyncGeneratorFunction/has-instance.js", + "built-ins/AsyncGeneratorFunction/invoked-as-function-no-arguments.js", + "built-ins/AsyncGeneratorFunction/instance-construct-throws.js", + "built-ins/AsyncGeneratorFunction/invoked-as-function-single-argument.js", + "built-ins/AsyncGeneratorFunction/instance-length.js", + "built-ins/AsyncGeneratorFunction/is-a-constructor.js", + "built-ins/AsyncGeneratorFunction/instance-prototype.js", + "built-ins/AsyncGeneratorFunction/proto-from-ctor-realm.js", + "built-ins/AsyncGeneratorFunction/proto-from-ctor-realm-prototype.js", + "built-ins/AsyncGeneratorFunction/instance-yield-expr-in-param.js", + "built-ins/AsyncGeneratorFunction/instance-name.js", + "built-ins/AsyncGeneratorFunction/instance-await-expr-in-param.js", + "built-ins/AsyncGeneratorFunction/invoked-as-function-multiple-arguments.js" + ] + }, + { + "reason": "Some details need to be improved", + "files": [ + "built-ins/AsyncGeneratorPrototype/constructor.js", + "built-ins/AsyncGeneratorPrototype/throw/this-val-not-async-generator.js", + "built-ins/AsyncGeneratorPrototype/throw/throw-suspendedYield-try-finally.js", + "built-ins/AsyncGeneratorPrototype/throw/request-queue-order-state-executing.js", + "built-ins/AsyncGeneratorPrototype/throw/this-val-not-object.js", + "built-ins/AsyncGeneratorPrototype/next/this-val-not-async-generator.js", + "built-ins/AsyncGeneratorPrototype/next/request-queue-order-state-executing.js", + "built-ins/AsyncGeneratorPrototype/next/this-val-not-object.js", + "built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-throw.js", + "built-ins/AsyncGeneratorPrototype/return/this-val-not-async-generator.js", + "built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally-return.js", + "built-ins/AsyncGeneratorPrototype/return/request-queue-order-state-executing.js", + "built-ins/AsyncGeneratorPrototype/return/this-val-not-object.js", + "built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-try-finally.js" + ] } ] \ No newline at end of file diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 0bec2dbd129416d753eb78d4ef385ccc4a4272cc..c757dd58cdab1110e57b70129cf5181019fb3cdc 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -58,9 +58,10 @@ import { compileStringLiteral } from "./expression/stringLiteral"; import { getTemplateObject } from "./expression/templateExpression"; import { compileYieldExpression } from "./expression/yieldExpression"; import { AsyncFunctionBuilder } from "./function/asyncFunctionBuilder"; +import { AsyncGeneratorFunctionBuilder } from "./function/asyncGeneratorFunctionBuilder"; import { FunctionBuilder, FunctionBuilderType } from "./function/functionBuilder"; import { GeneratorFunctionBuilder } from "./function/generatorFunctionBuilder"; -import { AsyncGeneratorFunctionBuilder } from "./function/asyncGeneratorFunctionBuilder"; + import { hoistFunctionInBlock } from "./hoisting"; diff --git a/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts b/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts index 53eec4ec79c7e14c82f2ae57e2578a3a424ce1c6..85341d1e783d8a8d4d7e51746aaf27800f2a7ba9 100644 --- a/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts +++ b/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,7 +13,6 @@ * limitations under the License. */ -import { Scope } from "src/scope"; import ts from "typescript"; import { CacheList, getVregisterCache } from "../base/vregisterCache"; import { Compiler, ControlFlowChange } from "../compiler"; @@ -23,9 +22,9 @@ import { } from "../irnodes"; import { PandaGen } from "../pandagen"; import { Recorder } from "../recorder"; -import { IteratorRecord, IteratorType, getIteratorRecord } from "../statement/forOfStatement"; -import { AsyncFunctionBuilder } from "./asyncFunctionBuilder"; import { NodeKind } from "../debuginfo"; +import { CatchTable, LabelPair } from "../statement/tryStatement"; + enum ResumeMode { Return = 0, Throw, Next }; /** @@ -38,17 +37,20 @@ export class AsyncGeneratorFunctionBuilder { private compiler: Compiler; private asyncGenObj: VReg; private retValue: VReg; + private beginLabel: Label; + private endLabel: Label; constructor(pandaGen: PandaGen, compiler: Compiler) { this.asyncPandaGen = pandaGen; this.compiler = compiler; + this.beginLabel = new Label(); + this.endLabel = new Label(); this.asyncGenObj = pandaGen.getTemp(); this.retValue = pandaGen.getTemp(); } - - prepare(node: ts.Node, recorder: Recorder) { + + prepare(node: ts.Node, recorder: Recorder) { let pandaGen = this.asyncPandaGen; - let scope = recorder.getScopeOfNode(node); // backend handle funcobj, frontend set undefined pandaGen.createAsyncGeneratorObj(node, getVregisterCache(pandaGen, CacheList.FUNC)); @@ -74,7 +76,7 @@ export class AsyncGeneratorFunctionBuilder { this.handleMode(node); } - + yield(node: ts.Node, value: VReg) { let pandaGen = this.asyncPandaGen; let promise = this.asyncPandaGen.getTemp(); @@ -166,7 +168,16 @@ export class AsyncGeneratorFunctionBuilder { pandaGen.EcmaAsyncgeneratorresolve(node, this.asyncGenObj, value, getVregisterCache(pandaGen, CacheList.True)); } - cleanUp() { + cleanUp(node: ts.Node) { + let pandaGen = this.asyncPandaGen; + pandaGen.label(node, this.endLabel); + // catch + let exception = pandaGen.getTemp(); + pandaGen.storeAccumulator(NodeKind.Invalid, exception); + pandaGen.EcmaAsyncgeneratorreject(node, this.asyncGenObj, exception); + pandaGen.return(NodeKind.Invalid); + pandaGen.freeTemps(exception); this.asyncPandaGen.freeTemps(this.asyncGenObj, this.retValue); + new CatchTable(pandaGen, this.endLabel, new LabelPair(this.beginLabel, this.endLabel)); } } diff --git a/ts2panda/src/pandagen.ts b/ts2panda/src/pandagen.ts index 4949c64d93a68d981d8344a289d45f913b04b268..ea71fe233f75ddf3062778af04b9afec12d4f252 100644 --- a/ts2panda/src/pandagen.ts +++ b/ts2panda/src/pandagen.ts @@ -137,6 +137,7 @@ import { EcmaCreateasyncgeneratorobj, EcmaCreateiterresultobj, EcmaAsyncgeneratorresolve, + EcmaAsyncgeneratorreject, EcmaDecdyn, EcmaDiv2dyn, EcmaEqdyn, @@ -1031,6 +1032,10 @@ export class PandaGen { this.add(node, new EcmaAsyncgeneratorresolve(genObj, value, done)); } + EcmaAsyncgeneratorreject(node: ts.Node, genObj: VReg, value: VReg) { + this.add(node, new EcmaAsyncgeneratorreject(genObj, value)); + } + suspendGenerator(node: ts.Node, genObj: VReg, iterRslt: VReg) { this.add(node, new EcmaSuspendgenerator(genObj, iterRslt)); }