From dc786ea9bcd9e973fca1c1ae40e385c4d1f04d72 Mon Sep 17 00:00:00 2001 From: zhangyukun Date: Fri, 24 Sep 2021 17:13:25 +0800 Subject: [PATCH] Fix reviewbot of js_runtime Signed-off-by: zhangyukun --- ecmascript/compiler/gate.cpp | 8 ++--- ecmascript/compiler/stub_optimizer.cpp | 2 +- ecmascript/compiler/stub_optimizer.h | 2 +- .../compiler/tests/stub_optimizer_tests.cpp | 34 +++++++++++-------- ecmascript/ecma_vm.cpp | 2 +- ecmascript/js_collator.cpp | 32 ++++++++++------- ecmascript/js_locale.cpp | 12 ++++--- ecmascript/js_locale.h | 6 ++-- ecmascript/js_method.h | 2 +- ecmascript/js_plural_rules.cpp | 15 +++++--- ecmascript/js_relative_time_format.cpp | 8 +++-- ecmascript/napi/include/jsnapi.h | 2 +- ecmascript/object_operator.h | 2 +- ecmascript/regexp/dyn_chunk.cpp | 8 ++--- 14 files changed, 79 insertions(+), 56 deletions(-) diff --git a/ecmascript/compiler/gate.cpp b/ecmascript/compiler/gate.cpp index 329cc2c2f8..31a5de5e11 100644 --- a/ecmascript/compiler/gate.cpp +++ b/ecmascript/compiler/gate.cpp @@ -26,13 +26,13 @@ Properties OpCode::GetProperties() const // GENERAL_STATE for any opcode match in // {IF_TRUE, IF_FALSE, SWITCH_CASE, DEFAULT_CASE, MERGE, LOOP_BEGIN, STATE_ENTRY} // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define STATE(...) (std::make_pair(std::vector{__VA_ARGS__}, false)) +#define STATE(...) (std::make_pair(std::vector {__VA_ARGS__}, false)) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define VALUE(...) (std::make_pair(std::vector{__VA_ARGS__}, false)) +#define VALUE(...) (std::make_pair(std::vector {__VA_ARGS__}, false)) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define MANY_STATE(...) (std::make_pair(std::vector{__VA_ARGS__}, true)) +#define MANY_STATE(...) (std::make_pair(std::vector {__VA_ARGS__}, true)) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define MANY_VALUE(...) (std::make_pair(std::vector{__VA_ARGS__}, true)) +#define MANY_VALUE(...) (std::make_pair(std::vector {__VA_ARGS__}, true)) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define NO_STATE (std::nullopt) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) diff --git a/ecmascript/compiler/stub_optimizer.cpp b/ecmascript/compiler/stub_optimizer.cpp index 25e344e793..5d8b8ba8bc 100644 --- a/ecmascript/compiler/stub_optimizer.cpp +++ b/ecmascript/compiler/stub_optimizer.cpp @@ -572,7 +572,7 @@ AddrShift StubOptimizer::UpdateRepresention(AddrShift oldRep, AddrShift value, L Label isObjectNewRep(env); Label notObjectNewRep(env); Branch(Word64NotEqual(newRep, GetWord64Constant( - static_cast(panda::ecmascript::Representation::OBJECT))), + static_cast(panda::ecmascript::Representation::OBJECT))), ¬ObjectNewRep, &isObjectNewRep); Bind(¬ObjectNewRep); { diff --git a/ecmascript/compiler/stub_optimizer.h b/ecmascript/compiler/stub_optimizer.h index 16846802c7..7143de7a8d 100644 --- a/ecmascript/compiler/stub_optimizer.h +++ b/ecmascript/compiler/stub_optimizer.h @@ -993,7 +993,7 @@ public: Word64Or(Word64And(oldValue, GetWord64Constant(~panda::ecmascript::JSHClass::ElementRepresentationBits::Mask())), Word64LSR(value, GetWord64Constant( - panda::ecmascript::JSHClass::ElementRepresentationBits::START_BIT)))); + panda::ecmascript::JSHClass::ElementRepresentationBits::START_BIT)))); } void UpdateValueAndDetails(AddrShift elements, AddrShift index, AddrShift value, AddrShift attr) diff --git a/ecmascript/compiler/tests/stub_optimizer_tests.cpp b/ecmascript/compiler/tests/stub_optimizer_tests.cpp index 165e90c9a1..179f52b7f2 100644 --- a/ecmascript/compiler/tests/stub_optimizer_tests.cpp +++ b/ecmascript/compiler/tests/stub_optimizer_tests.cpp @@ -49,9 +49,9 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } - PandaVM *instance{nullptr}; - EcmaHandleScope *scope{nullptr}; - JSThread *thread{nullptr}; + PandaVM *instance {nullptr}; + EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; }; HWTEST_F_L0(StubOptimizerTest, FastLoadElement) @@ -1176,8 +1176,9 @@ public: AddrShift elements = GetElements(*holder); AddrShift isDictionary = IsDictionaryMode(elements); StubInterfaceDescriptor *findOwnElemnt2 = GET_STUBDESCRIPTOR(FindOwnElement2); - AddrShift val = CallStub(findOwnElemnt2, GetWord64Constant(FAST_STUB_ID(FindOwnElement2)), - {thread, elements, index, isDictionary, pattr, pindexOrEntry}); + AddrShift val = CallStub(findOwnElemnt2, GetWord64Constant(FAST_STUB_ID(FindOwnElement2)), { + thread, elements, index, isDictionary, pattr, pindexOrEntry + }); Label notHole(env); Label isHole(env); Branch(TaggedIsNotHole(val), ¬Hole, &isHole); @@ -1211,8 +1212,10 @@ public: Bind(&nextExtensible); StubInterfaceDescriptor *addElementInternal = GET_STUBDESCRIPTOR(AddElementInternal); Return(CallRuntime(addElementInternal, thread, GetWord64Constant(FAST_STUB_ID(AddElementInternal)), - {thread, receiver, index, value, - GetInteger32Constant(PropertyAttributes::GetDefaultAttributes())})); + { + thread, receiver, index, value, + GetInteger32Constant(PropertyAttributes::GetDefaultAttributes()) + })); } Bind(&afterOnProtoType); { @@ -1260,8 +1263,9 @@ public: { StubInterfaceDescriptor *callsetter = GET_STUBDESCRIPTOR(CallSetter); AddrShift setter = GetSetterFromAccessor(val); - Return(CallRuntime(callsetter, thread, GetWord64Constant(FAST_STUB_ID(CallSetter)), - {thread, setter, receiver, value, TruncInt32ToInt1(mayThrow)})); + Return(CallRuntime(callsetter, thread, GetWord64Constant(FAST_STUB_ID(CallSetter)), { + thread, setter, receiver, value, TruncInt32ToInt1(mayThrow) + })); } } } @@ -1295,9 +1299,10 @@ public: { StubInterfaceDescriptor *addElementInternal = GET_STUBDESCRIPTOR(AddElementInternal); Return(CallRuntime(addElementInternal, thread, - GetWord64Constant(FAST_STUB_ID(AddElementInternal)), - {thread, receiver, index, value, - GetInteger32Constant(PropertyAttributes::GetDefaultAttributes())})); + GetWord64Constant(FAST_STUB_ID(AddElementInternal)), { + thread, receiver, index, value, + GetInteger32Constant(PropertyAttributes::GetDefaultAttributes()) + })); } } Bind(&isHeapObj); @@ -1309,8 +1314,9 @@ public: { StubInterfaceDescriptor *setProperty = GET_STUBDESCRIPTOR(JSProxySetProperty); Return(CallRuntime( - setProperty, thread, GetWord64Constant(FAST_STUB_ID(JSProxySetProperty)), - {thread, *holder, IntBuildTagged(index), value, receiver, TruncInt32ToInt1(mayThrow)})); + setProperty, thread, GetWord64Constant(FAST_STUB_ID(JSProxySetProperty)), { + thread, *holder, IntBuildTagged(index), value, receiver, TruncInt32ToInt1(mayThrow) + })); } Bind(¬JsProxy); onPrototype = TrueConstant(); diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index 31bb8274e6..6da411e325 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -388,7 +388,7 @@ Expected EcmaVM::InvokeEntrypointImpl(Method *entrypoint, c } Expected EcmaVM::InvokeEcmaEntrypoint(const panda_file::File &pf, const CString &methodName, - const std::vector &args) + const std::vector &args) { thread_->SetIsEcmaInterpreter(true); thread_->SetIsSnapshotMode(true); diff --git a/ecmascript/js_collator.cpp b/ecmascript/js_collator.cpp index 54b2b9c20b..671b34856d 100644 --- a/ecmascript/js_collator.cpp +++ b/ecmascript/js_collator.cpp @@ -85,18 +85,22 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); } // 4. Let usage be ? GetOption(options, "usage", "string", « "sort", "search" », "sort"). - auto usage = JSLocale::GetOptionOfString(thread, optionsObject, globalConst->GetHandledUsageString(), - {UsageOption::SORT, UsageOption::SEARCH}, {"sort", "search"}, - UsageOption::SORT); + auto usage = JSLocale::GetOptionOfString(thread, optionsObject, globalConst->GetHandledUsageString(), { + UsageOption::SORT, UsageOption::SEARCH + }, { + "sort", "search" + }, UsageOption::SORT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); JSHandle usageValue(thread, JSTaggedValue(static_cast(usage))); collator->SetUsage(thread, usageValue); // 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). auto matcher = JSLocale::GetOptionOfString( - thread, optionsObject, globalConst->GetHandledLocaleMatcherString(), - {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT}, {"lookup", "best fit"}, - LocaleMatcherOption::BEST_FIT); + thread, optionsObject, globalConst->GetHandledLocaleMatcherString(), { + LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT + }, { + "lookup", "best fit" + }, LocaleMatcherOption::BEST_FIT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); // 6. Let collation be ? GetOption(options, "collation", "string", undefined, undefined). @@ -126,9 +130,11 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa // 14. Let caseFirst be ? GetOption(options, "caseFirst", "string", « "upper", "lower", "false" », undefined). auto caseFirst = JSLocale::GetOptionOfString( - thread, optionsObject, globalConst->GetHandledCaseFirstString(), - {CaseFirstOption::UPPER, CaseFirstOption::LOWER, CaseFirstOption::FALSE_OPTION}, {"upper", "lower", "false"}, - CaseFirstOption::UNDEFINED); + thread, optionsObject, globalConst->GetHandledCaseFirstString(), { + CaseFirstOption::UPPER, CaseFirstOption::LOWER, CaseFirstOption::FALSE_OPTION + }, { + "upper", "lower", "false" + }, CaseFirstOption::UNDEFINED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); JSHandle caseFirstValue(thread, JSTaggedValue(static_cast(caseFirst))); collator->SetCaseFirst(thread, caseFirstValue); @@ -237,9 +243,11 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa // 24. Let sensitivity be ? GetOption(options, "sensitivity", "string", « "base", "accent", "case", "variant" », // undefined). auto sensitivity = JSLocale::GetOptionOfString( - thread, optionsObject, globalConst->GetHandledSensitivityString(), - {SensitivityOption::BASE, SensitivityOption::ACCENT, SensitivityOption::CASE, SensitivityOption::VARIANT}, - {"base", "accent", "case", "variant"}, SensitivityOption::UNDEFINED); + thread, optionsObject, globalConst->GetHandledSensitivityString(), { + SensitivityOption::BASE, SensitivityOption::ACCENT, SensitivityOption::CASE, SensitivityOption::VARIANT + }, { + "base", "accent", "case", "variant" + }, SensitivityOption::UNDEFINED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); // 25. If sensitivity is undefined, then // a. If usage is "sort", then diff --git a/ecmascript/js_locale.cpp b/ecmascript/js_locale.cpp index f87f3830ec..46d7ffcb64 100644 --- a/ecmascript/js_locale.cpp +++ b/ecmascript/js_locale.cpp @@ -543,9 +543,11 @@ JSHandle JSLocale::SupportedLocales(JSThread *thread, const JSHandle obj = JSTaggedValue::ToObject(thread, options); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread); - matcher = GetOptionOfString(thread, obj, globalConst->GetHandledLocaleMatcherString(), - {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT}, - {"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT); + matcher = GetOptionOfString(thread, obj, globalConst->GetHandledLocaleMatcherString(), { + LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT + }, { + "lookup", "best fit" + }, LocaleMatcherOption::BEST_FIT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread); } @@ -1115,7 +1117,7 @@ bool BuildOptionsTags(const JSHandle &tag, icu::LocaleBuilder *build JSHandle script, JSHandle region) { std::string tagStr = JSLocale::ConvertToStdString(tag); - int32_t len = static_cast(tagStr.length()); + auto len = static_cast(tagStr.length()); ASSERT(len > 0); builder->setLanguageTag({ tagStr.c_str(), len }); UErrorCode status = U_ZERO_ERROR; @@ -1231,7 +1233,7 @@ JSHandle JSLocale::InitializeLocale(JSThread *thread, const JSHandle &options) { icu::LocaleBuilder builder; - TagElements tagElements; + TagElements tagElements {}; if (!ApplyOptionsToTag(thread, localeString, options, tagElements)) { THROW_RANGE_ERROR_AND_RETURN(thread, "apply option to tag failed", locale); } diff --git a/ecmascript/js_locale.h b/ecmascript/js_locale.h index ccb87729a9..e32c97e104 100644 --- a/ecmascript/js_locale.h +++ b/ecmascript/js_locale.h @@ -136,9 +136,9 @@ struct OptionData { }; struct TagElements { - JSHandle language; - JSHandle script; - JSHandle region; + JSHandle language {}; + JSHandle script {}; + JSHandle region {}; }; class JSLocale : public JSObject { diff --git a/ecmascript/js_method.h b/ecmascript/js_method.h index ea583d495d..10775965a6 100644 --- a/ecmascript/js_method.h +++ b/ecmascript/js_method.h @@ -89,7 +89,7 @@ public: private: const uint8_t *bytecodeArray_ {nullptr}; uint32_t bytecodeArraySize_ {0}; - uint8_t slotSize_{0}; + uint8_t slotSize_ {0}; }; } // namespace panda::ecmascript diff --git a/ecmascript/js_plural_rules.cpp b/ecmascript/js_plural_rules.cpp index 73d93826a1..cc6f3d0b31 100644 --- a/ecmascript/js_plural_rules.cpp +++ b/ecmascript/js_plural_rules.cpp @@ -167,16 +167,21 @@ JSHandle JSPluralRules::InitializePluralRules(JSThread *thread, // 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). LocaleMatcherOption matcher = - JSLocale::GetOptionOfString(thread, prOptions, globalConst->GetHandledLocaleMatcherString(), - {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT}, - {"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT); + JSLocale::GetOptionOfString(thread, prOptions, globalConst->GetHandledLocaleMatcherString(), { + LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT + }, { + "lookup", "best fit" + }, LocaleMatcherOption::BEST_FIT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSPluralRules, thread); // 7. Let t be ? GetOption(options, "type", "string", « "cardinal", "ordinal" », "cardinal"). JSHandle property = JSHandle::Cast(globalConst->GetHandledTypeString()); TypeOption type = - JSLocale::GetOptionOfString(thread, prOptions, property, { TypeOption::CARDINAL, TypeOption::ORDINAL }, - { "cardinal", "ordinal" }, TypeOption::CARDINAL); + JSLocale::GetOptionOfString(thread, prOptions, property, { + TypeOption::CARDINAL, TypeOption::ORDINAL + }, { + "cardinal", "ordinal" + }, TypeOption::CARDINAL); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSPluralRules, thread); // set pluralRules.[[type]] to type diff --git a/ecmascript/js_relative_time_format.cpp b/ecmascript/js_relative_time_format.cpp index 107ea89fba..edd2f232ae 100644 --- a/ecmascript/js_relative_time_format.cpp +++ b/ecmascript/js_relative_time_format.cpp @@ -47,9 +47,11 @@ JSHandle JSRelativeTimeFormat::InitializeRelativeTimeForma // 5. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit"). auto globalConst = thread->GlobalConstants(); LocaleMatcherOption matcher = - JSLocale::GetOptionOfString(thread, rtfOptions, globalConst->GetHandledLocaleMatcherString(), - {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT}, - {"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT); + JSLocale::GetOptionOfString(thread, rtfOptions, globalConst->GetHandledLocaleMatcherString(), { + LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT + }, { + "lookup", "best fit" + }, LocaleMatcherOption::BEST_FIT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSRelativeTimeFormat, thread); // 7. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined). diff --git a/ecmascript/napi/include/jsnapi.h b/ecmascript/napi/include/jsnapi.h index 01b2f65c93..bf69750906 100644 --- a/ecmascript/napi/include/jsnapi.h +++ b/ecmascript/napi/include/jsnapi.h @@ -528,7 +528,7 @@ using FunctionCallback = Local (*)(EcmaVM *, Local, const Local [], // NOLINTNEXTLINE(modernize-avoid-c-arrays) int32_t, void *); using FunctionCallbackWithNewTarget = - Local (*)(EcmaVM *, Local, Local, const Local [], int32_t, void *); + Local(*)(EcmaVM *, Local, Local, const Local [], int32_t, void *); class PUBLIC_API FunctionRef : public ObjectRef { public: static Local New(EcmaVM *vm, FunctionCallback nativeFunc, void *data); diff --git a/ecmascript/object_operator.h b/ecmascript/object_operator.h index 0ca931ffba..601ece51b8 100644 --- a/ecmascript/object_operator.h +++ b/ecmascript/object_operator.h @@ -300,7 +300,7 @@ private: JSHandle key_{}; uint32_t elementIndex_{NOT_FOUND_INDEX}; uint32_t index_{NOT_FOUND_INDEX}; - PropertyAttributes attributes_; + PropertyAttributes attributes_{}; uint32_t metaData_{0}; }; } // namespace panda::ecmascript diff --git a/ecmascript/regexp/dyn_chunk.cpp b/ecmascript/regexp/dyn_chunk.cpp index 11733aefa3..d2a25a4427 100644 --- a/ecmascript/regexp/dyn_chunk.cpp +++ b/ecmascript/regexp/dyn_chunk.cpp @@ -76,7 +76,7 @@ int DynChunk::Emit(const uint8_t *data, size_t length) } if (memcpy_s(buf_ + size_, // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - length, data, length) != EOK) { + length, data, length) != EOK) { return FAILURE; } size_ += length; @@ -97,9 +97,9 @@ int DynChunk::EmitSelf(size_t offset, size_t length) } if (memcpy_s(buf_ + size_, // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - length, - buf_ + offset, // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - length) != EOK) { + length, + buf_ + offset, // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + length) != EOK) { return FAILURE; } size_ += length; -- Gitee