From 4c79076a09b5ebabda974b2899c5ac17eeea589b Mon Sep 17 00:00:00 2001 From: jiangkaiwen Date: Fri, 25 Nov 2022 20:14:45 +0800 Subject: [PATCH 1/2] Fix codecheck warnings of security compliance 1.Const modifies functions and formal parameters that do not need to be modified 2.The formal parameters and actual parameters are named the same Issue:I62GV7 Signed-off-by: jiangkaiwen Change-Id: I03afbc2e9893107f7ed26243d39cd6368b05487c --- es2panda/binder/variable.h | 2 +- es2panda/compiler/core/regAllocator.cpp | 5 ++--- es2panda/compiler/core/regAllocator.h | 4 ++-- es2panda/ir/expressions/literals/bigIntLiteral.cpp | 2 +- es2panda/parser/parserImpl.cpp | 4 ++-- es2panda/parser/parserImpl.h | 4 ++-- es2panda/parser/transformer/transformer.h | 2 +- ts2panda/ts2abc/ts2abc.cpp | 8 ++++---- ts2panda/ts2abc/ts2abc.h | 2 +- 9 files changed, 16 insertions(+), 17 deletions(-) diff --git a/es2panda/binder/variable.h b/es2panda/binder/variable.h index 170055cf16..ad25898681 100644 --- a/es2panda/binder/variable.h +++ b/es2panda/binder/variable.h @@ -49,7 +49,7 @@ public: NO_COPY_SEMANTIC(Variable); NO_MOVE_SEMANTIC(Variable); - VariableType virtual Type() const = 0; + virtual VariableType Type() const = 0; #define DECLARE_CHECKS_CASTS(variableType, className) \ bool Is##className() const \ diff --git a/es2panda/compiler/core/regAllocator.cpp b/es2panda/compiler/core/regAllocator.cpp index c6d9ac3537..7c41a1bd4d 100644 --- a/es2panda/compiler/core/regAllocator.cpp +++ b/es2panda/compiler/core/regAllocator.cpp @@ -120,7 +120,6 @@ void RegAllocator::AdjustInsRegWhenHasSpill() std::vector regsKind; std::array regs {}; auto regCnt = ins->Registers(®s); - if (regCnt == 0) { newInsns.push_back(ins); continue; @@ -148,8 +147,8 @@ void RegAllocator::AdjustInsRegWhenHasSpill() pg_->SetInsns(newInsns); } -void RegAllocator::AdjustInsSpill(Span ®isters, IRNode *ins, ArenaList &newInsns, - std::vector ®sKind) +void RegAllocator::AdjustInsSpill(const Span ®isters, IRNode *ins, ArenaList &newInsns, + const std::vector ®sKind) { ASSERT(spillIndex_ == 0); ASSERT(!regsKind.empty()); diff --git a/es2panda/compiler/core/regAllocator.h b/es2panda/compiler/core/regAllocator.h index dd0f440c5f..984bab01e7 100644 --- a/es2panda/compiler/core/regAllocator.h +++ b/es2panda/compiler/core/regAllocator.h @@ -121,8 +121,8 @@ private: void Run(IRNode *ins); void Run(IRNode *ins, size_t argCount); void Run(IRNode *ins, int64_t typeIndex); - void AdjustInsSpill(Span ®isters, IRNode *ins, ArenaList &newInsns, - std::vector ®sKind); + void AdjustInsSpill(const Span ®isters, IRNode *ins, ArenaList &newInsns, + const std::vector ®sKind); void AdjustRangeInsSpill(Span ®isters, IRNode *ins, ArenaList &newInsns); template diff --git a/es2panda/ir/expressions/literals/bigIntLiteral.cpp b/es2panda/ir/expressions/literals/bigIntLiteral.cpp index 0a274fa6a2..47251cae62 100644 --- a/es2panda/ir/expressions/literals/bigIntLiteral.cpp +++ b/es2panda/ir/expressions/literals/bigIntLiteral.cpp @@ -30,7 +30,7 @@ void BigIntLiteral::Dump(ir::AstDumper *dumper) const void BigIntLiteral::Compile(compiler::PandaGen *pg) const { - util::StringView bigIntValue = src_.Substr(0, src_.Length()-1); + util::StringView bigIntValue = src_.Substr(0, src_.Length() - 1); pg->LoadAccumulatorBigInt(this, bigIntValue); } diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 908c246cd9..11f74ffc37 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -807,7 +807,7 @@ bool ParserImpl::IsTSNamedTupleMember() return isNamedMember; } -void ParserImpl::HandleRestType(ir::AstNodeType elementType, bool *hasRestType) +void ParserImpl::HandleRestType(ir::AstNodeType elementType, bool *hasRestType) const { if (elementType == ir::AstNodeType::TS_ARRAY_TYPE && *hasRestType) { ThrowSyntaxError("A rest element cannot follow another rest element"); @@ -3460,7 +3460,7 @@ ir::Expression *ParserImpl::ParseFunctionParameter(bool isDeclare) return functionParameter; } -void ParserImpl::ValidateLvalueAssignmentTarget(ir::Expression *node) +void ParserImpl::ValidateLvalueAssignmentTarget(ir::Expression *node) const { switch (node->Type()) { case ir::AstNodeType::IDENTIFIER: { diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index 7b50fd675c..5a08d6fc65 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -260,7 +260,7 @@ private: ir::Expression *ParseTsQualifiedReference(ir::Expression *typeName); ir::Expression *ParseTsTypeReferenceOrQuery(bool parseQuery = false); bool IsTSNamedTupleMember(); - void HandleRestType(ir::AstNodeType elementType, bool *hasRestType); + void HandleRestType(ir::AstNodeType elementType, bool *hasRestType) const; ir::Expression *ParseTsTupleElement(ir::TSTupleKind *kind, bool *seenOptional, bool *hasRestType); ir::TSTupleType *ParseTsTupleType(); ir::TSImportType *ParseTsImportType(const lexer::SourcePosition &startLoc, bool isTypeof = false); @@ -403,7 +403,7 @@ private: ir::AstNode *ParseImportDefaultSpecifier(ArenaVector *specifiers); ir::AstNode *ParseImportSpecifiers(ArenaVector *specifiers); void ValidateAssignmentTarget(ExpressionParseFlags flags, ir::Expression *node); - void ValidateLvalueAssignmentTarget(ir::Expression *node); + void ValidateLvalueAssignmentTarget(ir::Expression *node) const; void ValidateArrowParameterBindings(const ir::Expression *node); ir::ExportDefaultDeclaration *ParseExportDefaultDeclaration(const lexer::SourcePosition &startLoc, diff --git a/es2panda/parser/transformer/transformer.h b/es2panda/parser/transformer/transformer.h index 9e90beb7f2..69ab3c21f7 100644 --- a/es2panda/parser/transformer/transformer.h +++ b/es2panda/parser/transformer/transformer.h @@ -115,7 +115,7 @@ private: ir::Expression *init = nullptr, bool needBinding = true); ir::CallExpression *CreateCallExpressionForTsModule(ir::TSModuleDeclaration *node, - util::StringView paramName, + util::StringView name, bool isExport = false); ir::Expression *CreateTsModuleParam(util::StringView paramName, bool isExport); ir::ExpressionStatement *CreateTsModuleAssignment(util::StringView name); diff --git a/ts2panda/ts2abc/ts2abc.cpp b/ts2panda/ts2abc/ts2abc.cpp index 9b0be99403..f244ae8830 100644 --- a/ts2panda/ts2abc/ts2abc.cpp +++ b/ts2panda/ts2abc/ts2abc.cpp @@ -1450,7 +1450,7 @@ static bool EmitProgram(const std::string &output, int optLevel, std::string opt return true; } -static bool EmitAndRestoreProgram(panda::pandasm::Program &prog, panda::ts2abc::Options options) +static bool EmitAndRestoreProgram(panda::pandasm::Program &prog, const panda::ts2abc::Options options) { if (!EmitProgram(g_outputFileName, options.GetOptLevelArg(), options.GetOptLogLevelArg(), prog)) { std::cerr << "fail to emit porgram " << g_outputFileName << " in HandleBuffer" << std::endl; @@ -1462,7 +1462,7 @@ static bool EmitAndRestoreProgram(panda::pandasm::Program &prog, panda::ts2abc:: } static bool HandleBuffer(const int &ret, char *buff, std::string &data, panda::pandasm::Program &prog, - panda::ts2abc::Options options) + const panda::ts2abc::Options options) { uint32_t startPos = 0; if (options.IsMultiProgramsPipe() && ((buff[0] == '*' && data.back() != '#') || @@ -1509,7 +1509,7 @@ static bool HandleBuffer(const int &ret, char *buff, std::string &data, panda::p return true; } -static bool ReadFromPipe(panda::pandasm::Program &prog, panda::ts2abc::Options options) +static bool ReadFromPipe(panda::pandasm::Program &prog, const panda::ts2abc::Options options) { std::string data; const size_t bufSize = 4096; @@ -1536,7 +1536,7 @@ static bool ReadFromPipe(panda::pandasm::Program &prog, panda::ts2abc::Options o return true; } -bool GenerateProgramsFromPipe(panda::ts2abc::Options options) +bool GenerateProgramsFromPipe(const panda::ts2abc::Options options) { panda::pandasm::Program prog = panda::pandasm::Program(); prog.lang = panda::pandasm::extensions::Language::ECMASCRIPT; diff --git a/ts2panda/ts2abc/ts2abc.h b/ts2panda/ts2abc/ts2abc.h index dfcee1e337..390924d22e 100644 --- a/ts2panda/ts2abc/ts2abc.h +++ b/ts2panda/ts2abc/ts2abc.h @@ -52,7 +52,7 @@ enum class OptLevel { bool HandleJsonFile(const std::string &input, std::string &data); bool GenerateProgram(const std::string &data, const std::string &output, panda::ts2abc::Options options); -bool GenerateProgramsFromPipe(panda::ts2abc::Options options); +bool GenerateProgramsFromPipe(const panda::ts2abc::Options options); bool CompileNpmEntries(const std::string &input, const std::string &output); bool GetDebugLog(); void ParseLogEnable(const Json::Value &rootValue); -- Gitee From 661fcfc9fc86e4ea5fda35a63f5a3b61b4d29688 Mon Sep 17 00:00:00 2001 From: jiangkaiwen Date: Tue, 29 Nov 2022 10:17:31 +0800 Subject: [PATCH 2/2] Fix compilation mode of dynamic-import Issue:I63KTH Signed-off-by: jiangkaiwen Change-Id: I2286d7ac6335a3282e7665489e04bc1f968486cb --- test262/es2abc_skip_tests.json | 9 +++++++++ test262/run_sunspider.py | 29 +++++++++++++++++++---------- test262/ts2abc_skip_tests.json | 9 +++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/test262/es2abc_skip_tests.json b/test262/es2abc_skip_tests.json index 0ee8f3d8f4..aa46ba542f 100644 --- a/test262/es2abc_skip_tests.json +++ b/test262/es2abc_skip_tests.json @@ -245,5 +245,14 @@ "language/expressions/dynamic-import/catch/nested-async-arrow-function-return-await-specifier-tostring-abrupt-rejects.js", "language/expressions/dynamic-import/catch/nested-async-arrow-function-await-specifier-tostring-abrupt-rejects.js" ] + }, + { + "reason" : "Test262Error: it returns the same namespace are the same Expected SameValue", + "files": [ + "language/expressions/dynamic-import/reuse-namespace-object-from-script.js", + "language/expressions/dynamic-import/namespace/await-ns-delete-non-exported-strict.js", + "language/expressions/dynamic-import/namespace/default-property-not-set-own.js", + "language/expressions/dynamic-import/namespace/promise-then-ns-delete-non-exported-strict.js" + ] } ] diff --git a/test262/run_sunspider.py b/test262/run_sunspider.py index 4a3bb4859a..1a962a438c 100755 --- a/test262/run_sunspider.py +++ b/test262/run_sunspider.py @@ -229,17 +229,28 @@ class ArkProgram(): def check_compile_mod_for_dynamicImport(self, dependency): with open(dependency, 'r', encoding='utf-8') as f: context_file = f.read() - script_mode_list = re.findall(r'(import)\(((.)|(\'(\.\/.*))\'|"(\.\/.*)")\)', + script_mode_list = re.findall(r'(import)\(((.)|\'(\.\/.*)\'|"(\.\/.*)")\)', context_file) - module_mode_list = re.findall(r'(export)|(import)(?:\s+)', + module_mode_list = re.findall(r'(export)\s+(?:(?:((?:\*|{\S+})\s+from))|({\S+}|{\s+\S+\s+as\s+\S+\s+}|{\s+\S+\s+}|\*\s+as\s+\S+\s+from\s+\'.+\'|let|const|var|function|class|default))|(import\s+\'.+\')', context_file) - compile_as_module = True + flags_module_mode_list = re.findall(r'(flags:)\s+(\[module])', context_file) + + compile_as_module = False for script_mode in list(set(script_mode_list)): - if len(script_mode[1]) != 0: + if len(script_mode[3]) != 0: compile_as_module = False for module_mode in list(set(module_mode_list)): - if len(module_mode[0]) != 0: + if (len(module_mode[0]) != 0 and (len(module_mode[1]) != 0 or len(module_mode[2]) != 0)) or len(module_mode[3]) != 0: compile_as_module = True + for flags_module_mode in list(set(flags_module_mode_list)): + if len(flags_module_mode[0]) != 0 and len(flags_module_mode[1]) != 0: + compile_as_module = True + + if not list(set(script_mode_list)) and not list(set(module_mode_list)) and not list(set(flags_module_mode_list)): + compile_as_module = False + + if "/language/module-code/" in self.js_file: + compile_as_module = True return compile_as_module @@ -345,7 +356,7 @@ class ArkProgram(): proto_bin_file = file_name_pre + "." + PROTO_BIN_SUFFIX self.abc_file = out_file mod_opt_index = 0 - compile_as_module = True + compile_as_module = False cmd_args = [] dependency_cmd_args = [] frontend_tool = self.ark_frontend_binary @@ -372,8 +383,7 @@ class ArkProgram(): # for testing no-record-name abc cmd_args = ['node', '--expose-gc', frontend_tool, js_file, '-o', out_file] - if (file_name in self.module_list or file_name in self.dynamicImport_list) \ - and compile_as_module: + if compile_as_module: cmd_args.insert(mod_opt_index, "-m") self.module = True elif self.ark_frontend == ARK_FRONTEND_LIST[1]: @@ -389,8 +399,7 @@ class ArkProgram(): '--function-threads=' + str(self.es2abc_thread_count), '--output', out_file, js_file] - if (file_name in self.module_list or file_name in self.dynamicImport_list) \ - and compile_as_module: + if compile_as_module: cmd_args.insert(mod_opt_index, "--module") self.module = True # get abc file list from import statement diff --git a/test262/ts2abc_skip_tests.json b/test262/ts2abc_skip_tests.json index b95f37d60e..2654bb1dfa 100644 --- a/test262/ts2abc_skip_tests.json +++ b/test262/ts2abc_skip_tests.json @@ -447,5 +447,14 @@ "language/expressions/dynamic-import/usage/syntax-nested-block-labeled-specifier-tostring.js", "language/expressions/dynamic-import/usage/top-level-import-then-specifier-tostring.js" ] + }, + { + "reason" : "Test262Error: it returns the same namespace are the same Expected SameValue", + "files": [ + "language/expressions/dynamic-import/reuse-namespace-object-from-script.js", + "language/expressions/dynamic-import/namespace/await-ns-delete-non-exported-strict.js", + "language/expressions/dynamic-import/namespace/default-property-not-set-own.js", + "language/expressions/dynamic-import/namespace/promise-then-ns-delete-non-exported-strict.js" + ] } ] -- Gitee