diff --git a/es2panda/compiler/core/function.cpp b/es2panda/compiler/core/function.cpp index 8700de95af33e40b60b9131282e3fbdadddb5360..9041063eb7cb54c6f676341095cd3e29ed4813dd 100644 --- a/es2panda/compiler/core/function.cpp +++ b/es2panda/compiler/core/function.cpp @@ -164,7 +164,7 @@ static void CompileField(PandaGen *pg, const ir::ClassProperty *prop, VReg thisR if (prop->IsPrivate()) { pg->DefineClassPrivateField(prop, result.lexLevel, result.result.slot, thisReg); } else { - pg->DefineClassField(prop, thisReg, op); + pg->DefineOwnProperty(prop, thisReg, op); } } diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index be375c35b8241799d2abbee8ad268c2db2563a80..79f9656c1d0d52725383ae7cf32a6a843e22b53b 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -473,7 +473,7 @@ void PandaGen::StoreObjProperty(const ir::AstNode *node, VReg obj, const Operand StoreObjByName(node, obj, std::get(prop)); } -void PandaGen::DefineClassField(const ir::AstNode *node, VReg obj, const Operand &prop) +void PandaGen::DefineOwnProperty(const ir::AstNode *node, VReg obj, const Operand &prop) { if (std::holds_alternative(prop)) { DefineFieldByValue(node, obj, std::get(prop)); diff --git a/es2panda/compiler/core/pandagen.h b/es2panda/compiler/core/pandagen.h index 5702c4dee3af8a6d6936cd7bb4ea335eacf4fb80..5516727bfdc2aa770a39dfe61609b2114fdd0b44 100644 --- a/es2panda/compiler/core/pandagen.h +++ b/es2panda/compiler/core/pandagen.h @@ -303,7 +303,7 @@ public: void LoadObjByName(const ir::AstNode *node, VReg obj, const util::StringView &prop); void StoreObjProperty(const ir::AstNode *node, VReg obj, const Operand &prop); - void DefineClassField(const ir::AstNode *node, VReg obj, const Operand &prop); + void DefineOwnProperty(const ir::AstNode *node, VReg obj, const Operand &prop); void DefineClassPrivateField(const ir::AstNode *node, uint32_t level, uint32_t slot, VReg obj); void StoreOwnProperty(const ir::AstNode *node, VReg obj, const Operand &prop, bool nameSetting = false); void DeleteObjProperty(const ir::AstNode *node, VReg obj, const Operand &prop); diff --git a/es2panda/ir/expressions/objectExpression.cpp b/es2panda/ir/expressions/objectExpression.cpp index 07517eac04b457e7e7150b7a17ccc50ee5b2e552..90cc020fa8efa91683bf5df80d432b69618e711b 100644 --- a/es2panda/ir/expressions/objectExpression.cpp +++ b/es2panda/ir/expressions/objectExpression.cpp @@ -394,7 +394,11 @@ void ObjectExpression::CompilePropertyWithInit(compiler::PandaGen *pg, const ir: } value->Compile(pg); - pg->StoreOwnProperty(this, objReg, key, nameSetting); + if (!nameSetting && pg->Binder()->Program()->TargetApiVersion() > 10) { + pg->DefineOwnProperty(this, objReg, key); + } else { + pg->StoreOwnProperty(this, objReg, key, nameSetting); + } pg->SetSourceLocationFlag(lexer::SourceLocationFlag::VALID_SOURCE_LOCATION); } diff --git a/es2panda/test/bytecode/commonjs/test-commonjs-main-func-args-expected.txt b/es2panda/test/bytecode/commonjs/test-commonjs-main-func-args-expected.txt index 7b14cad06485f3e6a9847b4272d8249dbcd1992f..ab578fdfd2eac069c051a7104cf5b8c76d54719d 100644 --- a/es2panda/test/bytecode/commonjs/test-commonjs-main-func-args-expected.txt +++ b/es2panda/test/bytecode/commonjs/test-commonjs-main-func-args-expected.txt @@ -8,7 +8,7 @@ label_0: createobjectwithbuffer 0x0, _0 sta v1 lda v0 - stownbyname 0x1, a, v1 + definefieldbyname 0x1, a, v1 ldundefined returnundefined label_2: diff --git a/es2panda/test/compiler/js/objectExpression/object-define-property-expected.txt b/es2panda/test/compiler/js/objectExpression/object-define-property-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/es2panda/test/compiler/js/objectExpression/object-define-property.js b/es2panda/test/compiler/js/objectExpression/object-define-property.js new file mode 100644 index 0000000000000000000000000000000000000000..8f2311408aec3a1c867b7ed100851b89dcd35bfb --- /dev/null +++ b/es2panda/test/compiler/js/objectExpression/object-define-property.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function func() { + let a = 1; + let obj = { + set a(run) { + run() + }, + [a]: 1, + "b": 2, + a: func + } +} +func(); \ No newline at end of file diff --git a/es2panda/test/parser/binder/test-func-naming-expected.txt b/es2panda/test/parser/binder/test-func-naming-expected.txt index 793348b89422b7a5c6fe434b05ebcb5d4c327c25..455956e2aa46d5401aac730f64a4d3257b78f870 100644 --- a/es2panda/test/parser/binder/test-func-naming-expected.txt +++ b/es2panda/test/parser/binder/test-func-naming-expected.txt @@ -66,13 +66,13 @@ label_0: createobjectwithbuffer 0x7, _0 sta v0 definefunc 0x8, .#1471473088249306135#, 0x0 - stownbyname 0x9, index.js, v0 + definefieldbyname 0x9, index.js, v0 lda v0 sttoglobalrecord 0xb, obj createobjectwithbuffer 0xc, _1 sta v0 definefunc 0xd, .#5496465400387880830#, 0x0 - stownbyname 0xe, \testcase, v0 + definefieldbyname 0xe, \testcase, v0 lda v0 sttoglobalrecord 0x10, objBackslash ldundefined