From 7210ea029a71d2e6c09dcd57cfd29f20a5149601 Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Thu, 14 Oct 2021 16:03:48 +0800 Subject: [PATCH 01/15] commit msg Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/BUILD.gn | 24 ++++ ecmascript/tests/js_arguments_test.cpp | 158 +++++++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 ecmascript/tests/js_arguments_test.cpp diff --git a/ecmascript/tests/BUILD.gn b/ecmascript/tests/BUILD.gn index 99ea6cc25a..e5ffb453bd 100644 --- a/ecmascript/tests/BUILD.gn +++ b/ecmascript/tests/BUILD.gn @@ -854,6 +854,28 @@ host_unittest_action("GcTest") { } } +host_unittest_action("JsArgumentsTest") { + module_out_path = module_output_path + + sources = [ + # test file + "js_arguments_test.cpp", + ] + + configs = [ + "//ark/js_runtime:ecma_test_config", + "//ark/js_runtime:ark_jsruntime_public_config", # should add before + # arkruntime_public_config + "//ark/js_runtime:ark_jsruntime_config", + "$ark_root/runtime:arkruntime_public_config", + ] + + deps = [ + "$ark_root/libpandabase:libarkbase", + sdk_libc_secshared_dep, + ] +} + group("unittest") { testonly = true @@ -866,6 +888,7 @@ group("unittest") { ":GcTest", ":GlueRegsTest", ":HugeObjectTest", + ":JsArgumentsTest", ":JsArrayTest", ":JsDateTest", ":JsForinIteratorTest", @@ -905,6 +928,7 @@ group("host_unittest") { ":GcTestAction", ":GlueRegsTestAction", ":HugeObjectTestAction", + ":JsArgumentsTestAction", ":JsArrayTestAction", ":JsDateTestAction", ":JsForinIteratorTestAction", diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp new file mode 100644 index 0000000000..69df746827 --- /dev/null +++ b/ecmascript/tests/js_arguments_test.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "ecmascript/ecma_string.h" +#include "ecmascript/ecma_vm.h" +#include "ecmascript/global_env.h" +#include "ecmascript/js_handle.h" +#include "ecmascript/js_object-inl.h" +#include "ecmascript/js_object.h" +#include "ecmascript/js_tagged_value-inl.h" +#include "ecmascript/js_tagged_value.h" +#include "ecmascript/object_factory.h" +#include "ecmascript/object_operator.h" +#include "ecmascript/tests/test_helper.h" +#include "ecmascript/js_thread.h" +#include "ecmascript/js_arguments.h" + +using namespace panda::ecmascript; +using namespace panda::ecmascript::base; + +namespace panda::test { +class JsArgumentsTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + JSThread *thread {nullptr}; + PandaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; +}; + +static JSFunction *JSObjectTestCreate(JSThread *thread) +{ + JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); + return globalEnv->GetObjectFunction().GetObject(); +} + +HWTEST_F_L0(JsArgumentsTest, SetProperty) +{ + EcmaVM *ecmaVM = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVM->GetFactory(); + + JSHandle argFunc(thread, JSObjectTestCreate(thread)); + JSHandle jsarg = factory->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); + JSHandle arg = factory->NewJSArguments(); + + char array[] = "x"; + JSHandle key(factory->NewFromCanBeCompressString(array)); + JSHandle value(thread, JSTaggedValue(1)); + + JSHandle receiver = JSHandle::Cast(jsarg); + EXPECT_TRUE(JSTaggedValue::SameValue(jsarg.GetTaggedValue(), receiver.GetTaggedValue())); + EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value, receiver)); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); + EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); + + JSHandle value2(thread, JSTaggedValue(2)); + EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value2, receiver)); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); + EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); +} + +HWTEST_F_L0(JsArgumentsTest, GetProperty) +{ + EcmaVM *ecmaVM = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVM->GetFactory(); + + JSHandle argFunc(thread, JSObjectTestCreate(thread)); + JSHandle jsarg = factory->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); + JSHandle arg = factory->NewJSArguments(); + + char array[] = "x"; + JSHandle key(factory->NewFromCanBeCompressString(array)); + JSHandle value(thread, JSTaggedValue(1)); + + JSHandle receiver = JSHandle::Cast(jsarg); + EXPECT_TRUE(JSTaggedValue::SameValue(jsarg.GetTaggedValue(), receiver.GetTaggedValue())); + JSArguments::SetProperty(thread, arg, key, value, receiver); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); + EXPECT_EQ(JSArguments::GetProperty(thread, JSHandle(jsarg), key, receiver).GetValue()->GetInt(), 1); + + JSHandle value2(thread, JSTaggedValue(2)); + JSArguments::SetProperty(thread, arg, key, value2, receiver); + EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); +} + +HWTEST_F_L0(JsArgumentsTest, DeleteProperty) +{ + EcmaVM *ecmaVM = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVM->GetFactory(); + + JSHandle argFunc(thread, JSObjectTestCreate(thread)); + JSHandle jsarg = factory->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); + JSHandle arg = factory->NewJSArguments(); + + char array[] = "delete"; + JSHandle key(factory->NewFromCanBeCompressString(array)); + JSHandle value(thread, JSTaggedValue(1)); + JSHandle receiver = JSHandle::Cast(jsarg); + JSArguments::SetProperty(thread, arg, key, value, receiver); + + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); + EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); + + PropertyDescriptor desc(thread); + JSArguments::DeleteProperty(thread, JSHandle(jsarg), key); + EXPECT_TRUE(JSArguments::GetOwnProperty(thread, arg, key, desc)); + EXPECT_TRUE(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->IsUndefined()); + EXPECT_TRUE(desc.GetValue()->IsUndefined()); +} + +HWTEST_F_L0(JsArgumentsTest, DefineOwnProperty) +{ + EcmaVM *ecmaVM = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVM->GetFactory(); + + JSHandle argFunc(thread, JSObjectTestCreate(thread)); + JSHandle jsarg = factory->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); + + JSHandle key(factory->NewFromCanBeCompressString("x")); + PropertyDescriptor desc(thread, JSHandle(thread, JSTaggedValue(2))); + + EXPECT_TRUE(JSObject::OrdinaryDefineOwnProperty(thread, jsarg, key, desc)); + EXPECT_TRUE(JSArguments::DefineOwnProperty(thread, JSHandle(jsarg), key, desc)); + EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); +} + +} // namespace panda::test \ No newline at end of file -- Gitee From f8d547a2ecbdd305a98ecffa32c94ba9a9638487 Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Fri, 15 Oct 2021 19:33:26 +0800 Subject: [PATCH 02/15] update BUILD.gn js_arguments_test.cpp --- ecmascript/tests/BUILD.gn | 27 ++++++++++ ecmascript/tests/js_arguments_test.cpp | 72 +++++++++++--------------- 2 files changed, 58 insertions(+), 41 deletions(-) diff --git a/ecmascript/tests/BUILD.gn b/ecmascript/tests/BUILD.gn index e5ffb453bd..ca690d4998 100644 --- a/ecmascript/tests/BUILD.gn +++ b/ecmascript/tests/BUILD.gn @@ -583,6 +583,33 @@ host_unittest_action("HugeObjectTest") { } } +host_unittest_action("JsArgumentsTest") { + module_out_path = module_output_path + + sources = [ + # test file + "js_arguments_test.cpp", + ] + + configs = [ + "//ark/js_runtime:ecma_test_config", + "//ark/js_runtime:ark_jsruntime_public_config", # should add before + # arkruntime_public_config + "//ark/js_runtime:ark_jsruntime_config", + "$ark_root/runtime:arkruntime_public_config", + ] + + deps = [ + "$ark_root/libpandabase:libarkbase", + "//ark/js_runtime:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + if (!is_standard_system) { + deps += [ "$ark_root/runtime:libarkruntime" ] + } +} + host_unittest_action("LexicalEnvTest") { module_out_path = module_output_path diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index 69df746827..93d98ced1a 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -13,22 +13,18 @@ * limitations under the License. */ -#include "ecmascript/ecma_string.h" +#include "ecmascript/js_arguments.h" #include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h" #include "ecmascript/js_handle.h" +#include "ecmascript/js_thread.h" +#include "ecmascript/js_function.h" #include "ecmascript/js_object-inl.h" -#include "ecmascript/js_object.h" #include "ecmascript/js_tagged_value-inl.h" -#include "ecmascript/js_tagged_value.h" #include "ecmascript/object_factory.h" -#include "ecmascript/object_operator.h" #include "ecmascript/tests/test_helper.h" -#include "ecmascript/js_thread.h" -#include "ecmascript/js_arguments.h" using namespace panda::ecmascript; -using namespace panda::ecmascript::base; namespace panda::test { class JsArgumentsTest : public testing::Test { @@ -52,33 +48,32 @@ public: { TestHelper::DestroyEcmaVMWithScope(instance, scope); } - JSThread *thread {nullptr}; - PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; + PandaVM *instance {nullptr}; + JSThread *thread {nullptr}; }; static JSFunction *JSObjectTestCreate(JSThread *thread) { - JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); + EcmaVM *ecmaVM = thread->GetEcmaVM(); + JSHandle globalEnv = ecmaVM->GetGlobalEnv(); return globalEnv->GetObjectFunction().GetObject(); } HWTEST_F_L0(JsArgumentsTest, SetProperty) { - EcmaVM *ecmaVM = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVM->GetFactory(); - JSHandle argFunc(thread, JSObjectTestCreate(thread)); - JSHandle jsarg = factory->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); - JSHandle arg = factory->NewJSArguments(); + JSHandle jsarg = + thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); + JSHandle arg = thread->GetEcmaVM()->GetFactory()->NewJSArguments(); char array[] = "x"; - JSHandle key(factory->NewFromCanBeCompressString(array)); + JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(array)); JSHandle value(thread, JSTaggedValue(1)); - + //receive must be jsarg's conversion JSHandle receiver = JSHandle::Cast(jsarg); - EXPECT_TRUE(JSTaggedValue::SameValue(jsarg.GetTaggedValue(), receiver.GetTaggedValue())); EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value, receiver)); + EXPECT_FALSE(JSArguments::SetProperty(thread, arg, key, value, value)); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); @@ -90,19 +85,16 @@ HWTEST_F_L0(JsArgumentsTest, SetProperty) HWTEST_F_L0(JsArgumentsTest, GetProperty) { - EcmaVM *ecmaVM = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVM->GetFactory(); - JSHandle argFunc(thread, JSObjectTestCreate(thread)); - JSHandle jsarg = factory->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); - JSHandle arg = factory->NewJSArguments(); + JSHandle jsarg = + thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); + JSHandle arg = thread->GetEcmaVM()->GetFactory()->NewJSArguments(); char array[] = "x"; - JSHandle key(factory->NewFromCanBeCompressString(array)); + JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(array)); JSHandle value(thread, JSTaggedValue(1)); JSHandle receiver = JSHandle::Cast(jsarg); - EXPECT_TRUE(JSTaggedValue::SameValue(jsarg.GetTaggedValue(), receiver.GetTaggedValue())); JSArguments::SetProperty(thread, arg, key, value, receiver); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, JSHandle(jsarg), key, receiver).GetValue()->GetInt(), 1); @@ -115,15 +107,13 @@ HWTEST_F_L0(JsArgumentsTest, GetProperty) HWTEST_F_L0(JsArgumentsTest, DeleteProperty) { - EcmaVM *ecmaVM = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVM->GetFactory(); - JSHandle argFunc(thread, JSObjectTestCreate(thread)); - JSHandle jsarg = factory->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); - JSHandle arg = factory->NewJSArguments(); + JSHandle jsarg = + thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); + JSHandle arg = thread->GetEcmaVM()->GetFactory()->NewJSArguments(); char array[] = "delete"; - JSHandle key(factory->NewFromCanBeCompressString(array)); + JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(array)); JSHandle value(thread, JSTaggedValue(1)); JSHandle receiver = JSHandle::Cast(jsarg); JSArguments::SetProperty(thread, arg, key, value, receiver); @@ -131,28 +121,28 @@ HWTEST_F_L0(JsArgumentsTest, DeleteProperty) EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); - PropertyDescriptor desc(thread); + PropertyDescriptor desc_count(thread); JSArguments::DeleteProperty(thread, JSHandle(jsarg), key); - EXPECT_TRUE(JSArguments::GetOwnProperty(thread, arg, key, desc)); + + //GetOwnProperty() get value and goes desc + EXPECT_TRUE(JSArguments::GetOwnProperty(thread, arg, key, desc_count)); + //if DeleteProperty(), then desc is undefined EXPECT_TRUE(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->IsUndefined()); - EXPECT_TRUE(desc.GetValue()->IsUndefined()); + EXPECT_TRUE(desc_count.GetValue()->IsUndefined()); } HWTEST_F_L0(JsArgumentsTest, DefineOwnProperty) { - EcmaVM *ecmaVM = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVM->GetFactory(); - JSHandle argFunc(thread, JSObjectTestCreate(thread)); - JSHandle jsarg = factory->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); - - JSHandle key(factory->NewFromCanBeCompressString("x")); + JSHandle jsarg = + thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); + JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); PropertyDescriptor desc(thread, JSHandle(thread, JSTaggedValue(2))); + //desc made by OrdinaryDefineOwnProperty() EXPECT_TRUE(JSObject::OrdinaryDefineOwnProperty(thread, jsarg, key, desc)); EXPECT_TRUE(JSArguments::DefineOwnProperty(thread, JSHandle(jsarg), key, desc)); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); } - } // namespace panda::test \ No newline at end of file -- Gitee From 8aa11a81450d98c71416502b82407cb9d16cf482 Mon Sep 17 00:00:00 2001 From: hj1007 <845154910@qq.com> Date: Sun, 17 Oct 2021 00:37:53 +0800 Subject: [PATCH 03/15] update js_arguments_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index 93d98ced1a..df0e30eda3 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -14,6 +14,7 @@ */ #include "ecmascript/js_arguments.h" + #include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h" #include "ecmascript/js_handle.h" @@ -73,7 +74,6 @@ HWTEST_F_L0(JsArgumentsTest, SetProperty) //receive must be jsarg's conversion JSHandle receiver = JSHandle::Cast(jsarg); EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value, receiver)); - EXPECT_FALSE(JSArguments::SetProperty(thread, arg, key, value, value)); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); @@ -145,4 +145,4 @@ HWTEST_F_L0(JsArgumentsTest, DefineOwnProperty) EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); } -} // namespace panda::test \ No newline at end of file +} // namespace panda::test -- Gitee From a8f3205a8d41fb84e30da3f82811929bc5682ed5 Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Sat, 16 Oct 2021 11:08:01 -0700 Subject: [PATCH 04/15] fix js_argumengts_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index df0e30eda3..2f0a6e7daa 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -14,7 +14,6 @@ */ #include "ecmascript/js_arguments.h" - #include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h" #include "ecmascript/js_handle.h" -- Gitee From 7f327fc5113437686b1bb07ceac20d81bdc53543 Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Sat, 16 Oct 2021 20:47:56 -0700 Subject: [PATCH 05/15] update js_arguments_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index 2f0a6e7daa..df0e30eda3 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -14,6 +14,7 @@ */ #include "ecmascript/js_arguments.h" + #include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h" #include "ecmascript/js_handle.h" -- Gitee From 711f2e7f0343db956479dfd817937f086255d79c Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Sat, 16 Oct 2021 20:58:06 -0700 Subject: [PATCH 06/15] fix js_arguments_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index df0e30eda3..2f0a6e7daa 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -14,7 +14,6 @@ */ #include "ecmascript/js_arguments.h" - #include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h" #include "ecmascript/js_handle.h" -- Gitee From 62c1c06ac907d29c8d05b05e47c79851dfbb1107 Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Sun, 17 Oct 2021 03:38:17 -0700 Subject: [PATCH 07/15] fix js_arguments_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index 2f0a6e7daa..3ed56de654 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -18,7 +18,6 @@ #include "ecmascript/global_env.h" #include "ecmascript/js_handle.h" #include "ecmascript/js_thread.h" -#include "ecmascript/js_function.h" #include "ecmascript/js_object-inl.h" #include "ecmascript/js_tagged_value-inl.h" #include "ecmascript/object_factory.h" -- Gitee From 6abf3444fc7336085d698f80dc7536a5f2ba58e5 Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Mon, 18 Oct 2021 09:54:24 +0800 Subject: [PATCH 08/15] fix js_arguments_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/BUILD.gn | 22 ---------------------- ecmascript/tests/js_arguments_test.cpp | 7 ++++--- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/ecmascript/tests/BUILD.gn b/ecmascript/tests/BUILD.gn index ca690d4998..653a46d87a 100644 --- a/ecmascript/tests/BUILD.gn +++ b/ecmascript/tests/BUILD.gn @@ -881,28 +881,6 @@ host_unittest_action("GcTest") { } } -host_unittest_action("JsArgumentsTest") { - module_out_path = module_output_path - - sources = [ - # test file - "js_arguments_test.cpp", - ] - - configs = [ - "//ark/js_runtime:ecma_test_config", - "//ark/js_runtime:ark_jsruntime_public_config", # should add before - # arkruntime_public_config - "//ark/js_runtime:ark_jsruntime_config", - "$ark_root/runtime:arkruntime_public_config", - ] - - deps = [ - "$ark_root/libpandabase:libarkbase", - sdk_libc_secshared_dep, - ] -} - group("unittest") { testonly = true diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index 3ed56de654..5f965e6083 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -69,6 +69,7 @@ HWTEST_F_L0(JsArgumentsTest, SetProperty) char array[] = "x"; JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(array)); JSHandle value(thread, JSTaggedValue(1)); + //receive must be jsarg's conversion JSHandle receiver = JSHandle::Cast(jsarg); EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value, receiver)); @@ -119,14 +120,14 @@ HWTEST_F_L0(JsArgumentsTest, DeleteProperty) EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); - PropertyDescriptor desc_count(thread); + PropertyDescriptor Desc(thread); JSArguments::DeleteProperty(thread, JSHandle(jsarg), key); //GetOwnProperty() get value and goes desc - EXPECT_TRUE(JSArguments::GetOwnProperty(thread, arg, key, desc_count)); + EXPECT_TRUE(JSArguments::GetOwnProperty(thread, arg, key, Desc)); //if DeleteProperty(), then desc is undefined EXPECT_TRUE(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->IsUndefined()); - EXPECT_TRUE(desc_count.GetValue()->IsUndefined()); + EXPECT_TRUE(Desc.GetValue()->IsUndefined()); } HWTEST_F_L0(JsArgumentsTest, DefineOwnProperty) -- Gitee From 08be3fe08ffb9f97d8da4000166c16daa239fbdb Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Mon, 18 Oct 2021 10:30:25 +0800 Subject: [PATCH 09/15] fix js_arguments_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index 5f965e6083..ba4b3abb3d 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -18,9 +18,9 @@ #include "ecmascript/global_env.h" #include "ecmascript/js_handle.h" #include "ecmascript/js_thread.h" +#include "ecmascript/object_factory.h" #include "ecmascript/js_object-inl.h" #include "ecmascript/js_tagged_value-inl.h" -#include "ecmascript/object_factory.h" #include "ecmascript/tests/test_helper.h" using namespace panda::ecmascript; @@ -62,7 +62,7 @@ static JSFunction *JSObjectTestCreate(JSThread *thread) HWTEST_F_L0(JsArgumentsTest, SetProperty) { JSHandle argFunc(thread, JSObjectTestCreate(thread)); - JSHandle jsarg = + JSHandle jsarg = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); JSHandle arg = thread->GetEcmaVM()->GetFactory()->NewJSArguments(); @@ -70,7 +70,7 @@ HWTEST_F_L0(JsArgumentsTest, SetProperty) JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(array)); JSHandle value(thread, JSTaggedValue(1)); - //receive must be jsarg's conversion + // receive must be jsarg's conversion JSHandle receiver = JSHandle::Cast(jsarg); EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value, receiver)); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); @@ -85,7 +85,7 @@ HWTEST_F_L0(JsArgumentsTest, SetProperty) HWTEST_F_L0(JsArgumentsTest, GetProperty) { JSHandle argFunc(thread, JSObjectTestCreate(thread)); - JSHandle jsarg = + JSHandle jsarg = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); JSHandle arg = thread->GetEcmaVM()->GetFactory()->NewJSArguments(); @@ -107,7 +107,7 @@ HWTEST_F_L0(JsArgumentsTest, GetProperty) HWTEST_F_L0(JsArgumentsTest, DeleteProperty) { JSHandle argFunc(thread, JSObjectTestCreate(thread)); - JSHandle jsarg = + JSHandle jsarg = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); JSHandle arg = thread->GetEcmaVM()->GetFactory()->NewJSArguments(); @@ -123,9 +123,9 @@ HWTEST_F_L0(JsArgumentsTest, DeleteProperty) PropertyDescriptor Desc(thread); JSArguments::DeleteProperty(thread, JSHandle(jsarg), key); - //GetOwnProperty() get value and goes desc + // GetOwnProperty() get value and goes Desc EXPECT_TRUE(JSArguments::GetOwnProperty(thread, arg, key, Desc)); - //if DeleteProperty(), then desc is undefined + // if DeleteProperty(), then Desc is undefined EXPECT_TRUE(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->IsUndefined()); EXPECT_TRUE(Desc.GetValue()->IsUndefined()); } @@ -133,12 +133,12 @@ HWTEST_F_L0(JsArgumentsTest, DeleteProperty) HWTEST_F_L0(JsArgumentsTest, DefineOwnProperty) { JSHandle argFunc(thread, JSObjectTestCreate(thread)); - JSHandle jsarg = + JSHandle jsarg = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); PropertyDescriptor desc(thread, JSHandle(thread, JSTaggedValue(2))); - //desc made by OrdinaryDefineOwnProperty() + // desc made by OrdinaryDefineOwnProperty() EXPECT_TRUE(JSObject::OrdinaryDefineOwnProperty(thread, jsarg, key, desc)); EXPECT_TRUE(JSArguments::DefineOwnProperty(thread, JSHandle(jsarg), key, desc)); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); -- Gitee From 84e8091caebdacec6e8c1bffce5d646f1c20d30e Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Mon, 18 Oct 2021 10:40:26 +0800 Subject: [PATCH 10/15] fix js_arguments_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index ba4b3abb3d..47da62021d 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -136,11 +136,11 @@ HWTEST_F_L0(JsArgumentsTest, DefineOwnProperty) JSHandle jsarg = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); - PropertyDescriptor desc(thread, JSHandle(thread, JSTaggedValue(2))); + PropertyDescriptor Desc(thread, JSHandle(thread, JSTaggedValue(2))); - // desc made by OrdinaryDefineOwnProperty() - EXPECT_TRUE(JSObject::OrdinaryDefineOwnProperty(thread, jsarg, key, desc)); - EXPECT_TRUE(JSArguments::DefineOwnProperty(thread, JSHandle(jsarg), key, desc)); + // Desc made by OrdinaryDefineOwnProperty() + EXPECT_TRUE(JSObject::OrdinaryDefineOwnProperty(thread, jsarg, key, Desc)); + EXPECT_TRUE(JSArguments::DefineOwnProperty(thread, JSHandle(jsarg), key, Desc)); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); } -- Gitee From e59b79a5860f2101929e16218542ef5f218ae486 Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Mon, 18 Oct 2021 11:44:48 +0800 Subject: [PATCH 11/15] fix js_arguments_testc.pp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index 47da62021d..a76c9adb9c 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -15,12 +15,11 @@ #include "ecmascript/js_arguments.h" #include "ecmascript/ecma_vm.h" +#include "ecmascript/js_thread.h" #include "ecmascript/global_env.h" #include "ecmascript/js_handle.h" -#include "ecmascript/js_thread.h" #include "ecmascript/object_factory.h" #include "ecmascript/js_object-inl.h" -#include "ecmascript/js_tagged_value-inl.h" #include "ecmascript/tests/test_helper.h" using namespace panda::ecmascript; @@ -75,11 +74,6 @@ HWTEST_F_L0(JsArgumentsTest, SetProperty) EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value, receiver)); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); - - JSHandle value2(thread, JSTaggedValue(2)); - EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value2, receiver)); - EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); - EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); } HWTEST_F_L0(JsArgumentsTest, GetProperty) @@ -97,11 +91,6 @@ HWTEST_F_L0(JsArgumentsTest, GetProperty) JSArguments::SetProperty(thread, arg, key, value, receiver); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, JSHandle(jsarg), key, receiver).GetValue()->GetInt(), 1); - - JSHandle value2(thread, JSTaggedValue(2)); - JSArguments::SetProperty(thread, arg, key, value2, receiver); - EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); - EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); } HWTEST_F_L0(JsArgumentsTest, DeleteProperty) @@ -126,7 +115,6 @@ HWTEST_F_L0(JsArgumentsTest, DeleteProperty) // GetOwnProperty() get value and goes Desc EXPECT_TRUE(JSArguments::GetOwnProperty(thread, arg, key, Desc)); // if DeleteProperty(), then Desc is undefined - EXPECT_TRUE(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->IsUndefined()); EXPECT_TRUE(Desc.GetValue()->IsUndefined()); } -- Gitee From 8f979be1573b20bfd802c1fe0357b06c73596aec Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Mon, 18 Oct 2021 13:44:59 +0800 Subject: [PATCH 12/15] fix js_arguments_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index a76c9adb9c..69d51e1b2a 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -15,11 +15,11 @@ #include "ecmascript/js_arguments.h" #include "ecmascript/ecma_vm.h" -#include "ecmascript/js_thread.h" #include "ecmascript/global_env.h" #include "ecmascript/js_handle.h" -#include "ecmascript/object_factory.h" +#include "ecmascript/js_thread.h" #include "ecmascript/js_object-inl.h" +#include "ecmascript/object_factory.h" #include "ecmascript/tests/test_helper.h" using namespace panda::ecmascript; @@ -74,6 +74,11 @@ HWTEST_F_L0(JsArgumentsTest, SetProperty) EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value, receiver)); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); + + JSHandle value2(thread, JSTaggedValue(2)); + EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value2, receiver)); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); + EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); } HWTEST_F_L0(JsArgumentsTest, GetProperty) @@ -91,6 +96,11 @@ HWTEST_F_L0(JsArgumentsTest, GetProperty) JSArguments::SetProperty(thread, arg, key, value, receiver); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, JSHandle(jsarg), key, receiver).GetValue()->GetInt(), 1); + + JSHandle value2(thread, JSTaggedValue(2)); + JSArguments::SetProperty(thread, arg, key, value2, receiver); + EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); } HWTEST_F_L0(JsArgumentsTest, DeleteProperty) @@ -115,6 +125,7 @@ HWTEST_F_L0(JsArgumentsTest, DeleteProperty) // GetOwnProperty() get value and goes Desc EXPECT_TRUE(JSArguments::GetOwnProperty(thread, arg, key, Desc)); // if DeleteProperty(), then Desc is undefined + EXPECT_TRUE(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->IsUndefined()); EXPECT_TRUE(Desc.GetValue()->IsUndefined()); } -- Gitee From 9d0fcf4d2d1f99b9d1f1d19d78622fab493cea65 Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Mon, 18 Oct 2021 14:05:04 +0800 Subject: [PATCH 13/15] fix js_arguments_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index 69d51e1b2a..8e517fce2e 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -17,8 +17,6 @@ #include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h" #include "ecmascript/js_handle.h" -#include "ecmascript/js_thread.h" -#include "ecmascript/js_object-inl.h" #include "ecmascript/object_factory.h" #include "ecmascript/tests/test_helper.h" @@ -72,12 +70,10 @@ HWTEST_F_L0(JsArgumentsTest, SetProperty) // receive must be jsarg's conversion JSHandle receiver = JSHandle::Cast(jsarg); EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value, receiver)); - EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); JSHandle value2(thread, JSTaggedValue(2)); EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value2, receiver)); - EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); } @@ -94,13 +90,11 @@ HWTEST_F_L0(JsArgumentsTest, GetProperty) JSHandle receiver = JSHandle::Cast(jsarg); JSArguments::SetProperty(thread, arg, key, value, receiver); - EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, JSHandle(jsarg), key, receiver).GetValue()->GetInt(), 1); JSHandle value2(thread, JSTaggedValue(2)); JSArguments::SetProperty(thread, arg, key, value2, receiver); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); - EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); } HWTEST_F_L0(JsArgumentsTest, DeleteProperty) @@ -115,8 +109,6 @@ HWTEST_F_L0(JsArgumentsTest, DeleteProperty) JSHandle value(thread, JSTaggedValue(1)); JSHandle receiver = JSHandle::Cast(jsarg); JSArguments::SetProperty(thread, arg, key, value, receiver); - - EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); PropertyDescriptor Desc(thread); @@ -125,7 +117,6 @@ HWTEST_F_L0(JsArgumentsTest, DeleteProperty) // GetOwnProperty() get value and goes Desc EXPECT_TRUE(JSArguments::GetOwnProperty(thread, arg, key, Desc)); // if DeleteProperty(), then Desc is undefined - EXPECT_TRUE(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->IsUndefined()); EXPECT_TRUE(Desc.GetValue()->IsUndefined()); } @@ -141,6 +132,5 @@ HWTEST_F_L0(JsArgumentsTest, DefineOwnProperty) EXPECT_TRUE(JSObject::OrdinaryDefineOwnProperty(thread, jsarg, key, Desc)); EXPECT_TRUE(JSArguments::DefineOwnProperty(thread, JSHandle(jsarg), key, Desc)); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); - EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); } } // namespace panda::test -- Gitee From 444497e821a56fdd6e996b1dd14a27100a227a9a Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Tue, 19 Oct 2021 09:30:18 +0800 Subject: [PATCH 14/15] fix js_arguments_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 55 ++++++++++++++++++++------ 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index 8e517fce2e..a2d5505142 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -70,10 +70,12 @@ HWTEST_F_L0(JsArgumentsTest, SetProperty) // receive must be jsarg's conversion JSHandle receiver = JSHandle::Cast(jsarg); EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value, receiver)); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); JSHandle value2(thread, JSTaggedValue(2)); EXPECT_TRUE(JSArguments::SetProperty(thread, arg, key, value2, receiver)); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); } @@ -90,11 +92,13 @@ HWTEST_F_L0(JsArgumentsTest, GetProperty) JSHandle receiver = JSHandle::Cast(jsarg); JSArguments::SetProperty(thread, arg, key, value, receiver); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, JSHandle(jsarg), key, receiver).GetValue()->GetInt(), 1); JSHandle value2(thread, JSTaggedValue(2)); JSArguments::SetProperty(thread, arg, key, value2, receiver); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); } HWTEST_F_L0(JsArgumentsTest, DeleteProperty) @@ -109,15 +113,14 @@ HWTEST_F_L0(JsArgumentsTest, DeleteProperty) JSHandle value(thread, JSTaggedValue(1)); JSHandle receiver = JSHandle::Cast(jsarg); JSArguments::SetProperty(thread, arg, key, value, receiver); + + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); - PropertyDescriptor Desc(thread); - JSArguments::DeleteProperty(thread, JSHandle(jsarg), key); - - // GetOwnProperty() get value and goes Desc - EXPECT_TRUE(JSArguments::GetOwnProperty(thread, arg, key, Desc)); - // if DeleteProperty(), then Desc is undefined - EXPECT_TRUE(Desc.GetValue()->IsUndefined()); + // test delete + bool Result = JSArguments::DeleteProperty(thread, JSHandle(jsarg), key); + EXPECT_TRUE(Result); + EXPECT_TRUE(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->IsUndefined()); } HWTEST_F_L0(JsArgumentsTest, DefineOwnProperty) @@ -125,12 +128,40 @@ HWTEST_F_L0(JsArgumentsTest, DefineOwnProperty) JSHandle argFunc(thread, JSObjectTestCreate(thread)); JSHandle jsarg = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); + JSHandle arg = thread->GetEcmaVM()->GetFactory()->NewJSArguments(); + JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); - PropertyDescriptor Desc(thread, JSHandle(thread, JSTaggedValue(2))); - - // Desc made by OrdinaryDefineOwnProperty() - EXPECT_TRUE(JSObject::OrdinaryDefineOwnProperty(thread, jsarg, key, Desc)); + JSHandle value1(thread, JSTaggedValue(1)); + JSHandle value2(thread, JSTaggedValue(2)); + JSHandle receiver = JSHandle::Cast(jsarg); + JSArguments::SetProperty(thread, arg, key, value2, receiver); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 2); + + PropertyDescriptor Desc(thread); + // set value1 + Desc.SetValue(value1); + Desc.SetWritable(false); EXPECT_TRUE(JSArguments::DefineOwnProperty(thread, JSHandle(jsarg), key, Desc)); - EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 2); + EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); +} + +HWTEST_F_L0(JsArgumentsTest, GetOwnProperty) +{ + JSHandle argFunc(thread, JSObjectTestCreate(thread)); + JSHandle jsarg = + thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(argFunc), argFunc); + JSHandle arg = thread->GetEcmaVM()->GetFactory()->NewJSArguments(); + + JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("x")); + JSHandle value(thread, JSTaggedValue(1)); + JSHandle receiver = JSHandle::Cast(jsarg); + JSArguments::SetProperty(thread, arg, key, value, receiver); + + PropertyDescriptor Desc(thread); + JSHandle caller = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("caller"); + // key is not caller + EXPECT_FALSE(JSTaggedValue::SameValue(key.GetTaggedValue(), caller.GetTaggedValue())); + EXPECT_TRUE(JSArguments::GetOwnProperty(thread, JSHandle(jsarg), key, Desc)); + EXPECT_EQ(Desc.GetValue()->GetInt(), 1); } } // namespace panda::test -- Gitee From cc482e10c0d040a7ce7830f715250f3d4d168734 Mon Sep 17 00:00:00 2001 From: hjzhangcm <845154910@qq.com> Date: Tue, 19 Oct 2021 09:51:42 +0800 Subject: [PATCH 15/15] fix js_arguments_test.cpp Signed-off-by: hjzhangcm <845154910@qq.com> --- ecmascript/tests/js_arguments_test.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index a2d5505142..5e5f06d8e6 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -113,13 +113,11 @@ HWTEST_F_L0(JsArgumentsTest, DeleteProperty) JSHandle value(thread, JSTaggedValue(1)); JSHandle receiver = JSHandle::Cast(jsarg); JSArguments::SetProperty(thread, arg, key, value, receiver); - - EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->GetInt(), 1); EXPECT_EQ(JSArguments::GetProperty(thread, jsarg, key).GetValue()->GetInt(), 1); // test delete - bool Result = JSArguments::DeleteProperty(thread, JSHandle(jsarg), key); - EXPECT_TRUE(Result); + bool result = JSArguments::DeleteProperty(thread, JSHandle(jsarg), key); + EXPECT_TRUE(result); EXPECT_TRUE(JSObject::GetProperty(thread, JSHandle(jsarg), key).GetValue()->IsUndefined()); } -- Gitee