bugfix 262 cases of for-await-of

issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I6KAG4?from=project-issue

Signed-off-by: maojunwei <maojunwei1@huawei.com>
Change-Id: I9410513b0b4b49f72f0ab3e659a0ac19e5cd7e2d
This commit is contained in:
maojunwei 2023-03-11 11:31:01 +08:00
parent e7b4386df6
commit 80b0eed438
6 changed files with 90 additions and 25 deletions

View File

@ -106,22 +106,12 @@ void JSAsyncFunction::AsyncFunctionAwait(JSThread *thread, const JSHandle<JSTagg
asyncCtxt = JSHandle<JSTaggedValue>(thread, asyncFun->GetGeneratorContext());
}
// 2.Let promiseCapability be ! NewPromiseCapability(%Promise%).
// 2.Let promise be ? PromiseResolve(%Promise%, value).
JSHandle<GlobalEnv> env = vm->GetGlobalEnv();
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
JSHandle<PromiseCapability> pcap =
JSPromise::NewPromiseCapability(thread, JSHandle<JSTaggedValue>::Cast(env->GetPromiseFunction()));
// 3.Let resolveResult be ! Call(promiseCapability.[[Resolve]], undefined, « value »).
JSHandle<JSTaggedValue> resolve(thread, pcap->GetResolve());
JSHandle<JSTaggedValue> thisArg = globalConst->GetHandledUndefined();
JSHandle<JSTaggedValue> undefined = globalConst->GetHandledUndefined();
EcmaRuntimeCallInfo *info =
EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, thisArg, undefined, 1);
RETURN_IF_ABRUPT_COMPLETION(thread);
info->SetCallArg(value.GetTaggedValue());
JSFunction::Call(info);
JSHandle<JSTaggedValue> promiseValue =
builtins::BuiltinsPromiseHandler::PromiseResolve(thread,
JSHandle<JSTaggedValue>::Cast(env->GetPromiseFunction()),
value);
RETURN_IF_ABRUPT_COMPLETION(thread);
// 4.Let onFulfilled be a new built-in function object as defined in AsyncFunction Awaited Fulfilled.
JSHandle<JSAsyncAwaitStatusFunction> fulFunc = factory->NewJSAsyncAwaitStatusFunction(
@ -143,8 +133,9 @@ void JSAsyncFunction::AsyncFunctionAwait(JSThread *thread, const JSHandle<JSTagg
JSHandle<JSPromise>(thread, tcap->GetPromise())->SetPromiseIsHandled(true);
// 10.Perform ! PerformPromiseThen(promiseCapability.[[Promise]], onFulfilled, onRejected, throwawayCapability).
JSHandle<JSPromise> promise(thread, pcap->GetPromise());
BuiltinsPromise::PerformPromiseThen(thread, promise, JSHandle<JSTaggedValue>::Cast(fulFunc),
JSHandle<JSObject> promise = JSHandle<JSObject>::Cast(promiseValue);
BuiltinsPromise::PerformPromiseThen(thread, JSHandle<JSPromise>::Cast(promise),
JSHandle<JSTaggedValue>::Cast(fulFunc),
JSHandle<JSTaggedValue>::Cast(rejFunc), tcap);
// 11.Remove asyncContext from the execution context stack and restore the execution context that

View File

@ -1289,7 +1289,7 @@ JSTaggedValue RuntimeStubs::RuntimeTryUpdateGlobalRecord(JSThread *thread, JSTag
ASSERT(entry != -1);
if (dict->GetAttributes(entry).IsConstProps()) {
return RuntimeThrowSyntaxError(thread, "const variable can not be modified");
return RuntimeThrowTypeError(thread, "const variable can not be modified");
}
PropertyBox *box = dict->GetBox(entry);
@ -1929,9 +1929,12 @@ JSTaggedValue RuntimeStubs::RuntimeCreateObjectWithExcludedKeys(JSThread *thread
uint16_t firstArgRegIdx)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSObject> restObj = factory->NewEmptyJSObject();
if (objVal->IsNull() || objVal->IsUndefined()) {
return restObj.GetTaggedValue();
}
JSHandle<JSObject> obj(JSTaggedValue::ToObject(thread, objVal));
ASSERT(objVal->IsJSObject());
JSHandle<JSObject> obj(objVal);
uint32_t numExcludedKeys = 0;
JSHandle<TaggedArray> excludedKeys = factory->NewTaggedArray(numKeys + 1);
FrameHandler frameHandler(thread);
@ -1945,11 +1948,8 @@ JSTaggedValue RuntimeStubs::RuntimeCreateObjectWithExcludedKeys(JSThread *thread
}
}
uint32_t numAllKeys = obj->GetNumberOfKeys();
JSHandle<TaggedArray> allKeys = factory->NewTaggedArray(numAllKeys);
JSObject::GetAllKeys(thread, obj, 0, allKeys);
JSHandle<JSObject> restObj = factory->NewEmptyJSObject();
JSHandle<TaggedArray> allKeys = JSObject::GetOwnPropertyKeys(thread, obj);
uint32_t numAllKeys = allKeys->GetLength();
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
for (uint32_t i = 0; i < numAllKeys; i++) {
key.Update(allKeys->Get(i));

View File

@ -37,6 +37,7 @@ group("ark_js_moduletest") {
"dynamicimport",
"dyninstruction",
"ecmastringtable",
"forawaitof",
"forin",
"fortest",
"generator",

View File

@ -0,0 +1,18 @@
# Copyright (c) 2023 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_moduletest_action("forawaitof") {
deps = []
}

View File

@ -0,0 +1,18 @@
# Copyright (c) 2023 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
true
true
true
true
1

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2023 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @tc.name:forawaitof
* @tc.desc:test forawaitof
* @tc.type: FUNC
* @tc.require: issueI5NO8G
*/
let rest;
let iterCount = 0;
async function fn() {
for await ({...rest} of ["foo"]) {
print(rest["0"] == "f");
print(rest["1"] == "o");
print(rest["2"] == "o");
print(rest instanceof Object);
iterCount += 1;
}
}
let promise = fn();
promise.then(() => print(iterCount));