diff --git a/runtime/linked_hash_table.h b/runtime/linked_hash_table.h index 4e9cc29dc4c2441fdc35a1503a53e2bdfeb6d5c5..18f8d617ba4d9a0349ffcbac6ce7f102334d6bbd 100644 --- a/runtime/linked_hash_table.h +++ b/runtime/linked_hash_table.h @@ -147,6 +147,12 @@ public: { return static_cast(obj); } + + static JSHandle Create(const JSThread *thread, int number_of_elements) + { + return Create(thread, false, number_of_elements); + } + static JSHandle Create(const JSThread *thread, bool is_weak = false, int number_of_elements = MIN_CAPACITY); @@ -190,6 +196,12 @@ public: { return static_cast(obj); } + + static JSHandle Create(const JSThread *thread, int number_of_elements) + { + return Create(thread, false, number_of_elements); + } + static JSHandle Create(const JSThread *thread, bool is_weak = false, int number_of_elements = MIN_CAPACITY); diff --git a/tests/runtime/common/builtins_test.cpp b/tests/runtime/common/builtins_test.cpp index e4710324b1604880e032bdb9496912aa164c5634..ddbfab6a7f7cd70972b9291f2ef38888d95c5201 100644 --- a/tests/runtime/common/builtins_test.cpp +++ b/tests/runtime/common/builtins_test.cpp @@ -25,9 +25,11 @@ #include "plugins/ecmascript/runtime/js_object.h" #include "plugins/ecmascript/runtime/base/builtins_base.h" -using namespace panda::coretypes; -using namespace panda::ecmascript; -using namespace panda::ecmascript::base; +using panda::ecmascript::GlobalEnv; +using panda::ecmascript::JSFunction; +using panda::ecmascript::JSHandle; +using panda::ecmascript::JSObject; +using panda::ecmascript::ObjectFactory; namespace panda::test { class BuiltinsTest : public testing::Test { @@ -42,9 +44,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + +private: PandaVM *instance {nullptr}; EcmaHandleScope *scope {nullptr}; - JSThread *thread; }; TEST_F(BuiltinsTest, ObjectInit) diff --git a/tests/runtime/common/ecma_empty_class_check/ecma_empty_class_check.cpp b/tests/runtime/common/ecma_empty_class_check/ecma_empty_class_check.cpp index 6cb22e2e468b4adcfb90c538a920d886efbf28c6..09ef5c057ca813b18e6621e78dace88e2aabc93d 100644 --- a/tests/runtime/common/ecma_empty_class_check/ecma_empty_class_check.cpp +++ b/tests/runtime/common/ecma_empty_class_check/ecma_empty_class_check.cpp @@ -56,13 +56,13 @@ TEST_F(EcmaEmptyClassCheck, TestJSABC) RuntimeOptions options; options.SetLoadRuntimes({"ecmascript"}); options.SetBootPandaFiles({}); + // NOLINTNEXTLINE(readability-magic-numbers) options.SetHeapSizeLimit(50_MB); options.SetGcType("epsilon"); ASSERT_TRUE(Runtime::Create(options)); - panda::ecmascript::EcmaVM *ecma_vm = - reinterpret_cast(Runtime::GetCurrent()->GetPandaVM()); + auto *ecma_vm = reinterpret_cast(Runtime::GetCurrent()->GetPandaVM()); ASSERT_TRUE(ecma_vm); @@ -70,7 +70,7 @@ TEST_F(EcmaEmptyClassCheck, TestJSABC) panda_file::OpenPandaFile(GetJSAbcFile(), "", panda_file::File::OpenMode::READ_WRITE); ASSERT_TRUE(pf); - CheckNames(*pf.get()); + CheckNames(*pf); ASSERT_TRUE(ecma_vm->ExecuteFromBuffer(pf->GetBase(), pf->GetPtr().GetSize(), "_GLOBAL::func_main_0", {})); diff --git a/tests/runtime/common/ecma_module_test.cpp b/tests/runtime/common/ecma_module_test.cpp index 832cf2026c6ba9f76b2bf782858bb0fdf4b696ae..b1c802df6b74f2e1e4aec75aa1ba5b68257df920 100644 --- a/tests/runtime/common/ecma_module_test.cpp +++ b/tests/runtime/common/ecma_module_test.cpp @@ -19,7 +19,15 @@ #include "plugins/ecmascript/runtime/tagged_dictionary.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" -using namespace panda::ecmascript; +using panda::ecmascript::EcmaModule; +using panda::ecmascript::EcmaString; +using panda::ecmascript::JSFunction; +using panda::ecmascript::JSHandle; +using panda::ecmascript::JSLocale; +using panda::ecmascript::ModuleManager; +using panda::ecmascript::NameDictionary; +using panda::ecmascript::ObjectFactory; +using panda::ecmascript::PropertyAttributes; namespace panda::test { class EcmaModuleTest : public testing::Test { @@ -43,9 +51,14 @@ public: { TestHelper::DestroyEcmaVMWithScope(instance, scope); } + +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread {nullptr}; }; EcmaModule *EcmaModuleCreate(JSThread *thread) @@ -370,18 +383,18 @@ TEST_F(EcmaModuleTest, ModuleManager_AddModuleItem) ObjectFactory *obj_factory = thread->GetEcmaVM()->GetFactory(); ModuleManager *module_manager = thread->GetEcmaVM()->GetModuleManager(); - int int_item_value11 = 11; - int int_item_value12 = 12; - int int_item_value21 = 21; - int int_item_value22 = 22; + constexpr int INT_ITEM_VALUE_11 = 11; + constexpr int INT_ITEM_VALUE_12 = 12; + constexpr int INT_ITEM_VALUE_21 = 21; + constexpr int INT_ITEM_VALUE_22 = 22; JSHandle handle_tag_val_item_name11(obj_factory->NewFromCanBeCompressString("cStrItemName11")); JSHandle handle_tag_val_item_name12(obj_factory->NewFromCanBeCompressString("cStrItemName12")); JSHandle handle_tag_val_item_name21(obj_factory->NewFromCanBeCompressString("cStrItemName21")); JSHandle handle_tag_val_item_name22(obj_factory->NewFromCanBeCompressString("cStrItemName22")); - JSHandle handle_tag_val_item_value11(thread, JSTaggedValue(int_item_value11)); - JSHandle handle_tag_val_item_value12(thread, JSTaggedValue(int_item_value12)); - JSHandle handle_tag_val_item_value21(thread, JSTaggedValue(int_item_value21)); - JSHandle handle_tag_val_item_value22(thread, JSTaggedValue(int_item_value22)); + JSHandle handle_tag_val_item_value11(thread, JSTaggedValue(INT_ITEM_VALUE_11)); + JSHandle handle_tag_val_item_value12(thread, JSTaggedValue(INT_ITEM_VALUE_12)); + JSHandle handle_tag_val_item_value21(thread, JSTaggedValue(INT_ITEM_VALUE_21)); + JSHandle handle_tag_val_item_value22(thread, JSTaggedValue(INT_ITEM_VALUE_22)); JSHandle handle_ecma_str_name_ecma_module1 = obj_factory->NewFromString("cStrNameEcmaModule1"); JSHandle handle_ecma_str_name_ecma_module2 = obj_factory->NewFromString("cStrNameEcmaModule2"); std::string std_str_module_file_name1 = JSLocale::ConvertToStdString(handle_ecma_str_name_ecma_module1); @@ -399,10 +412,10 @@ TEST_F(EcmaModuleTest, ModuleManager_AddModuleItem) EXPECT_EQ( module_manager->GetModuleItem(thread, handle_tag_val_ecma_module1, handle_tag_val_item_name11)->GetNumber(), - int_item_value11); + INT_ITEM_VALUE_11); EXPECT_EQ( module_manager->GetModuleItem(thread, handle_tag_val_ecma_module1, handle_tag_val_item_name12)->GetNumber(), - int_item_value12); + INT_ITEM_VALUE_12); // Test when the module is created through 'NewEmptyEcmaModule' function called at "ecma_module.cpp". module_manager->SetCurrentExportModuleName(std_str_module_file_name2); @@ -413,16 +426,16 @@ TEST_F(EcmaModuleTest, ModuleManager_AddModuleItem) module_manager->GetModule(thread, handle_tag_val_ecma_module_name2); EXPECT_EQ( module_manager->GetModuleItem(thread, handle_tag_val_ecma_module1, handle_tag_val_item_name11)->GetNumber(), - int_item_value11); + INT_ITEM_VALUE_11); EXPECT_EQ( module_manager->GetModuleItem(thread, handle_tag_val_ecma_module1, handle_tag_val_item_name12)->GetNumber(), - int_item_value12); + INT_ITEM_VALUE_12); EXPECT_EQ( module_manager->GetModuleItem(thread, handle_tag_val_ecma_module2, handle_tag_val_item_name21)->GetNumber(), - int_item_value21); + INT_ITEM_VALUE_21); EXPECT_EQ( module_manager->GetModuleItem(thread, handle_tag_val_ecma_module2, handle_tag_val_item_name22)->GetNumber(), - int_item_value22); + INT_ITEM_VALUE_22); } /* @@ -440,20 +453,20 @@ TEST_F(EcmaModuleTest, ModuleManager_CopyModule) ObjectFactory *obj_factory = thread->GetEcmaVM()->GetFactory(); ModuleManager *module_manager = thread->GetEcmaVM()->GetModuleManager(); - int int_item_value11 = 11; - int int_item_value12 = 12; - int int_item_value21 = 21; - int int_item_value22 = 22; + constexpr int INT_ITEM_VALUE_11 = 11; + constexpr int INT_ITEM_VALUE_12 = 12; + constexpr int INT_ITEM_VALUE_21 = 21; + constexpr int INT_ITEM_VALUE_22 = 22; std::string_view file_name_ecma_module_copy_to1 = "fileNameEcmaModuleCopyTo1"; std::string_view file_name_ecma_module_copy_to2 = "fileNameEcmaModuleCopyTo2"; JSHandle handle_tag_val_item_name11(obj_factory->NewFromCanBeCompressString("ItemName11")); JSHandle handle_tag_val_item_name12(obj_factory->NewFromCanBeCompressString("ItemName12")); JSHandle handle_tag_val_item_name21(obj_factory->NewFromCanBeCompressString("ItemName21")); JSHandle handle_tag_val_item_name22(obj_factory->NewFromCanBeCompressString("ItemName22")); - JSHandle handle_tag_val_item_value11(thread, JSTaggedValue(int_item_value11)); - JSHandle handle_tag_val_item_value12(thread, JSTaggedValue(int_item_value12)); - JSHandle handle_tag_val_item_value21(thread, JSTaggedValue(int_item_value21)); - JSHandle handle_tag_val_item_value22(thread, JSTaggedValue(int_item_value22)); + JSHandle handle_tag_val_item_value11(thread, JSTaggedValue(INT_ITEM_VALUE_11)); + JSHandle handle_tag_val_item_value12(thread, JSTaggedValue(INT_ITEM_VALUE_12)); + JSHandle handle_tag_val_item_value21(thread, JSTaggedValue(INT_ITEM_VALUE_21)); + JSHandle handle_tag_val_item_value22(thread, JSTaggedValue(INT_ITEM_VALUE_22)); JSHandle handle_ecma_module_copy_from1(thread, EcmaModuleCreate(thread)); JSHandle handle_ecma_module_copy_from2(thread, EcmaModuleCreate(thread)); JSHandle handle_tag_val_ecma_module_copy_from1(thread, @@ -469,10 +482,10 @@ TEST_F(EcmaModuleTest, ModuleManager_CopyModule) module_manager->CopyModule(thread, handle_tag_val_ecma_module_copy_from1); JSHandle handle_tag_val_ecma_module_copy_to1 = module_manager->GetModule( thread, JSHandle::Cast(obj_factory->NewFromString(PandaString(file_name_ecma_module_copy_to1)))); - EXPECT_EQ(int_item_value11, + EXPECT_EQ(INT_ITEM_VALUE_11, module_manager->GetModuleItem(thread, handle_tag_val_ecma_module_copy_to1, handle_tag_val_item_name11) ->GetNumber()); - EXPECT_EQ(int_item_value12, + EXPECT_EQ(INT_ITEM_VALUE_12, module_manager->GetModuleItem(thread, handle_tag_val_ecma_module_copy_to1, handle_tag_val_item_name12) ->GetNumber()); @@ -480,16 +493,16 @@ TEST_F(EcmaModuleTest, ModuleManager_CopyModule) module_manager->CopyModule(thread, handle_tag_val_ecma_module_copy_from2); JSHandle handle_tag_val_ecma_module_copy_to2 = module_manager->GetModule( thread, JSHandle::Cast(obj_factory->NewFromString(PandaString(file_name_ecma_module_copy_to2)))); - EXPECT_EQ(int_item_value11, + EXPECT_EQ(INT_ITEM_VALUE_11, module_manager->GetModuleItem(thread, handle_tag_val_ecma_module_copy_to1, handle_tag_val_item_name11) ->GetNumber()); - EXPECT_EQ(int_item_value12, + EXPECT_EQ(INT_ITEM_VALUE_12, module_manager->GetModuleItem(thread, handle_tag_val_ecma_module_copy_to1, handle_tag_val_item_name12) ->GetNumber()); - EXPECT_EQ(int_item_value21, + EXPECT_EQ(INT_ITEM_VALUE_21, module_manager->GetModuleItem(thread, handle_tag_val_ecma_module_copy_to2, handle_tag_val_item_name21) ->GetNumber()); - EXPECT_EQ(int_item_value22, + EXPECT_EQ(INT_ITEM_VALUE_22, module_manager->GetModuleItem(thread, handle_tag_val_ecma_module_copy_to2, handle_tag_val_item_name22) ->GetNumber()); } diff --git a/tests/runtime/common/ecma_string_test.cpp b/tests/runtime/common/ecma_string_test.cpp index 4ea80f9fd60d8252ea0ef157c6212154d23a38ba..2ebcd1ffbbd6f160e15ccf0084429b5c29a4c47c 100644 --- a/tests/runtime/common/ecma_string_test.cpp +++ b/tests/runtime/common/ecma_string_test.cpp @@ -16,8 +16,11 @@ #include "plugins/ecmascript/runtime/ecma_string-inl.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; +// NOLINTBEGIN(readability-magic-numbers,modernize-avoid-c-arrays) + namespace panda::test { class EcmaStringTest : public testing::Test { public: @@ -40,9 +43,15 @@ public: { TestHelper::DestroyEcmaVMWithScope(instance, scope); } + +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) PandaVM *instance {nullptr}; + +private: ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread {nullptr}; }; /* @@ -942,6 +951,7 @@ TEST_F(EcmaStringTest, GetDataUtf8) JSHandle handle_ecma_str_u8( thread, EcmaString::CreateFromUtf8(&array_u8[0], length_ecma_str_u8, ecma_vm_ptr, true)); for (size_t i = 0; i < length_ecma_str_u8; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) EXPECT_EQ(*(handle_ecma_str_u8->GetDataUtf8() + i), array_u8[i]); } @@ -951,6 +961,7 @@ TEST_F(EcmaStringTest, GetDataUtf8) JSHandle handle_ecma_str_u16_comp( thread, EcmaString::CreateFromUtf16(&array_u16_comp[0], length_ecma_str_u16_comp, ecma_vm_ptr, true)); for (size_t i = 0; i < sizeof(array_u16_comp) / array_u16_comp[0]; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) EXPECT_EQ(*(handle_ecma_str_u16_comp->GetDataUtf8() + i), array_u16_comp[i]); } } @@ -971,6 +982,7 @@ TEST_F(EcmaStringTest, GetDataUtf16) JSHandle handle_ecma_str_u16_not_comp( thread, EcmaString::CreateFromUtf16(&array_u16_not_comp[0], length_ecma_str_u16_not_comp, ecma_vm_ptr, false)); for (size_t i = 0; i < length_ecma_str_u16_not_comp; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) EXPECT_EQ(*(handle_ecma_str_u16_not_comp->GetDataUtf16() + i), array_u16_not_comp[i]); } } @@ -1122,7 +1134,7 @@ TEST_F(EcmaStringTest, CopyDataRegionUtf16) } for (size_t i = length_return_u16_not_comp; i < length_array_u16_target; i++) { EXPECT_EQ(array_u16_not_comp_copy_to[i], - ((uint16_t)default_one_byte_value_of_array_u16_not_comp_copy_to) * (1 + (1 << 8))); + ((uint16_t)default_one_byte_value_of_array_u16_not_comp_copy_to) * (1U + (1U << 8U))); } } @@ -1159,7 +1171,7 @@ TEST_F(EcmaStringTest, CopyDataUtf16) } for (size_t i = length_return_u16_not_comp; i < length_array_u16_target; i++) { EXPECT_EQ(array_u16_not_comp_copy_to[i], - ((uint16_t)default_one_byte_value_of_array_u16_not_comp_copy_to) * (1 + (1 << 8))); + ((uint16_t)default_one_byte_value_of_array_u16_not_comp_copy_to) * (1U + (1U << 8U))); } } @@ -1932,3 +1944,5 @@ TEST_F(EcmaStringTest, SetIsInternString) EXPECT_TRUE(handle_ecma_str_u16_not_comp->IsInternString()); } } // namespace panda::test + +// NOLINTEND(readability-magic-numbers,modernize-avoid-c-arrays) diff --git a/tests/runtime/common/glue_regs_test.cpp b/tests/runtime/common/glue_regs_test.cpp index 2754cf44b0ee17ce64cb880e5beb2df314e8bc83..ce614efc06c22936f9a6362f62594c9ebff52ba3 100644 --- a/tests/runtime/common/glue_regs_test.cpp +++ b/tests/runtime/common/glue_regs_test.cpp @@ -24,8 +24,7 @@ #include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/global_env_constants-inl.h" -using namespace panda::ecmascript; -using namespace panda::ecmascript::base; +using panda::ecmascript::GlobalEnvConstants; namespace panda::test { class GlueRegsTest : public testing::Test { @@ -40,9 +39,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread; }; TEST_F(GlueRegsTest, ConstantClassTest) @@ -53,6 +56,7 @@ TEST_F(GlueRegsTest, ConstantClassTest) const JSTaggedValue *address = global_const->BeginSlot(); while (address < global_const->EndSlot()) { EXPECT_TRUE(!(*address).IsNull()); // Visit barely + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) address += sizeof(JSTaggedValue); } } @@ -75,6 +79,7 @@ TEST_F(GlueRegsTest, ConstantStringTest) auto global_const = const_cast(thread->GlobalConstants()); ASSERT_NE(global_const, nullptr); +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define CONSTANT_STRING_ITERATOR(Type, Name, Index, Desc) \ Type Name##value = globalConst->Get##Name(); \ ASSERT_TRUE(!Name##value.IsNull()); \ @@ -89,6 +94,7 @@ TEST_F(GlueRegsTest, ConstantAccessorTest) auto global_const = const_cast(thread->GlobalConstants()); ASSERT_NE(global_const, nullptr); +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define CONSTANT_ACCESSOR_ITERATOR(Type, Name, Index, Desc) \ Type Name##value = globalConst->Get##Name(); \ ASSERT_TRUE(!Name##value.IsNull()); \ @@ -97,4 +103,4 @@ TEST_F(GlueRegsTest, ConstantAccessorTest) GLOBAL_ENV_CONSTANT_ACCESSOR(CONSTANT_ACCESSOR_ITERATOR) #undef CONSTANT_ACCESSOR_ITERATOR } -} // namespace panda::test \ No newline at end of file +} // namespace panda::test diff --git a/tests/runtime/common/huge_object_test.cpp b/tests/runtime/common/huge_object_test.cpp index d18675ba5162df3672597ab9672f5c5ad60b65c5..3c4cae07c7b4b97278ba2dd3ec25e2a7fc39de50 100644 --- a/tests/runtime/common/huge_object_test.cpp +++ b/tests/runtime/common/huge_object_test.cpp @@ -20,8 +20,6 @@ #include "plugins/ecmascript/runtime/tagged_array-inl.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" -using namespace panda::ecmascript; - namespace panda::test { class HugeObjectTest : public testing::Test { public: @@ -45,11 +43,23 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) JSThread *thread {nullptr}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; }; +#if !defined(NDEBUG) +using panda::ecmascript::JSFunction; +using panda::ecmascript::JSHandle; +using panda::ecmascript::JSObject; +using panda::ecmascript::TaggedArray; +using panda::ecmascript::TaggedObject; +#endif + #if !defined(NDEBUG) static JSObject *JSObjectTestCreate(JSThread *thread) { diff --git a/tests/runtime/common/js_arguments_test.cpp b/tests/runtime/common/js_arguments_test.cpp index 1ab749a5510e8c47a51b2f2f118b83dbd5cab3b6..758a77d4f477ec53a254585b42b587deb9f39401 100644 --- a/tests/runtime/common/js_arguments_test.cpp +++ b/tests/runtime/common/js_arguments_test.cpp @@ -20,7 +20,13 @@ #include "plugins/ecmascript/runtime/object_factory.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" -using namespace panda::ecmascript; +using panda::ecmascript::EcmaString; +using panda::ecmascript::GlobalEnv; +using panda::ecmascript::JSArguments; +using panda::ecmascript::JSFunction; +using panda::ecmascript::JSHandle; +using panda::ecmascript::JSObject; +using panda::ecmascript::PropertyDescriptor; namespace panda::test { class JsArgumentsTest : public testing::Test { @@ -44,9 +50,14 @@ public: { TestHelper::DestroyEcmaVMWithScope(instance, scope); } + +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: ecmascript::EcmaHandleScope *scope {nullptr}; PandaVM *instance {nullptr}; - JSThread *thread {nullptr}; }; static JSFunction *JSObjectTestCreate(JSThread *thread) @@ -63,6 +74,7 @@ TEST_F(JsArgumentsTest, SetProperty) thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(arg_func), arg_func); JSHandle arg = thread->GetEcmaVM()->GetFactory()->NewJSArguments(); + // NOLINTNEXTLINE(modernize-avoid-c-arrays) char array[] = "x"; JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(array)); JSHandle value(thread, JSTaggedValue(1)); @@ -86,6 +98,7 @@ TEST_F(JsArgumentsTest, GetProperty) thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(arg_func), arg_func); JSHandle arg = thread->GetEcmaVM()->GetFactory()->NewJSArguments(); + // NOLINTNEXTLINE(modernize-avoid-c-arrays) char array[] = "x"; JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(array)); JSHandle value(thread, JSTaggedValue(1)); @@ -108,6 +121,7 @@ TEST_F(JsArgumentsTest, DeleteProperty) thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(arg_func), arg_func); JSHandle arg = thread->GetEcmaVM()->GetFactory()->NewJSArguments(); + // NOLINTNEXTLINE(modernize-avoid-c-arrays) char array[] = "delete"; JSHandle key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(array)); JSHandle value(thread, JSTaggedValue(1)); diff --git a/tests/runtime/common/js_array_iterator_test.cpp b/tests/runtime/common/js_array_iterator_test.cpp index 4b5115c28a9b51d6e9246c12ae5cb5ee6f5f12b6..38942b4a79620db086e391405b0145b91adcd9cb 100644 --- a/tests/runtime/common/js_array_iterator_test.cpp +++ b/tests/runtime/common/js_array_iterator_test.cpp @@ -19,7 +19,13 @@ #include "plugins/ecmascript/runtime/object_factory.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" -using namespace panda::ecmascript; +using panda::ecmascript::IterationKind; +using panda::ecmascript::JSArray; +using panda::ecmascript::JSArrayIterator; +using panda::ecmascript::JSHandle; +using panda::ecmascript::JSObject; +using panda::ecmascript::ObjectFactory; +using panda::ecmascript::TaggedArray; namespace panda::test { class JSArrayIteratorTest : public testing::Test { @@ -43,9 +49,14 @@ public: { TestHelper::DestroyEcmaVMWithScope(instance, scope); } + +public: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread {nullptr}; }; /* @@ -61,7 +72,9 @@ TEST_F(JSArrayIteratorTest, SetIteratedArray) EcmaVM *ecma_vm_ptr = thread->GetEcmaVM(); ObjectFactory *factory = ecma_vm_ptr->GetFactory(); + // NOLINTNEXTLINE(modernize-avoid-c-arrays,readability-magic-numbers) uint32_t array_from1[10] = {0, 6, 8, 99, 200, 1, static_cast(-1), static_cast(-199), 33, 100}; + // NOLINTNEXTLINE(modernize-avoid-c-arrays,readability-magic-numbers) uint32_t array_from2[10] = {1111, 3211, 737, 0, 1267, 174, 2763, 832, 11, 93}; int num_array_from1 = sizeof(array_from1) / sizeof(array_from1[0]); int num_array_from2 = sizeof(array_from2) / sizeof(array_from2[0]); @@ -115,6 +128,7 @@ TEST_F(JSArrayIteratorTest, SetNextIndex) EcmaVM *ecma_vm_ptr = thread->GetEcmaVM(); ObjectFactory *factory = ecma_vm_ptr->GetFactory(); + // NOLINTNEXTLINE(modernize-avoid-c-arrays,readability-magic-numbers) uint32_t array[10] = {0, 6, 8, 99, 200, 1, static_cast(-1), static_cast(-199), 33, 100}; int num_array = sizeof(array) / sizeof(array[0]); JSHandle handle_tagged_array(factory->NewTaggedArray(num_array)); @@ -128,6 +142,7 @@ TEST_F(JSArrayIteratorTest, SetNextIndex) factory->NewJSArrayIterator(handle_js_object_tagged_array, IterationKind::KEY); EXPECT_EQ(handle_js_array_iter->GetNextIndex().GetNumber(), 0); + // NOLINTNEXTLINE(readability-magic-numbers) int test_quantity = 100; for (int i = 1; i <= test_quantity; i++) { JSHandle handle_tag_val_next_index(thread, JSTaggedValue(i)); @@ -151,6 +166,7 @@ TEST_F(JSArrayIteratorTest, SetIterationKind) EcmaVM *ecma_vm_ptr = thread->GetEcmaVM(); ObjectFactory *factory = ecma_vm_ptr->GetFactory(); + // NOLINTNEXTLINE(modernize-avoid-c-arrays,readability-magic-numbers) uint32_t array[10] = {0, 6, 8, 99, 200, 1, static_cast(-1), static_cast(-199), 33, 100}; int num_array = sizeof(array) / sizeof(array[0]); JSHandle handle_tagged_array(factory->NewTaggedArray(num_array)); diff --git a/tests/runtime/common/js_array_test.cpp b/tests/runtime/common/js_array_test.cpp index 20491b72a6f92940fe720b186c4a0992ab3b0bba..4d716985f4ec03a6d4f0a9e7deb19880ed510940 100644 --- a/tests/runtime/common/js_array_test.cpp +++ b/tests/runtime/common/js_array_test.cpp @@ -32,8 +32,18 @@ #include "plugins/ecmascript/runtime/js_iterator.h" #include "plugins/ecmascript/runtime/tagged_array-inl.h" -using namespace panda::ecmascript; -using namespace panda::coretypes; +using panda::ecmascript::EcmaString; +using panda::ecmascript::IterationKind; +using panda::ecmascript::JSArray; +using panda::ecmascript::JSArrayIterator; +using panda::ecmascript::JSHandle; +using panda::ecmascript::JSIterator; +using panda::ecmascript::JSObject; +using panda::ecmascript::JSTaggedNumber; +using panda::ecmascript::ObjectFactory; +using panda::ecmascript::ObjectOperator; +using panda::ecmascript::PropertyDescriptor; +using panda::ecmascript::TaggedArray; namespace panda::test { class JSArrayTest : public testing::Test { @@ -53,20 +63,25 @@ public: return JSObject::SetProperty(op, value, true); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: PandaVM *instance {nullptr}; EcmaHandleScope *scope {nullptr}; - JSThread *thread {nullptr}; }; TEST_F(JSArrayTest, ArrayCreate) { JSHandle length_key_handle(thread->GlobalConstants()->GetHandledLengthString()); - JSArray *arr = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetObject(); + auto *arr = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetObject(); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread, arr); EXPECT_EQ(JSArray::GetProperty(thread, obj, length_key_handle).GetValue()->GetInt(), 0); - JSArray *arr2 = JSArray::ArrayCreate(thread, JSTaggedNumber(10)).GetObject(); + // NOLINTNEXTLINE(readability-magic-numbers) + auto *arr2 = JSArray::ArrayCreate(thread, JSTaggedNumber(10)).GetObject(); EXPECT_TRUE(arr2 != nullptr); JSHandle obj2(thread, arr2); EXPECT_EQ(JSArray::GetProperty(thread, obj2, length_key_handle).GetValue()->GetInt(), 10); @@ -75,14 +90,16 @@ TEST_F(JSArrayTest, ArrayCreate) TEST_F(JSArrayTest, ArraySpeciesCreate) { JSHandle length_key_handle(thread->GlobalConstants()->GetHandledLengthString()); - JSArray *arr = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetObject(); + auto *arr = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetObject(); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread, arr); EXPECT_EQ(JSArray::GetProperty(thread, JSHandle(obj), length_key_handle).GetValue()->GetInt(), 0); + // NOLINTNEXTLINE(readability-magic-numbers) JSArray *arr2 = JSArray::Cast(JSArray::ArraySpeciesCreate(thread, obj, JSTaggedNumber(10)).GetHeapObject()); EXPECT_TRUE(arr2 != nullptr); JSHandle obj2(thread, arr2); + // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(JSArray::GetProperty(thread, obj2, length_key_handle).GetValue()->GetInt(), 10); } @@ -91,11 +108,12 @@ TEST_F(JSArrayTest, DefineOwnProperty) auto ecma_vm = thread->GetEcmaVM(); auto factory = ecma_vm->GetFactory(); JSHandle length_key_handle(thread->GlobalConstants()->GetHandledLengthString()); - JSArray *arr = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetObject(); + auto *arr = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetObject(); EXPECT_TRUE(arr != nullptr); JSHandle obj(thread, arr); EXPECT_EQ(JSArray::GetProperty(thread, obj, length_key_handle).GetValue()->GetInt(), 0); + // NOLINTNEXTLINE(readability-magic-numbers) PropertyDescriptor desc(thread, JSHandle(thread, JSTaggedValue(100)), true, true, true); EcmaLanguageContext ecma_language_context; @@ -106,27 +124,37 @@ TEST_F(JSArrayTest, DefineOwnProperty) EXPECT_TRUE(JSArray::DefineOwnProperty(thread, JSHandle(obj), key1, desc)); EXPECT_EQ(JSArray::GetProperty(thread, obj, length_key_handle).GetValue()->GetInt(), 2); TaggedValue v = JSArray::GetProperty(thread, obj, key1).GetValue().GetTaggedValue(); + // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(v.GetInt(), 100); v = JSArray::GetProperty(thread, obj, index1).GetValue().GetTaggedValue(); + // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(v.GetInt(), 100); EXPECT_EQ(JSArray::GetProperty(thread, obj, length_key_handle).GetValue()->GetInt(), 2); EcmaString *string100 = *factory->NewFromString("100"); JSHandle key100(thread, static_cast(string100)); + // NOLINTNEXTLINE(readability-magic-numbers) JSHandle index100(thread, JSTaggedValue(100)); EXPECT_TRUE(JSArray::DefineOwnProperty(thread, JSHandle(obj), key100, desc)); + // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(JSArray::GetProperty(thread, obj, key100).GetValue()->GetInt(), 100); + // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(JSArray::GetProperty(thread, obj, index100).GetValue()->GetInt(), 100); + // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(JSArray::GetProperty(thread, obj, length_key_handle).GetValue()->GetInt(), 101); EcmaString *stringx = *factory->NewFromString("2147483646"); JSHandle keyx(thread, static_cast(stringx)); + // NOLINTNEXTLINE(readability-magic-numbers) JSHandle indexx(thread, JSTaggedValue(2147483646U)); // 2147483646U EXPECT_TRUE(JSArray::DefineOwnProperty(thread, JSHandle(obj), keyx, desc)); + // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(JSArray::GetProperty(thread, obj, keyx).GetValue()->GetInt(), 100); + // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(JSArray::GetProperty(thread, obj, indexx).GetValue()->GetInt(), 100); + // NOLINTNEXTLINE(readability-magic-numbers) EXPECT_EQ(JSArray::GetProperty(thread, obj, length_key_handle).GetValue()->GetInt(), 2147483647); EXPECT_TRUE(JSArray::DeleteProperty(thread, JSHandle(obj), indexx)); @@ -195,7 +223,7 @@ TEST_F(JSArrayTest, Iterator) TEST_F(JSArrayTest, AddProperty) { - JSArray *arr = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetObject(); + auto *arr = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetObject(); ASSERT_TRUE(arr != nullptr); JSHandle obj(thread, arr); JSHandle key(thread, JSTaggedValue(1)); diff --git a/tests/runtime/common/js_dataview_test.cpp b/tests/runtime/common/js_dataview_test.cpp index fb535ab5462763b6446c65c3f6c5970408d1159d..cfbe2653c3d07a23264047deb8f56bade69b5010 100644 --- a/tests/runtime/common/js_dataview_test.cpp +++ b/tests/runtime/common/js_dataview_test.cpp @@ -19,6 +19,7 @@ #include "plugins/ecmascript/runtime/object_factory.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; namespace panda::test { @@ -43,9 +44,14 @@ public: { TestHelper::DestroyEcmaVMWithScope(instance, scope); } + +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread {nullptr}; }; /* @@ -119,6 +125,7 @@ TEST_F(JSDataViewTest, SetViewedArrayBuffer) JSHandle handle_tag_val_func_array_buf(handle_func_array_buf); int32_t length_data_array_buf1 = 8; + // NOLINTNEXTLINE(readability-magic-numbers) int32_t length_data_array_buf2 = 16; int32_t offset_data_view = 4; int32_t length_data_view = 4; diff --git a/tests/runtime/common/js_date_test.cpp b/tests/runtime/common/js_date_test.cpp index 149fa494015d14890ccf489b07cc2416d48522db..24db2da4abed817ad5fa719b9a9e8718ed1be12b 100644 --- a/tests/runtime/common/js_date_test.cpp +++ b/tests/runtime/common/js_date_test.cpp @@ -22,7 +22,9 @@ #include "plugins/ecmascript/runtime/js_function.h" #include "plugins/ecmascript/runtime/global_env.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::coretypes; namespace panda::test { @@ -38,9 +40,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread; }; JSDate *JSDateCreate(JSThread *thread) @@ -60,6 +66,7 @@ TEST_F(JSDateTest, Create) JSHandle js_date(thread, JSDateCreate(thread)); EXPECT_EQ(js_date->GetTimeValue(), JSTaggedValue(tm)); EXPECT_EQ(js_date->GetLocalOffset(), JSTaggedValue(JSDate::MAX_DOUBLE)); + // NOLINTNEXTLINE(readability-magic-numbers) tm = 28 * 60 * 60 * 1000; js_date->SetTimeValue(thread, JSTaggedValue(tm)); diff --git a/tests/runtime/common/js_forin_iterator_test.cpp b/tests/runtime/common/js_forin_iterator_test.cpp index 244493aa4de80df588cd597534452f150be97b6f..d9fcd83deff5e79b30cd1373445b224e226ca41f 100644 --- a/tests/runtime/common/js_forin_iterator_test.cpp +++ b/tests/runtime/common/js_forin_iterator_test.cpp @@ -21,8 +21,10 @@ #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/js_handle.h" -using namespace panda::ecmascript; -using namespace panda::coretypes; +using panda::ecmascript::JSForInIterator; +using panda::ecmascript::JSHandle; +using panda::ecmascript::JSObject; +using panda::ecmascript::JSThread; namespace panda::test { class JSForinIteratorTest : public testing::Test { @@ -37,9 +39,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread; }; TEST_F(JSForinIteratorTest, Create) diff --git a/tests/runtime/common/js_handle_test.cpp b/tests/runtime/common/js_handle_test.cpp index 8c7de224314676b09f14a416746f3481ebd54632..c6ee53f919720b273748af183b3bcb78b92ae893 100644 --- a/tests/runtime/common/js_handle_test.cpp +++ b/tests/runtime/common/js_handle_test.cpp @@ -20,8 +20,11 @@ #include "plugins/ecmascript/runtime/object_factory.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; +// NOLINTBEGIN(readability-magic-numbers,readability-redundant-string-cstr,modernize-avoid-c-arrays) + namespace panda::test { class JSHandleTest : public testing::Test { public: @@ -45,9 +48,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread {nullptr}; }; TEST_F(JSHandleTest, NewGlobalHandle) @@ -76,6 +83,7 @@ static void FillGlobalString(uintptr_t global_string[], int length, EcmaGlobalSt for (int i = 0; i < length; i++) { std::string test = "test" + std::to_string(i); auto string1 = factory->NewFromString(test.c_str()); + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) global_string[i] = global->NewGlobalHandle(string1.GetTaggedType()); } } @@ -216,3 +224,5 @@ TEST_F(JSHandleTest, DISABLED_NewWeakGlobalHandle1) } } } // namespace panda::test + +// NOLINTEND(readability-magic-numbers,readability-redundant-string-cstr,modernize-avoid-c-arrays) diff --git a/tests/runtime/common/js_iterator_test.cpp b/tests/runtime/common/js_iterator_test.cpp index 62a98e21af1173b70627d90821550e3cf0cf9d4b..9b0f57dc9bf60d4fc55474b3ccd399f2abea9b6a 100644 --- a/tests/runtime/common/js_iterator_test.cpp +++ b/tests/runtime/common/js_iterator_test.cpp @@ -30,10 +30,8 @@ #include "plugins/ecmascript/runtime/js_array.h" #include "plugins/ecmascript/runtime/tagged_array-inl.h" -using namespace panda; - +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; -using namespace panda::coretypes; namespace panda::test { class JSIteratorTest : public testing::Test { @@ -48,9 +46,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread; }; TEST_F(JSIteratorTest, GetIterator) diff --git a/tests/runtime/common/js_map_test.cpp b/tests/runtime/common/js_map_test.cpp index 6f8eeb4584a6f21ad37d6bcf21b57a0b71a967ba..48c036a51afcb4fee0f15015474ed7cb3715ff21 100644 --- a/tests/runtime/common/js_map_test.cpp +++ b/tests/runtime/common/js_map_test.cpp @@ -32,10 +32,8 @@ #include "plugins/ecmascript/runtime/js_iterator.h" #include "plugins/ecmascript/runtime/js_map_iterator.h" -using namespace panda; - +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; -using namespace panda::coretypes; namespace panda::test { class JSMapTest : public testing::Test { @@ -50,11 +48,10 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } - PandaVM *instance {nullptr}; - ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread; - protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + JSMap *CreateMap() { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -66,6 +63,10 @@ protected: map->SetLinkedMap(thread, hash_map); return *map; } + +private: + PandaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; }; TEST_F(JSMapTest, MapCreate) @@ -94,7 +95,9 @@ TEST_F(JSMapTest, DeleteAndGet) JSHandle map(thread, CreateMap()); // add 40 keys + // NOLINTNEXTLINE(modernize-avoid-c-arrays) char key_array[] = "key0"; + // NOLINTNEXTLINE(readability-magic-numbers) for (int i = 0; i < 40; i++) { key_array[3] = '1' + i; JSHandle key(factory->NewFromString(key_array)); @@ -121,6 +124,7 @@ TEST_F(JSMapTest, Iterator) JSHandle map(thread, CreateMap()); for (int i = 0; i < 5; i++) { JSHandle key(thread, JSTaggedValue(i)); + // NOLINTNEXTLINE(readability-magic-numbers) JSHandle value(thread, JSTaggedValue(i + 10)); JSMap::Set(thread, map, key, value); } diff --git a/tests/runtime/common/js_primitive_ref_test.cpp b/tests/runtime/common/js_primitive_ref_test.cpp index 11509b15c57adcfd463ad1f50cb8c3da93fe7713..76973a5baa8f1e893afecac08e9abd87a819e4a1 100644 --- a/tests/runtime/common/js_primitive_ref_test.cpp +++ b/tests/runtime/common/js_primitive_ref_test.cpp @@ -28,8 +28,8 @@ #include "plugins/ecmascript/runtime/object_factory.h" #include "plugins/ecmascript/runtime/ecma_vm.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; -using namespace panda::coretypes; namespace panda::test { class JSPrimitiveRefTest : public testing::Test { @@ -44,9 +44,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread; }; TEST_F(JSPrimitiveRefTest, StringCreate) diff --git a/tests/runtime/common/js_promise_test.cpp b/tests/runtime/common/js_promise_test.cpp index 18bf13c6af65e989fd5f842323aef033e4949a9b..88cdbb9e8469aa88df161a39851e8b7a970c83df 100644 --- a/tests/runtime/common/js_promise_test.cpp +++ b/tests/runtime/common/js_promise_test.cpp @@ -29,9 +29,8 @@ #include "plugins/ecmascript/runtime/js_promise.h" #include "include/runtime_options.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; -using namespace panda::ecmascript::base; -using namespace panda::coretypes; namespace panda::test { class JSPromiseTest : public testing::Test { @@ -46,7 +45,11 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) JSThread *thread {nullptr}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; }; @@ -102,6 +105,7 @@ TEST_F(JSPromiseTest, FullFillPromise) JSHandle undefined(thread, JSTaggedValue::Undefined()); auto info = NewRuntimeCallInfo(thread, resolve, undefined, JSTaggedValue::Undefined(), 1); + // NOLINTNEXTLINE(readability-magic-numbers) info->SetCallArgs(JSTaggedValue(33)); JSFunction::Call(info.Get()); EXPECT_EQ(static_cast(new_promise->GetPromiseState().GetInt()), PromiseStatus::FULFILLED); @@ -122,6 +126,7 @@ TEST_F(JSPromiseTest, RejectPromise) JSHandle undefined(thread, JSTaggedValue::Undefined()); auto info = NewRuntimeCallInfo(thread, reject, undefined, JSTaggedValue::Undefined(), 1); + // NOLINTNEXTLINE(readability-magic-numbers) info->SetCallArgs(JSTaggedValue(44)); JSFunction::Call(info.Get()); EXPECT_EQ(static_cast(new_promise->GetPromiseState().GetInt()), PromiseStatus::REJECTED); diff --git a/tests/runtime/common/js_proxy_test.cpp b/tests/runtime/common/js_proxy_test.cpp index 6192410ebe9e474e2a10af6f9f56c0c9a37f9566..715e54cd35391d6e1ddc4771fce0fc8196554780 100644 --- a/tests/runtime/common/js_proxy_test.cpp +++ b/tests/runtime/common/js_proxy_test.cpp @@ -30,9 +30,8 @@ #include "plugins/ecmascript/runtime/js_function.h" #include "plugins/ecmascript/runtime/global_env.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; -using namespace panda::ecmascript::base; -using namespace panda::coretypes; namespace panda::test { class JSProxyTest : public testing::Test { @@ -47,9 +46,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread; }; static JSFunction *JSObjectTestCreate(JSThread *thread) @@ -86,6 +89,7 @@ TEST_F(JSProxyTest, ProxyCreate) // ES6 9.5.8 [[Get]] (P, Receiver) JSTaggedValue HandlerGetProperty([[maybe_unused]] EcmaRuntimeCallInfo *argv) { + // NOLINTNEXTLINE(readability-magic-numbers) return JSTaggedValue(10); } @@ -203,6 +207,7 @@ TEST_F(JSProxyTest, SetProperty) JSHandle proxy_handle2(JSProxy::ProxyCreate(thread, target_handle, handler_handle)); EXPECT_TRUE(*proxy_handle2 != nullptr); + // NOLINTNEXTLINE(readability-magic-numbers) JSHandle value2(thread, JSTaggedValue(10)); EXPECT_FALSE(JSProxy::SetProperty(thread, proxy_handle2, key, value2)); EXPECT_EQ(JSProxy::GetProperty(thread, proxy_handle2, key).GetValue()->GetInt(), 1); @@ -245,6 +250,7 @@ TEST_F(JSProxyTest, DefineOwnProperty) JSHandle proxy_handle2 = JSProxy::ProxyCreate(thread, target_handle, handler_handle); EXPECT_TRUE(*proxy_handle2 != nullptr); + // NOLINTNEXTLINE(readability-magic-numbers) PropertyDescriptor desc2(thread, JSHandle(thread, JSTaggedValue(10))); EXPECT_FALSE(JSProxy::DefineOwnProperty(thread, proxy_handle, key, desc2)); EXPECT_EQ(JSProxy::GetProperty(thread, proxy_handle2, key).GetValue()->GetInt(), 1); diff --git a/tests/runtime/common/js_set_iterator_test.cpp b/tests/runtime/common/js_set_iterator_test.cpp index 94cf7b6cbd8e03845efce84c16fe0b77f1b013c2..75ae59fb285b642a88e99d1763cf5c9d813d97e0 100644 --- a/tests/runtime/common/js_set_iterator_test.cpp +++ b/tests/runtime/common/js_set_iterator_test.cpp @@ -20,6 +20,7 @@ #include "plugins/ecmascript/runtime/object_factory.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; namespace panda::test { @@ -44,9 +45,14 @@ public: { TestHelper::DestroyEcmaVMWithScope(instance, scope); } + +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: ecmascript::EcmaHandleScope *scope {nullptr}; PandaVM *instance {nullptr}; - JSThread *thread {nullptr}; }; JSSet *CreateSet(JSThread *thread) diff --git a/tests/runtime/common/js_set_test.cpp b/tests/runtime/common/js_set_test.cpp index af3f1c5aa8bfb433e2ef4820901aea7c21423800..de4907df6510b2c8e4689b6ff3ed17acb5c0c3b4 100644 --- a/tests/runtime/common/js_set_test.cpp +++ b/tests/runtime/common/js_set_test.cpp @@ -32,10 +32,8 @@ #include "plugins/ecmascript/runtime/js_iterator.h" #include "plugins/ecmascript/runtime/js_set_iterator.h" -using namespace panda; - +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; -using namespace panda::coretypes; namespace panda::test { class JSSetTest : public testing::Test { @@ -50,11 +48,10 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } - PandaVM *instance {nullptr}; - EcmaHandleScope *scope {nullptr}; - JSThread *thread; - protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + JSSet *CreateSet() { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -67,6 +64,10 @@ protected: set->SetLinkedSet(thread, hash_set); return JSSet::Cast(set.GetTaggedValue().GetTaggedObject()); } + +private: + PandaVM *instance {nullptr}; + EcmaHandleScope *scope {nullptr}; }; TEST_F(JSSetTest, SetCreate) @@ -95,7 +96,9 @@ TEST_F(JSSetTest, DeleteAndGet) JSHandle set(thread, CreateSet()); // add 40 keys + // NOLINTNEXTLINE(modernize-avoid-c-arrays) char key_array[] = "key0"; + // NOLINTNEXTLINE(readability-magic-numbers) for (int i = 0; i < 40; i++) { key_array[3] = '1' + i; JSHandle key(factory->NewFromString(key_array)); diff --git a/tests/runtime/common/js_symbol_test.cpp b/tests/runtime/common/js_symbol_test.cpp index 40c2819cf18171841f5b4ccf36f17f07c63beb6a..4d5f59151373d6bc69fc563c6f7d2ca630249c78 100644 --- a/tests/runtime/common/js_symbol_test.cpp +++ b/tests/runtime/common/js_symbol_test.cpp @@ -46,9 +46,10 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread; + JSThread *thread {}; }; } // namespace panda::test diff --git a/tests/runtime/common/js_tagged_queue_test.cpp b/tests/runtime/common/js_tagged_queue_test.cpp index 757cfea88e2014f31a39c2985b24a330ae28830d..3df1279bc6d4f4648cadd9739af77a54f3c67baf 100644 --- a/tests/runtime/common/js_tagged_queue_test.cpp +++ b/tests/runtime/common/js_tagged_queue_test.cpp @@ -24,8 +24,8 @@ #include "plugins/ecmascript/runtime/object_factory.h" #include "plugins/ecmascript/runtime/global_env.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; -using namespace panda::coretypes; namespace panda::test { class JSTaggedQueueTest : public testing::Test { @@ -40,9 +40,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread; }; TEST_F(JSTaggedQueueTest, Create) diff --git a/tests/runtime/common/js_typed_array_test.cpp b/tests/runtime/common/js_typed_array_test.cpp index 9e75cf574c28b66bfe7e716689d4eca80635e986..d3b622cb719cdd5b0a4fdecf2977a1f73319e625 100644 --- a/tests/runtime/common/js_typed_array_test.cpp +++ b/tests/runtime/common/js_typed_array_test.cpp @@ -16,8 +16,10 @@ #include "plugins/ecmascript/runtime/base/typed_array_helper-inl.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; -using namespace std; + +// NOLINTBEGIN(readability-magic-numbers,modernize-avoid-c-arrays,modernize-loop-convert) namespace panda::test { class JSTypedArrayTest : public testing::Test { @@ -41,23 +43,30 @@ public: { TestHelper::DestroyEcmaVMWithScope(instance, scope); } - PandaVM *instance {nullptr}; - EcmaHandleScope *scope {nullptr}; + +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) JSThread *thread {nullptr}; - const vector c_vec_js_type_ { + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + const std::vector c_vec_js_type_ { JSType::JS_INT8_ARRAY, JSType::JS_UINT8_ARRAY, JSType::JS_UINT8_CLAMPED_ARRAY, JSType::JS_INT16_ARRAY, JSType::JS_UINT16_ARRAY, JSType::JS_INT32_ARRAY, JSType::JS_UINT32_ARRAY, JSType::JS_FLOAT32_ARRAY, JSType::JS_FLOAT64_ARRAY}; // PandaVector pushed with JSTaggedValue made from compatible input value for the JSType - const vector c_vec_handle_tag_val_value_for_typed_array_ { + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + const std::vector c_vec_handle_tag_val_value_for_typed_array_ { // Use "(S)(...)" cast to make v in "JSTaggedValue(T v) : coretypes::TaggedValue(v) {}" compatible with S JSTaggedValue((int8_t)(-111)), JSTaggedValue((uint8_t)(222)), JSTaggedValue((uint8_t)(222)), JSTaggedValue((int16_t)(-31111)), JSTaggedValue((uint16_t)(61111)), // int32 : -2147483648->2147483647, uint32 : 0->4294967295 JSTaggedValue((int32_t)(2111111111)), JSTaggedValue((uint32_t)(4111111111)), JSTaggedValue((float)(4321.1234)), JSTaggedValue((double)(987654321.123456789))}; + +private: + PandaVM *instance {nullptr}; + EcmaHandleScope *scope {nullptr}; }; JSHandle CreateNumberTypedArray(JSThread *thread, JSType js_type) @@ -1365,3 +1374,5 @@ TEST_F(JSTypedArrayTest, FastCopyElementToArray_TypedArray) } } } // namespace panda::test + +// NOLINTEND(readability-magic-numbers,modernize-avoid-c-arrays,modernize-loop-convert) diff --git a/tests/runtime/common/large_object_test.cpp b/tests/runtime/common/large_object_test.cpp index c159a8458ff1270d84b36779a9ddc182bd1a2b39..9090634da2860f0fa90078ce77b377ed791082b1 100644 --- a/tests/runtime/common/large_object_test.cpp +++ b/tests/runtime/common/large_object_test.cpp @@ -25,8 +25,8 @@ #include "plugins/ecmascript/runtime/tagged_array-inl.h" #include "plugins/ecmascript/runtime/object_factory.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; -using namespace panda::coretypes; namespace panda::test { class LargeObjectTest : public testing::Test { @@ -42,7 +42,11 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } - JSThread *thread; +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; }; @@ -64,6 +68,7 @@ static JSObject *JSObjectTestCreate(JSThread *thread) static TaggedArray *LargeArrayTestCreate(JSThread *thread) { [[maybe_unused]] ecmascript::EcmaHandleScope scope(thread); + // NOLINTNEXTLINE(readability-magic-numbers) JSHandle array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(20 * 10000); return *array; } diff --git a/tests/runtime/common/lexical_env_test.cpp b/tests/runtime/common/lexical_env_test.cpp index 2abb76a303f95953b91bee0977678be917126a61..5168ab0c0baee27bb03b8e39d3a6489dc259d60a 100644 --- a/tests/runtime/common/lexical_env_test.cpp +++ b/tests/runtime/common/lexical_env_test.cpp @@ -19,6 +19,7 @@ #include "plugins/ecmascript/runtime/lexical_env.h" #include "plugins/ecmascript/runtime/object_factory.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; namespace panda::test { @@ -34,9 +35,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread; }; TEST_F(LexicalEnvTest, LexicalEnv_Create) diff --git a/tests/runtime/common/linked_hash_table_test.cpp b/tests/runtime/common/linked_hash_table_test.cpp index dae0248e79314fb4cfbe53995d4b41a39d94628e..fe97a400c56d6d4761aa57eafea1a0bc58b96bec 100644 --- a/tests/runtime/common/linked_hash_table_test.cpp +++ b/tests/runtime/common/linked_hash_table_test.cpp @@ -24,10 +24,11 @@ #include "plugins/ecmascript/runtime/tagged_hash_table-inl.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" -using namespace panda; - +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; +// NOLINTBEGIN(readability-magic-numbers,modernize-avoid-c-arrays) + namespace panda::test { class LinkedHashTableTest : public testing::Test { public: @@ -51,15 +52,19 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } - PandaVM *instance {nullptr}; - EcmaHandleScope *scope {nullptr}; - JSThread *thread {nullptr}; - JSHandle GetGlobalEnv() { EcmaVM *ecma = thread->GetEcmaVM(); return ecma->GetGlobalEnv(); } + +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: + PandaVM *instance {nullptr}; + EcmaHandleScope *scope {nullptr}; }; TEST_F(LinkedHashTableTest, MapCreate) @@ -292,3 +297,5 @@ TEST_F(LinkedHashTableTest, SetShrinkCapacity) EXPECT_EQ(set_handle->Capacity(), 16); } } // namespace panda::test + +// NOLINTEND(readability-magic-numbers,modernize-avoid-c-arrays) diff --git a/tests/runtime/common/name_dictionary_test.cpp b/tests/runtime/common/name_dictionary_test.cpp index 4d8a9f97363b399edf1f9ac6e84fb4f5c29969f5..a2934db78da2ff9755178b4f8ed2c9054ff70aea 100644 --- a/tests/runtime/common/name_dictionary_test.cpp +++ b/tests/runtime/common/name_dictionary_test.cpp @@ -27,10 +27,11 @@ #include "plugins/ecmascript/runtime/tagged_hash_table.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" -using namespace panda; - +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; +// NOLINTBEGIN(readability-magic-numbers,modernize-avoid-c-arrays) + namespace panda::test { class NameDictionaryTest : public testing::Test { public: @@ -54,9 +55,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: PandaVM *instance {nullptr}; EcmaHandleScope *scope {nullptr}; - JSThread *thread {nullptr}; }; static JSHandle GetGlobalEnv(JSThread *thread) @@ -191,3 +196,5 @@ TEST_F(NameDictionaryTest, ShrinkCapacity) EXPECT_EQ(dict_handle->Size(), 16); } } // namespace panda::test + +// NOLINTEND(readability-magic-numbers,modernize-avoid-c-arrays) diff --git a/tests/runtime/common/native_methods_api_no_crash/native_methods_api_no_crash.cpp b/tests/runtime/common/native_methods_api_no_crash/native_methods_api_no_crash.cpp index a3d3e9e783e07ffef39186df649bc2d84d47ddf1..bce4a51d8dfb1e9dddc49374ebe92e804f668705 100644 --- a/tests/runtime/common/native_methods_api_no_crash/native_methods_api_no_crash.cpp +++ b/tests/runtime/common/native_methods_api_no_crash/native_methods_api_no_crash.cpp @@ -99,13 +99,13 @@ TEST_F(EcmaEmptyClassCheck, TestJSABC) RuntimeOptions options; options.SetLoadRuntimes({"ecmascript"}); options.SetBootPandaFiles({}); + // NOLINTNEXTLINE(readability-magic-numbers) options.SetHeapSizeLimit(50_MB); options.SetGcType("epsilon"); ASSERT_TRUE(Runtime::Create(options)); - panda::ecmascript::EcmaVM *ecma_vm = - reinterpret_cast(Runtime::GetCurrent()->GetPandaVM()); + auto *ecma_vm = reinterpret_cast(Runtime::GetCurrent()->GetPandaVM()); for (Method *m : ecma_vm->GetNativeMethods()) { CheckAPINoCrash(m); diff --git a/tests/runtime/common/native_pointer_test.cpp b/tests/runtime/common/native_pointer_test.cpp index 34cc5eb279bac5c7a2e4edec31d0c00f956a27ba..7c88cc13bbd859243ea542bfb273f2b41bc0ed60 100644 --- a/tests/runtime/common/native_pointer_test.cpp +++ b/tests/runtime/common/native_pointer_test.cpp @@ -22,6 +22,7 @@ #include "plugins/ecmascript/runtime/object_factory.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; using FunctionPtr = void (*)(panda::ecmascript::JSHandle &); @@ -49,14 +50,19 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread {nullptr}; }; TEST_F(NativePointerTest, Print) { // mock object needed in test + // NOLINTNEXTLINE(modernize-avoid-c-arrays) char array[] = "Hello World!"; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); diff --git a/tests/runtime/common/object_factory_test.cpp b/tests/runtime/common/object_factory_test.cpp index 12ff87868cfd6f4bc55589c8ed8fcb492c44cbb8..0def03aa3b0b499ad0d8f0bef631a14322a39873 100644 --- a/tests/runtime/common/object_factory_test.cpp +++ b/tests/runtime/common/object_factory_test.cpp @@ -27,8 +27,7 @@ #include "plugins/ecmascript/runtime/tagged_array-inl.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" -using namespace panda; - +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; namespace panda::test { @@ -54,9 +53,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread {nullptr}; }; JSHandle GetGlobal(JSThread *thread) diff --git a/tests/runtime/common/separate_jsvm_test.cpp b/tests/runtime/common/separate_jsvm_test.cpp index 89b17215d7d9a98af4327592ccb3e32b04087314..bb9f4741ef4505713ed57b64d15ce3d6cd1d4453 100644 --- a/tests/runtime/common/separate_jsvm_test.cpp +++ b/tests/runtime/common/separate_jsvm_test.cpp @@ -23,10 +23,8 @@ #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" -using namespace panda; - +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; -using namespace panda::coretypes; namespace panda::test { class SepareteJSVMTest : public testing::Test { @@ -62,8 +60,6 @@ public: ecma_vm->StartGC(); return ecma_vm; } - - PandaVM *instance; }; TEST_F(SepareteJSVMTest, CreateInstance) diff --git a/tests/runtime/common/symbol_table_test.cpp b/tests/runtime/common/symbol_table_test.cpp index cf59b9e7a870142c9cf997aca91c01743ba8b2e5..d5b3a50cd673f693f768410f5203c090a5c00815 100644 --- a/tests/runtime/common/symbol_table_test.cpp +++ b/tests/runtime/common/symbol_table_test.cpp @@ -20,6 +20,8 @@ #include "plugins/ecmascript/runtime/js_tagged_value.h" #include "plugins/ecmascript/runtime/tagged_array-inl.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" + +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; namespace panda::test { @@ -44,9 +46,14 @@ public: { TestHelper::DestroyEcmaVMWithScope(instance, scope); } + +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {nullptr}; + +private: ecmascript::EcmaHandleScope *scope {nullptr}; PandaVM *instance {nullptr}; - JSThread *thread {nullptr}; }; TEST_F(SymbolTableTest, GetKeyIndex) @@ -116,11 +123,13 @@ TEST_F(SymbolTableTest, Hash_Utf8) bool flag = EcmaString::GetCompressedStringsEnabled(); EXPECT_EQ(flag, true); + // NOLINTNEXTLINE(modernize-avoid-c-arrays) uint8_t utf8_array_name1[4] = {1, 2, 3}; // The last element is "\0" uint32_t utf8_array_name_len1 = sizeof(utf8_array_name1) - 1; JSHandle name_string_utf8_obj1 = factory->NewFromUtf8(utf8_array_name1, utf8_array_name_len1); EXPECT_EQ(SymbolTable::Hash(name_string_utf8_obj1.GetTaggedValue()), 1026); // 1026 = (1 << 5 - 1 + 2) << 5 - 2 + 3 + // NOLINTNEXTLINE(modernize-avoid-c-arrays) uint8_t utf8_array_name2[] = "key"; uint32_t utf8_array_name_len2 = sizeof(utf8_array_name2) - 1; JSHandle name_string_utf8_obj2 = factory->NewFromUtf8(utf8_array_name2, utf8_array_name_len2); @@ -139,12 +148,14 @@ TEST_F(SymbolTableTest, Hash_Utf16) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + // NOLINTNEXTLINE(modernize-avoid-c-arrays) uint16_t utf16_array_name1[] = {1, 2, 3}; uint32_t utf16_array_name_len1 = sizeof(utf16_array_name1) / sizeof(utf16_array_name1[0]); JSHandle name_string_utf16_obj1 = factory->NewFromUtf16(utf16_array_name1, utf16_array_name_len1); EXPECT_EQ(SymbolTable::Hash(name_string_utf16_obj1.GetTaggedValue()), 1026); // 1026 = (1 << 5 - 1 + 2) << 5 - 2 + 3 + // NOLINTNEXTLINE(modernize-avoid-c-arrays) uint16_t utf16_array_name2[] = {0, 1, 2}; uint32_t utf16_array_name_len2 = sizeof(utf16_array_name2) / sizeof(utf16_array_name2[0]); JSHandle name_string_utf16_obj2 = factory->NewFromUtf16(utf16_array_name2, utf16_array_name_len2); diff --git a/tests/runtime/common/tagged_value_test.cpp b/tests/runtime/common/tagged_value_test.cpp index c760b1b17ab2ae32f566f3260b8f4f7abea2cb2b..59d384abddd075dca968c197652ed6a3f3fee18d 100644 --- a/tests/runtime/common/tagged_value_test.cpp +++ b/tests/runtime/common/tagged_value_test.cpp @@ -28,9 +28,12 @@ #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; +using panda::coretypes::ReinterpretDoubleToTaggedType; +using panda::coretypes::ReinterpretTaggedTypeToDouble; -using namespace panda::coretypes; +// NOLINTBEGIN(readability-magic-numbers) namespace panda::test { class JSTaggedValueTest : public testing::Test { @@ -45,9 +48,13 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; + +private: PandaVM *instance {nullptr}; ecmascript::EcmaHandleScope *scope {nullptr}; - JSThread *thread; }; TEST_F(JSTaggedValueTest, Double) @@ -82,7 +89,7 @@ TEST_F(JSTaggedValueTest, Int) TEST_F(JSTaggedValueTest, IsObject) { - panda::ObjectHeader *p = reinterpret_cast(0xffff0000UL); + auto *p = reinterpret_cast(0xffff0000UL); JSTaggedValue t(p); EXPECT_EQ(true, t.IsObject()); EXPECT_EQ(false, t.IsInt()); @@ -761,7 +768,7 @@ void CheckOkString(JSThread *thread, const JSHandle &tagged, Pand TEST_F(JSTaggedValueTest, ToString) { - PandaString right_c_str = ""; + PandaString right_c_str; CheckOkString(thread, JSHandle(thread, JSTaggedValue()), right_c_str); right_c_str = "undefined"; @@ -782,7 +789,7 @@ TEST_F(JSTaggedValueTest, ToString) right_c_str); double num = 1; - JSTaggedNumber number_num = JSTaggedNumber(num); + auto number_num = JSTaggedNumber(num); right_c_str = "1"; CheckOkString(thread, JSHandle(thread, number_num), right_c_str); @@ -1197,3 +1204,5 @@ TEST_F(JSTaggedValueTest, StrictEqual) JSHandle(thread, JSTaggedValue(std::numeric_limits::quiet_NaN())))); } } // namespace panda::test + +// NOLINTEND(readability-magic-numbers) diff --git a/tests/runtime/common/test_helper.cpp b/tests/runtime/common/test_helper.cpp index 8d45442631b713de9f27c59c452bf7249e13decf..6c84865737a17d1cb15b61284e8ff073b4b54963 100644 --- a/tests/runtime/common/test_helper.cpp +++ b/tests/runtime/common/test_helper.cpp @@ -22,6 +22,7 @@ using panda::ecmascript::JSTaggedValue; using panda::ecmascript::JSThread; thread_local bool TestHelper::is_leaf_ = true; +// NOLINTNEXTLINE(fuchsia-statically-constructed-objects) ecmascript::JSHandle TestHelper::method_function_ {}; std::unique_ptr TestHelper::CreateEcmaRuntimeCallInfo(JSThread *thread, JSTaggedValue new_tgt, @@ -57,6 +58,7 @@ std::unique_ptr TestHelper::CreateEcmaRuntimeCallInfo(JSThr Frame *TestHelper::SetupFrame(JSThread *thread, [[maybe_unused]] EcmaRuntimeCallInfo *info) { is_leaf_ = false; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) ASSERT((void *)info->GetArgAddress(0) == &thread->GetCurrentFrame()->GetVReg(0)); return thread->GetCurrentFrame()->GetPrevFrame(); } diff --git a/tests/runtime/mem/g1gc_barrier_test.cpp b/tests/runtime/mem/g1gc_barrier_test.cpp index 729db8b58ca655b48b1f528ee2383f8e33d9cf97..894b325c7f8532261d281c4d29dd4ebd0727efad 100644 --- a/tests/runtime/mem/g1gc_barrier_test.cpp +++ b/tests/runtime/mem/g1gc_barrier_test.cpp @@ -18,6 +18,10 @@ namespace panda::ecmascript { class G1GCBarrierTest : public testing::Test { public: + NO_COPY_SEMANTIC(G1GCBarrierTest); + NO_MOVE_SEMANTIC(G1GCBarrierTest); + + // NOLINTNEXTLINE(readability-magic-numbers) explicit G1GCBarrierTest(size_t promotion_region_alive_rate = 100) { RuntimeOptions options; @@ -36,11 +40,11 @@ public: thread = JSThread::GetCurrent(); const GlobalEnvConstants *global_const = thread->GlobalConstants(); - string_class = JSHClass::Cast(global_const->GetStringClass().GetTaggedObject()); - array_class = JSHClass::Cast(global_const->GetArrayClass().GetTaggedObject()); + string_class_ = JSHClass::Cast(global_const->GetStringClass().GetTaggedObject()); + array_class_ = JSHClass::Cast(global_const->GetArrayClass().GetTaggedObject()); } - ~G1GCBarrierTest() + ~G1GCBarrierTest() override { Runtime::Destroy(); } @@ -56,21 +60,28 @@ public: size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), length); mem::HeapManager *heap_manager = thread->GetVM()->GetHeapManager(); auto *array = reinterpret_cast( - heap_manager->AllocateObject(array_class->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread)); + heap_manager->AllocateObject(array_class_->GetHClass(), size, TAGGED_OBJECT_ALIGNMENT, thread)); array->SetLength(length); return array; } + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) JSThread *thread; - JSHClass *array_class; - JSHClass *string_class; + +private: + JSHClass *array_class_; + JSHClass *string_class_; }; class ConcurrentMarkListener : public mem::GCListener { public: + NO_COPY_SEMANTIC(ConcurrentMarkListener); + NO_MOVE_SEMANTIC(ConcurrentMarkListener); + ~ConcurrentMarkListener() override = default; + ConcurrentMarkListener(G1GCBarrierTest *cur_test, JSHandle arr, JSHandle obj, JSHandle cur_replacement) - : test(cur_test), array(arr), object(obj), replacement(cur_replacement) + : test_(cur_test), array_(arr), object_(obj), replacement_(cur_replacement) { } @@ -80,9 +91,9 @@ public: return; } has_concurrent_mark = true; - JSThread *thread = test->thread; - array->Set(thread, 0, JSTaggedValue::Undefined()); - array->Set(thread, 1, replacement.GetTaggedValue()); + JSThread *thread = test_->thread; + array_->Set(thread, 0, JSTaggedValue::Undefined()); + array_->Set(thread, 1, replacement_.GetTaggedValue()); PandaVector *pre_buff = thread->GetPreBuff(); EXPECT_TRUE(pre_buff != nullptr); @@ -90,14 +101,17 @@ public: return; } EXPECT_EQ(1U, pre_buff->size()); - EXPECT_EQ(object.GetObject(), pre_buff->front()); + EXPECT_EQ(object_.GetObject(), pre_buff->front()); } - G1GCBarrierTest *test; - JSHandle array; - JSHandle object; - JSHandle replacement; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) bool has_concurrent_mark = false; + +private: + G1GCBarrierTest *test_; + JSHandle array_; + JSHandle object_; + JSHandle replacement_; }; TEST_F(G1GCBarrierTest, TestPreBarrier) @@ -124,6 +138,9 @@ TEST_F(G1GCBarrierTest, TestPreBarrier) class G1GCClassCollectionTest : public testing::TestWithParam { public: + NO_COPY_SEMANTIC(G1GCClassCollectionTest); + NO_MOVE_SEMANTIC(G1GCClassCollectionTest); + G1GCClassCollectionTest() { RuntimeOptions options; @@ -142,7 +159,7 @@ public: thread = JSThread::GetCurrent(); } - ~G1GCClassCollectionTest() + ~G1GCClassCollectionTest() override { Runtime::Destroy(); } @@ -162,7 +179,9 @@ public: return static_cast *>(gc->GetObjectAllocator()); } - JSThread *thread; +protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread {}; }; TEST_P(G1GCClassCollectionTest, TestCollectClasses) diff --git a/tests/runtime/mem/object_helpers_test.cpp b/tests/runtime/mem/object_helpers_test.cpp index b2f7329cb502bec0bb45d29dc440a3d07edf066d..17ca4613449b8049b1445cc33a59b2afbff8f6d0 100644 --- a/tests/runtime/mem/object_helpers_test.cpp +++ b/tests/runtime/mem/object_helpers_test.cpp @@ -26,6 +26,9 @@ inline std::string Separator() class DynamicObjectHelpersTest : public testing::Test { public: + NO_COPY_SEMANTIC(DynamicObjectHelpersTest); + NO_MOVE_SEMANTIC(DynamicObjectHelpersTest); + DynamicObjectHelpersTest() { RuntimeOptions options; @@ -50,7 +53,7 @@ public: dynclass->GetHClass()->SetNativeFieldMask(JSHClass::NATIVE_FIELDS_MASK); } - ~DynamicObjectHelpersTest() + ~DynamicObjectHelpersTest() override { vm_->GetMutatorLock()->Unlock(); delete handle_scope_; @@ -63,10 +66,14 @@ public: } protected: - EcmaHandleScope *handle_scope_; - EcmaVM *vm_; - JSThread *thread_; - ObjectFactory *factory_; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread_ {}; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + ObjectFactory *factory_ {}; + +private: + EcmaHandleScope *handle_scope_ {}; + EcmaVM *vm_ {}; JSHandle initial_dyn_class_; }; diff --git a/tests/runtime/mem/weak_containers_test.cpp b/tests/runtime/mem/weak_containers_test.cpp index be844f0e55b252983dd31ef6ddffa7b65cb72c84..9ac1ba749c360c96217c6a14a2eef25809453a46 100644 --- a/tests/runtime/mem/weak_containers_test.cpp +++ b/tests/runtime/mem/weak_containers_test.cpp @@ -27,7 +27,7 @@ #include "libpandabase/os/thread.h" -using namespace panda; +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; namespace panda::test { @@ -52,21 +52,27 @@ public: } protected: - JSThread *thread_ = nullptr; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) EcmaVM *vm_ = nullptr; + +private: + JSThread *thread_ = nullptr; }; -Local RunGC(EcmaVM *vm, Local, const Local *, int32_t, void *) +Local RunGC(EcmaVM *vm /*unused*/, Local /*unused*/, const Local * /*unused*/, + int32_t /*unused*/, void * /*unused*/) { vm->GetGC()->WaitForGC(GCTask(GCTaskCause::EXPLICIT_CAUSE)); return JSValueRef::Undefined(vm); } -Local GetContainerSize(EcmaVM *vm, Local, const Local *args, int32_t argc, void *) +Local GetContainerSize(EcmaVM *vm, Local /*unused*/, const Local *args, + int32_t argc, void * /*unused*/) { if (argc != 1) { LOG_ECMA(FATAL) << "Unexpected number of arguments: " << argc; } + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) JSHandle value = JSNApiHelper::ToJSHandle(args[0]); if (!value->IsHeapObject()) { LOG_ECMA(FATAL) << "Argument must be heap object"; @@ -78,7 +84,9 @@ Local GetContainerSize(EcmaVM *vm, Local, const LocalIsJSWeakMap()) { auto *weak_map = JSWeakMap::Cast(value->GetHeapObject()); return IntegerRef::New(vm, weak_map->GetSize()); - } else if (hclass->IsJSWeakSet()) { + } + + if (hclass->IsJSWeakSet()) { auto *weak_set = JSWeakSet::Cast(value->GetHeapObject()); return IntegerRef::New(vm, weak_set->GetSize()); } @@ -98,6 +106,7 @@ bool RegisterFunction(EcmaVM *vm, Local &global_object, panda::Functi TEST_F(WeakContainersTests, WeakContainers) { + // NOLINTNEXTLINE(modernize-avoid-c-arrays) const char main_func[] = "_GLOBAL::func_main_0"; JSExecutionScope execution_scope(vm_); LocalScope scope(vm_); @@ -107,6 +116,7 @@ TEST_F(WeakContainersTests, WeakContainers) ASSERT_TRUE(RegisterFunction(vm_, global_object, RunGC, "collectGarbage")); ASSERT_TRUE(RegisterFunction(vm_, global_object, GetContainerSize, "getContainerSize")); + // NOLINTNEXTLINE(modernize-avoid-c-arrays) const char file_name[] = "weakContainers.abc"; bool ret2 = JSNApi::Execute(vm_, file_name, main_func); ASSERT_EQ(ret2, true); diff --git a/tests/runtime/napi/jsnapi_tests.cpp b/tests/runtime/napi/jsnapi_tests.cpp index 59e3e0aa986ffcdb5a099f125b817456bfdd6016..002568907012142a27c51007079ce975a57c4107 100644 --- a/tests/runtime/napi/jsnapi_tests.cpp +++ b/tests/runtime/napi/jsnapi_tests.cpp @@ -27,9 +27,11 @@ #include "libpandabase/os/thread.h" -using namespace panda; +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; +// NOLINTBEGIN(readability-magic-numbers,modernize-avoid-c-arrays) + namespace panda::test { class JSNApiTests : public testing::Test { public: @@ -86,11 +88,14 @@ public: } protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) JSThread *thread_ = nullptr; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) EcmaVM *vm_ = nullptr; }; -Local FunctionCallback(EcmaVM *vm, Local, const Local *, int32_t length, void *) +Local FunctionCallback(EcmaVM *vm, Local /*unused*/, const Local * /*unused*/, + int32_t length, void * /*unused*/) { EscapeLocalScope scope(vm); return scope.Escape(ArrayRef::New(vm, length)); @@ -321,9 +326,11 @@ TEST_F(JSNApiTests, GetProtoType) ASSERT_TRUE(proto_type->IsObject()); } -void CheckReject(EcmaVM *, Local, const Local argv[], int32_t length, void *) +void CheckReject(EcmaVM * /*unused*/, Local /*unused*/, const Local argv[], int32_t length, + void * /*unused*/) { ASSERT_EQ(length, 1); + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) Local reason = argv[0]; ASSERT_TRUE(reason->IsString()); ASSERT_EQ(Local(reason)->ToString(), "Reject"); @@ -354,9 +361,11 @@ TEST_F(JSNApiTests, PromiseCatch) JSNApi::ExecutePendingJob(vm_); } -void CheckResolve(EcmaVM *, Local, const Local argv[], int32_t length, void *) +void CheckResolve(EcmaVM * /*unused*/, Local /*unused*/, const Local argv[], int32_t length, + void * /*unused*/) { ASSERT_EQ(length, 1); + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) Local value = argv[0]; ASSERT_TRUE(value->IsNumber()); ASSERT_EQ(Local(value)->Value(), 300.3); // 300.3 : test case of input @@ -429,7 +438,7 @@ TEST_F(JSNApiTests, ArrayBufferWithBuffer) }; { LocalScope scope(vm_); - uint8_t *buffer = new uint8_t[length](); + auto *buffer = new uint8_t[length](); Local array_buffer = ArrayBufferRef::New(vm_, buffer, length, deleter, data); ASSERT_TRUE(array_buffer->IsArrayBuffer()); ASSERT_EQ(array_buffer->ByteLength(vm_), length); @@ -871,3 +880,5 @@ TEST_F(JSNApiTests, ClassFunction) ASSERT_TRUE(accessor.IsInternalAccessor()); } } // namespace panda::test + +// NOLINTEND(readability-magic-numbers,modernize-avoid-c-arrays) diff --git a/tests/runtime/regexp/dyn_buffer_test.cpp b/tests/runtime/regexp/dyn_buffer_test.cpp index c5e4bdcada98dfbb2521d18c181a9a3ecea03c4c..3fea8c0150ed378455cf96eb1c5d535888e371a8 100644 --- a/tests/runtime/regexp/dyn_buffer_test.cpp +++ b/tests/runtime/regexp/dyn_buffer_test.cpp @@ -23,7 +23,8 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::test { -using namespace panda::coretypes; + +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; class DynBufferTest : public testing::Test { @@ -38,16 +39,20 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } - PandaVM *instance; - JSThread *thread; +private: + PandaVM *instance {}; + JSThread *thread {}; EcmaHandleScope *scope {nullptr}; }; TEST_F(DynBufferTest, EmitAndGet) { DynChunk dyn_chunk = DynChunk(); + // NOLINTNEXTLINE(readability-magic-numbers) dyn_chunk.EmitChar(65); + // NOLINTNEXTLINE(readability-magic-numbers) dyn_chunk.EmitU16(66); + // NOLINTNEXTLINE(readability-magic-numbers) dyn_chunk.EmitU32(67); ASSERT_EQ(dyn_chunk.GetSize(), 7); ASSERT_EQ(dyn_chunk.GetAllocatedSize(), DynChunk::ALLOCATE_MIN_SIZE); @@ -64,6 +69,7 @@ TEST_F(DynBufferTest, EmitAndGet) TEST_F(DynBufferTest, EmitSelfAndGet) { DynChunk dyn_chunk = DynChunk(); + // NOLINTNEXTLINE(readability-magic-numbers) dyn_chunk.EmitChar(65); dyn_chunk.EmitSelf(0, 1); ASSERT_EQ(dyn_chunk.GetSize(), 2); diff --git a/tests/runtime/regexp/regexp_test.cpp b/tests/runtime/regexp/regexp_test.cpp index 2f9cee67147af7237306a94595264e129ccdc69e..86b5b914aa8ea97511ccd18b8a7d2a4a96bdcffc 100644 --- a/tests/runtime/regexp/regexp_test.cpp +++ b/tests/runtime/regexp/regexp_test.cpp @@ -25,9 +25,13 @@ #include "plugins/ecmascript/runtime/ecma_string-inl.h" namespace panda::test { + +// NOLINTNEXTLINE(google-build-using-namespace) using namespace panda::ecmascript; using MatchResult = RegExpExecutor::MatchResult; +// NOLINTBEGIN(readability-magic-numbers) + class RegExpTest : public testing::Test { public: static void SetUpTestCase() @@ -101,9 +105,12 @@ public: } protected: + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + JSThread *thread_ {nullptr}; + +private: PandaVM *instance_ {nullptr}; EcmaHandleScope *scope_ {nullptr}; - JSThread *thread_ {nullptr}; }; TEST_F(RegExpTest, ParseError1) @@ -1265,7 +1272,7 @@ TEST_F(RegExpTest, ParseAndExec29) ASSERT_FALSE(parse_result); RegExpExecutor executor; - PandaString input(""); + PandaString input; bool ret = executor.Execute(reinterpret_cast(input.c_str()), 0, input.size(), parser.GetOriginBuffer()); ASSERT_TRUE(ret); @@ -1288,7 +1295,7 @@ TEST_F(RegExpTest, ParseAndExec30) ASSERT_FALSE(parse_result); RegExpExecutor executor; - PandaString input(""); + PandaString input; bool ret = executor.Execute(reinterpret_cast(input.c_str()), 0, input.size(), parser.GetOriginBuffer()); ASSERT_TRUE(ret); @@ -1390,7 +1397,7 @@ TEST_F(RegExpTest, ParseAndExec35) { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); RegExpParser parser = RegExpParser(); - PandaString source("(\\d{4})-(\\d{2})-(\\d{2})"); + PandaString source(R"((\d{4})-(\d{2})-(\d{2}))"); parser.Init(const_cast(reinterpret_cast(source.c_str())), source.size(), 2); parser.Parse(); bool parse_result = parser.IsError(); @@ -1736,6 +1743,7 @@ TEST_F(RegExpTest, ParseAndExec51) bool parse_result = parser.IsError(); ASSERT_FALSE(parse_result); RegExpExecutor executor; + // NOLINTNEXTLINE(bugprone-string-literal-with-embedded-nul) std::u16string input(u"\u0000"); bool ret = executor.Execute(reinterpret_cast(input.c_str()), 0, input.length() + 1, parser.GetOriginBuffer(), true); @@ -1850,6 +1858,7 @@ TEST_F(RegExpTest, ParseAndExec57) bool parse_result = parser.IsError(); ASSERT_FALSE(parse_result); RegExpExecutor executor; + // NOLINTNEXTLINE(modernize-avoid-c-arrays) char16_t data[] = {0xd834, 0xdf06}; bool ret = executor.Execute(reinterpret_cast(data), 0, 2, parser.GetOriginBuffer(), true); ASSERT_FALSE(ret); @@ -1865,11 +1874,13 @@ TEST_F(RegExpTest, ParseAndExec58) bool parse_result = parser.IsError(); ASSERT_FALSE(parse_result); RegExpExecutor executor; + // NOLINTNEXTLINE(modernize-avoid-c-arrays) char16_t data[] = {0xd834, 0xdf06}; bool ret = executor.Execute(reinterpret_cast(data), 0, 2, parser.GetOriginBuffer(), true); ASSERT_TRUE(ret); MatchResult result = executor.GetResult(thread_, ret); ASSERT_EQ(result.captures.size(), 1U); + // NOLINTNEXTLINE(modernize-avoid-c-arrays) char16_t data1[] = {0xdf06}; JSHandle str = factory->NewFromUtf16(reinterpret_cast(data1), 1); ASSERT_TRUE(result.captures[0].second->Compare(*str) == 0); @@ -2043,3 +2054,5 @@ TEST_F(RegExpTest, RangeSet10) EXPECT_EQ(range_result, range_expected); } } // namespace panda::test + +// NOLINTEND(readability-magic-numbers) diff --git a/tests/runtime/tooling/api_tests/js/js_breakpoint_test.h b/tests/runtime/tooling/api_tests/js/js_breakpoint_test.h index db2abcac69b600f9f8afb811201b3470cb5259df..dffd9e6bf0296bb71a00916e9cbbd75ea1f6faac 100644 --- a/tests/runtime/tooling/api_tests/js/js_breakpoint_test.h +++ b/tests/runtime/tooling/api_tests/js/js_breakpoint_test.h @@ -24,6 +24,7 @@ public: JsBreakpointTest() { vm_start = [this] { + // NOLINTNEXTLINE(readability-magic-numbers) location_ = TestUtil::GetLocation("Sample.js", 22, panda_file_.c_str()); ASSERT_TRUE(location_.GetMethodId().IsValid()); return true; @@ -64,7 +65,7 @@ private: size_t breakpoint_counter_ = 0; }; -std::unique_ptr GetJsBreakpointTest() +inline std::unique_ptr GetJsBreakpointTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/api_tests/js/js_enumerate_frames_test.h b/tests/runtime/tooling/api_tests/js/js_enumerate_frames_test.h index fa74d130f4935964b33f79d8c8760b687d6d35d1..ac471c618a5b91de47eb32e03644d3405a37ced5 100644 --- a/tests/runtime/tooling/api_tests/js/js_enumerate_frames_test.h +++ b/tests/runtime/tooling/api_tests/js/js_enumerate_frames_test.h @@ -58,13 +58,11 @@ private: std::function callback_ {[this](const PtFrame &debug_frame) { this->count_frames_++; - if (debug_frame.GetArgumentNum() != 1) - return true; - return false; + return debug_frame.GetArgumentNum() != 1; }}; }; -std::unique_ptr JsEnumerateFramesTest() +inline std::unique_ptr JsEnumerateFramesTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/api_tests/js/js_exception_events_test.h b/tests/runtime/tooling/api_tests/js/js_exception_events_test.h index fdce4363dc45185a54f06e5b1641e8ed6a0d674d..93ab82a8cd635df3b45caa7679e12359fd7c8583 100644 --- a/tests/runtime/tooling/api_tests/js/js_exception_events_test.h +++ b/tests/runtime/tooling/api_tests/js/js_exception_events_test.h @@ -81,7 +81,7 @@ private: PtLocation catch_location_ {nullptr, PtLocation::EntityId(0), 0}; }; -std::unique_ptr GetJsExceptionEventTest() +inline std::unique_ptr GetJsExceptionEventTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/api_tests/js/js_frame_pop_test.h b/tests/runtime/tooling/api_tests/js/js_frame_pop_test.h index 6d7509a932cb196c7fb02d2b683555c3f72ad1b1..20cf10025a987a3e97624901d8837f046bef2fba 100644 --- a/tests/runtime/tooling/api_tests/js/js_frame_pop_test.h +++ b/tests/runtime/tooling/api_tests/js/js_frame_pop_test.h @@ -24,6 +24,7 @@ public: JsFramePopTest() { vm_start = [this] { + // NOLINTNEXTLINE(readability-magic-numbers) location_ = TestUtil::GetLocation("FramePop.js", 33, panda_file_.c_str()); ASSERT_TRUE(location_.GetMethodId().IsValid()); return true; @@ -103,7 +104,7 @@ private: PtMethod pop_method_ {nullptr}; }; -std::unique_ptr GetJsFramePopTest() +inline std::unique_ptr GetJsFramePopTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/api_tests/js/js_get_current_frame_test.h b/tests/runtime/tooling/api_tests/js/js_get_current_frame_test.h index 129c99670c151f31ed08f1c0e7761ab00db48634..fac06bf9c0cdba95821072df5f6ea7858d38a045 100644 --- a/tests/runtime/tooling/api_tests/js/js_get_current_frame_test.h +++ b/tests/runtime/tooling/api_tests/js/js_get_current_frame_test.h @@ -36,11 +36,13 @@ public: ASSERT_EQ((*frme)->GetMethod(), method); } else if (method->GetFullName() == "_GLOBAL::func_method2_2") { ASSERT_EQ(entry_, 1U); + // NOLINTNEXTLINE(readability-magic-numbers) entry_ += 10; auto frme = debug_interface->GetCurrentFrame(thread); ASSERT_EQ((*frme)->GetMethod(), method); } else if (method->GetFullName() == "_GLOBAL::func_method1_1") { ASSERT_EQ(entry_, 11U); + // NOLINTNEXTLINE(readability-magic-numbers) entry_ += 100U; auto frme = debug_interface->GetCurrentFrame(thread); ASSERT_EQ((*frme)->GetMethod(), method); @@ -60,7 +62,7 @@ private: size_t entry_ = 0; }; -std::unique_ptr GetJsCurrentFrameTest() +inline std::unique_ptr GetJsCurrentFrameTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/api_tests/js/js_get_variable_test.h b/tests/runtime/tooling/api_tests/js/js_get_variable_test.h index a4bb34bc80d9d751ace09645c0ecad61baf14c6a..2ecc7d70bfd16c163d228e82391d61e0119a10d5 100644 --- a/tests/runtime/tooling/api_tests/js/js_get_variable_test.h +++ b/tests/runtime/tooling/api_tests/js/js_get_variable_test.h @@ -40,6 +40,7 @@ public: if (module_name.find(panda_file_.c_str()) == std::string_view::npos) { return true; } + // NOLINTNEXTLINE(readability-magic-numbers) auto location = TestUtil::GetLocation("GetVariable.js", 19, panda_file_.c_str()); // getVariable ASSERT_TRUE(location.GetMethodId().IsValid()); ASSERT_SUCCESS(debug_interface->SetBreakpoint(location)); @@ -59,6 +60,7 @@ public: bool CheckSetValues(PtThread thread, Method *method, uint32_t offset) { + // NOLINTNEXTLINE(modernize-avoid-c-arrays) std::function checkers_list[] = { [&](JSTaggedValue value) { // boolean: false ASSERT_EQ(value.GetRawData(), JSTaggedValue::VALUE_FALSE); @@ -80,6 +82,7 @@ public: }, [&](JSTaggedValue value) { // double: 1.5 ASSERT_TRUE(value.IsDouble()); + // NOLINTNEXTLINE(readability-magic-numbers) ASSERT_EQ(value.GetDouble(), double(1.5)); // 1.5 return true; }, @@ -88,6 +91,7 @@ public: ASSERT_TRUE(value.IsHeapObject()); auto vreg_value = ecmascript::PtEcmaScriptExtension::TaggedValueToVRegValue(value); ASSERT_TRUE(ecmascript::JSTestApi::VRegValueToString(vreg_value, &checked_value)); + // NOLINTNEXTLINE(readability-string-compare) ASSERT_TRUE(checked_value.compare("new_string") == 0); return true; }}; @@ -95,7 +99,7 @@ public: ++count_checker_; uint32_t frame_depth = 0; int32_t arg_number = TestUtil::GetValueRegister(method, "bl1", offset); - for (auto checker : checkers_list) { + for (const auto &checker : checkers_list) { VRegValue vreg_value; ASSERT_SUCCESS(debug_interface->GetVariable(thread, frame_depth, arg_number++, &vreg_value)); ASSERT_TRUE(checker(ecmascript::PtEcmaScriptExtension::VRegValueToTaggedValue(vreg_value))); @@ -111,7 +115,7 @@ private: int count_checker_ = 0; }; -std::unique_ptr GetJsGetVariableTest() +inline std::unique_ptr GetJsGetVariableTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/api_tests/js/js_method_event_test.h b/tests/runtime/tooling/api_tests/js/js_method_event_test.h index 7fa342d472f69fdfe3c23be1c3e58e0b3f518ae6..7a450f9429344ad49cc5b00a6ad8507d64941024 100644 --- a/tests/runtime/tooling/api_tests/js/js_method_event_test.h +++ b/tests/runtime/tooling/api_tests/js/js_method_event_test.h @@ -54,7 +54,7 @@ private: int method_entry_count_ = 0; }; -std::unique_ptr GetJsMethodEventTest() +inline std::unique_ptr GetJsMethodEventTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/api_tests/js/js_restart_frame_test.h b/tests/runtime/tooling/api_tests/js/js_restart_frame_test.h index 78c2087aa4e302748893a908ab7abd089c81e278..0f53770cbfb9911dd9c2cacf6b76a8619ad9f0ea 100644 --- a/tests/runtime/tooling/api_tests/js/js_restart_frame_test.h +++ b/tests/runtime/tooling/api_tests/js/js_restart_frame_test.h @@ -27,6 +27,7 @@ public: JsRestartFrameTest() { vm_start = [this] { + // NOLINTNEXTLINE(readability-magic-numbers) location_ = TestUtil::GetLocation("RestartFrame.js", 35, panda_file_.c_str()); ASSERT_TRUE(location_.GetMethodId().IsValid()); return true; @@ -116,7 +117,7 @@ private: int64_t result_ = 0; }; -std::unique_ptr GetJsRestartFrameTest() +inline std::unique_ptr GetJsRestartFrameTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/api_tests/js/js_set_notification_test.h b/tests/runtime/tooling/api_tests/js/js_set_notification_test.h index c5c325dff0d085f245de5c4cbabcdd9d9544415d..800a7a1568eae1bb14ed2ebce1220d4f3ee8808e 100644 --- a/tests/runtime/tooling/api_tests/js/js_set_notification_test.h +++ b/tests/runtime/tooling/api_tests/js/js_set_notification_test.h @@ -100,7 +100,7 @@ private: int exit_ = 0; }; -std::unique_ptr GetJsSetNotificationTest() +inline std::unique_ptr GetJsSetNotificationTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/api_tests/js/js_set_variable_test.h b/tests/runtime/tooling/api_tests/js/js_set_variable_test.h index a59b1fbb5775197e1c1ce336ee2cf38dacdf20d1..5d2ad6dfbb99dda2b06d80dfd0da7eda049ed347 100644 --- a/tests/runtime/tooling/api_tests/js/js_set_variable_test.h +++ b/tests/runtime/tooling/api_tests/js/js_set_variable_test.h @@ -40,13 +40,18 @@ public: if (module_name.find(panda_file_.c_str()) == std::string_view::npos) { return true; } + // NOLINTNEXTLINE(readability-magic-numbers) SetBreakpoint(22); // setBoolean + // NOLINTNEXTLINE(readability-magic-numbers) SetBreakpoint(26); // setInt + // NOLINTNEXTLINE(readability-magic-numbers) SetBreakpoint(30); // setDouble + // NOLINTNEXTLINE(readability-magic-numbers) SetBreakpoint(34); // setString return true; }; + // NOLINTBEGIN(readability-magic-numbers) breakpoint = [this](PtThread thread, Method *method, PtLocation location) { breakpoint_count_ += 1; auto method_name = method->GetFullName(); @@ -73,6 +78,7 @@ public: } return true; }; + // NOLINTEND(readability-magic-numbers) method_entry = [this](PtThread thread, Method *method) { auto method_name = method->GetFullName(); @@ -97,8 +103,10 @@ private: auto global_object = global_env->GetGlobalObject(); panda::ecmascript::ObjectFactory *factory = ecma_vm->GetFactory(); + // NOLINTBEGIN(readability-redundant-string-cstr) panda::ecmascript::JSHandle exec_handle( factory->NewFromStdString(name.c_str())); + // NOLINTEND(readability-redundant-string-cstr) panda::ecmascript::JSHandle object_handle(js_thread, global_object); if (!panda::ecmascript::JSObject::HasProperty(js_thread, object_handle, exec_handle)) { return false; @@ -109,7 +117,7 @@ private: return true; } - bool CheckData(PtThread, Method *) + bool CheckData(PtThread /*unused*/, Method * /*unused*/) { { VRegValue pt_bool; @@ -137,6 +145,7 @@ private: const PandaString expected_value = "x2348x"; ASSERT_TRUE(GetGlobalVariable("stringData", &pt_string)); ASSERT_TRUE(ecmascript::JSTestApi::VRegValueToString(pt_string, &string_value)); + // NOLINTNEXTLINE(readability-string-compare) ASSERT_TRUE(string_value.compare(expected_value) == 0); } return true; @@ -155,7 +164,7 @@ private: std::string entry_point_ = "_GLOBAL::func_main_0"; }; -std::unique_ptr GetJsSetVariableTest() +inline std::unique_ptr GetJsSetVariableTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/api_tests/js/js_single_step_test.h b/tests/runtime/tooling/api_tests/js/js_single_step_test.h index 46d50d5ebbfeeeaf2bd85ace607680770b20a62a..0226c89d610a8cd74b3968eeea6e413f5514fd82 100644 --- a/tests/runtime/tooling/api_tests/js/js_single_step_test.h +++ b/tests/runtime/tooling/api_tests/js/js_single_step_test.h @@ -24,7 +24,9 @@ public: JsSingleStepTest() { vm_start = [this] { + // NOLINTNEXTLINE(readability-magic-numbers) location_start_ = TestUtil::GetLocation("Sample.js", 19, panda_file_.c_str()); + // NOLINTNEXTLINE(readability-magic-numbers) location_end_ = TestUtil::GetLocation("Sample.js", 22, panda_file_.c_str()); return true; }; @@ -89,7 +91,7 @@ private: uint32_t bytecode_offset_ = std::numeric_limits::max(); }; -std::unique_ptr GetJsSingleStepTest() +inline std::unique_ptr GetJsSingleStepTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/api_tests/js/js_vm_event_test.h b/tests/runtime/tooling/api_tests/js/js_vm_event_test.h index 74fcea3b3d001f1a69819447cc5a086e7e454c5c..3691872df9c94655733b3ada671755116387a985 100644 --- a/tests/runtime/tooling/api_tests/js/js_vm_event_test.h +++ b/tests/runtime/tooling/api_tests/js/js_vm_event_test.h @@ -57,7 +57,7 @@ private: uint32_t init_thread_ = PtThread::NONE.GetId(); }; -std::unique_ptr GetJsVmEventTest() +inline std::unique_ptr GetJsVmEventTest() { return std::make_unique(); } diff --git a/tests/runtime/tooling/js_test_api.h b/tests/runtime/tooling/js_test_api.h index 77303c4ea774b64ca539dc9c494c66dba8556503..96f1f093f0c04b698b5ee1d9faa1056fe707436f 100644 --- a/tests/runtime/tooling/js_test_api.h +++ b/tests/runtime/tooling/js_test_api.h @@ -21,6 +21,8 @@ #include "plugins/ecmascript/runtime/js_handle.h" #include "plugins/ecmascript/runtime/global_env.h" +// NOLINTBEGIN(readability-redundant-string-cstr) + namespace panda::tooling::ecmascript { using JSThread = panda::ecmascript::JSThread; class JSTestApi { @@ -48,4 +50,6 @@ public: }; } // namespace panda::tooling::ecmascript +// NOLINTEND(readability-redundant-string-cstr) + #endif // PANDA_PLUGINS_ECMASCRIPT_TESTS_RUNTIME_TOOLING_JS_TEST_API_H diff --git a/tests/runtime/tooling/launcher.cpp b/tests/runtime/tooling/launcher.cpp index cff84aace349d7cfcc9fd69cc6da33245dca7226..aa1da27c769fcb413910abee1f5e7f009caae89b 100644 --- a/tests/runtime/tooling/launcher.cpp +++ b/tests/runtime/tooling/launcher.cpp @@ -25,7 +25,11 @@ extern void SetExtractorFactoryForTest(TestExtractorFactory *test_extractor); class BaseDebugApiTest : public testing::TestWithParam { public: - virtual ~BaseDebugApiTest() = default; + NO_COPY_SEMANTIC(BaseDebugApiTest); + NO_MOVE_SEMANTIC(BaseDebugApiTest); + + ~BaseDebugApiTest() override = default; + BaseDebugApiTest() = default; protected: void RunTest(RuntimeOptions &options, const char *test_name) const diff --git a/tests/runtime/tooling/options_test/options_test.cpp b/tests/runtime/tooling/options_test/options_test.cpp index f5afc7bec66f2be5604ebbb58503abc3fa1db6c5..3edde1b7be143dd0a725a399712a6eb0164228bd 100644 --- a/tests/runtime/tooling/options_test/options_test.cpp +++ b/tests/runtime/tooling/options_test/options_test.cpp @@ -24,8 +24,11 @@ namespace panda::test { class EcmascriptRuntimeOptionsTest : public RuntimeOptionsTestBase { public: + NO_COPY_SEMANTIC(EcmascriptRuntimeOptionsTest); + NO_MOVE_SEMANTIC(EcmascriptRuntimeOptionsTest); + EcmascriptRuntimeOptionsTest() = default; - ~EcmascriptRuntimeOptionsTest() = default; + ~EcmascriptRuntimeOptionsTest() override = default; private: void LoadCorrectOptionsList() override;