From a510c39b24a7408141072d52b0b7c7f510ce9287 Mon Sep 17 00:00:00 2001 From: "@wang-jingwu001" Date: Mon, 8 Aug 2022 17:32:02 +0800 Subject: [PATCH] Added asyncgeneratorreject command and modified front-end review comments Signed-off-by: @wang-jingwu001 https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5LA3G --- test262/es2021_tests.txt | 40 +++++++++++++++++++ test262/skip_tests.json | 38 ++++++++++++++++++ ts2panda/src/compiler.ts | 3 +- .../function/asyncGeneratorFunctionBuilder.ts | 29 +++++++++----- ts2panda/src/pandagen.ts | 5 +++ 5 files changed, 105 insertions(+), 10 deletions(-) diff --git a/test262/es2021_tests.txt b/test262/es2021_tests.txt index c467b241f5..2289914d50 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 e8b3a705d7..0cedeafeb8 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 0bec2dbd12..c757dd58cd 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 53eec4ec79..85341d1e78 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 4949c64d93..ea71fe233f 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)); } -- Gitee