diff --git a/ecmascript/compiler/slowpath_lowering.cpp b/ecmascript/compiler/slowpath_lowering.cpp index e35852fb..2a087bcd 100644 --- a/ecmascript/compiler/slowpath_lowering.cpp +++ b/ecmascript/compiler/slowpath_lowering.cpp @@ -229,7 +229,6 @@ void SlowPathLowering::Lower(GateRef gate) GateRef glue = bcBuilder_->GetCommonArgByIndex(CommonArgIdx::GLUE); GateRef newTarget = bcBuilder_->GetCommonArgByIndex(CommonArgIdx::NEW_TARGET); GateRef jsFunc = bcBuilder_->GetCommonArgByIndex(CommonArgIdx::FUNC); - GateRef thisObj = bcBuilder_->GetCommonArgByIndex(CommonArgIdx::THIS); auto pc = bcBuilder_->GetJSBytecode(gate); EcmaOpcode op = static_cast(*pc); @@ -603,7 +602,7 @@ void SlowPathLowering::Lower(GateRef gate) LowerCreateObjectHavingMethod(gate, glue, jsFunc); break; case LDHOMEOBJECT_PREF: - LowerLdHomeObject(gate, thisObj); + LowerLdHomeObject(gate, jsFunc); break; case DEFINECLASSWITHBUFFER_PREF_ID16_IMM16_IMM16_V8_V8: LowerDefineClassWithBuffer(gate, glue, jsFunc); @@ -2523,13 +2522,18 @@ void SlowPathLowering::LowerCreateObjectHavingMethod(GateRef gate, GateRef glue, GateRef literal = GetObjectFromConstPool(jsFunc, imm); GateRef env = acc_.GetValueIn(gate, 1); GateRef constpool = GetConstPool(jsFunc); - GateRef newGate = LowerCallRuntime(glue, id, { literal, env, constpool }); - ReplaceHirToCall(gate, newGate); + GateRef result = LowerCallRuntime(glue, id, { literal, env, constpool }); + Label successExit(&builder_); + Label exceptionExit(&builder_); + builder_.Branch(builder_.IsSpecial(result, JSTaggedValue::VALUE_EXCEPTION), + &exceptionExit, &successExit); + CREATE_DOUBLE_EXIT(successExit, exceptionExit) + ReplaceHirToSubCfg(gate, result, successControl, failControl); } -void SlowPathLowering::LowerLdHomeObject(GateRef gate, GateRef thisFunc) +void SlowPathLowering::LowerLdHomeObject(GateRef gate, GateRef jsFunc) { - GateRef homeObj = GetHomeObjectFromJSFunction(thisFunc); + GateRef homeObj = GetHomeObjectFromJSFunction(jsFunc); std::vector successControl; std::vector exceptionControl; successControl.emplace_back(builder_.GetState()); diff --git a/ecmascript/compiler/slowpath_lowering.h b/ecmascript/compiler/slowpath_lowering.h index 32eea13c..e386102a 100644 --- a/ecmascript/compiler/slowpath_lowering.h +++ b/ecmascript/compiler/slowpath_lowering.h @@ -252,7 +252,7 @@ private: void LowerLdLexVarDyn(GateRef gate, GateRef jsFunc); void LowerStLexVarDyn(GateRef gate, GateRef glue, GateRef jsFunc); void LowerCreateObjectHavingMethod(GateRef gate, GateRef glue, GateRef jsFunc); - void LowerLdHomeObject(GateRef gate, GateRef thisFunc); + void LowerLdHomeObject(GateRef gate, GateRef jsFunc); void LowerDefineClassWithBuffer(GateRef gate, GateRef glue, GateRef jsFunc); void LowerAsyncFunctionEnter(GateRef gate, GateRef glue); void LowerTypeOfDyn(GateRef gate, GateRef glue); diff --git a/test/aottest/createobjecthavingmethod/BUILD.gn b/test/aottest/createobjecthavingmethod/BUILD.gn new file mode 100644 index 00000000..255deb0f --- /dev/null +++ b/test/aottest/createobjecthavingmethod/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("createobjecthavingmethod") { + deps = [] +} diff --git a/test/aottest/createobjecthavingmethod/createobjecthavingmethod.ts b/test/aottest/createobjecthavingmethod/createobjecthavingmethod.ts new file mode 100644 index 00000000..bce0ab6a --- /dev/null +++ b/test/aottest/createobjecthavingmethod/createobjecthavingmethod.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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. + */ + +declare function print(arg:any):string; +var obj = { + value: 1, + fun (a:number) {print(this.value + a)}, +}; + +obj.fun(1); diff --git a/test/aottest/createobjecthavingmethod/expect_output.txt b/test/aottest/createobjecthavingmethod/expect_output.txt new file mode 100644 index 00000000..fbdf0fc9 --- /dev/null +++ b/test/aottest/createobjecthavingmethod/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +2 diff --git a/test/aottest/defineclasswithbuffer/BUILD.gn b/test/aottest/defineclasswithbuffer/BUILD.gn new file mode 100644 index 00000000..010d1752 --- /dev/null +++ b/test/aottest/defineclasswithbuffer/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("defineclasswithbuffer") { + deps = [] +} diff --git a/test/aottest/defineclasswithbuffer/defineclasswithbuffer.ts b/test/aottest/defineclasswithbuffer/defineclasswithbuffer.ts new file mode 100644 index 00000000..6cd4c39d --- /dev/null +++ b/test/aottest/defineclasswithbuffer/defineclasswithbuffer.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 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. + */ + +declare function print(str:any):string; +class Obj1 { + value:number; + constructor(value:number) { + this.value = value; + } +} + +class Obj2 { + fun():void { + print("Hello World"); + } +} + +var obj1 = new Obj1(0); +print(obj1.value); +var obj2 = new Obj2(); +obj2.fun(); diff --git a/test/aottest/defineclasswithbuffer/expect_output.txt b/test/aottest/defineclasswithbuffer/expect_output.txt new file mode 100644 index 00000000..08f99d2d --- /dev/null +++ b/test/aottest/defineclasswithbuffer/expect_output.txt @@ -0,0 +1,15 @@ +# Copyright (c) 2022 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. + +0 +Hello World diff --git a/test/aottest/getiteratornext/BUILD.gn b/test/aottest/getiteratornext/BUILD.gn new file mode 100644 index 00000000..583356e1 --- /dev/null +++ b/test/aottest/getiteratornext/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("getiteratornext") { + deps = [] +} diff --git a/test/aottest/getiteratornext/expect_output.txt b/test/aottest/getiteratornext/expect_output.txt new file mode 100644 index 00000000..b3fd4bf9 --- /dev/null +++ b/test/aottest/getiteratornext/expect_output.txt @@ -0,0 +1,19 @@ +# Copyright (c) 2022 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. + +0 +1 +1 +0 +0 +1,2 diff --git a/test/aottest/getiteratornext/getiteratornext.ts b/test/aottest/getiteratornext/getiteratornext.ts new file mode 100644 index 00000000..aa93493f --- /dev/null +++ b/test/aottest/getiteratornext/getiteratornext.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 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. + */ + +declare function print(str:any):string; +var [a, b] = [0, 1]; +print(a); +print(b); +[a, b] = [b, a]; +print(a); +print(b); + +var [c, ...rest] = [0, 1, 2]; +print(c); +print(rest); diff --git a/test/aottest/isfalse/BUILD.gn b/test/aottest/isfalse/BUILD.gn new file mode 100644 index 00000000..9bf1c4f7 --- /dev/null +++ b/test/aottest/isfalse/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("isfalse") { + deps = [] +} diff --git a/test/aottest/isfalse/isfalse.ts b/test/aottest/isfalse/isfalse.ts new file mode 100644 index 00000000..2affb18d --- /dev/null +++ b/test/aottest/isfalse/isfalse.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 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. + */ + +declare function print(tmp:any):string; +var num1:number = 123; +var num2:number = 0; +var num3:number = -0; +var num4:number = 123.456; +var num5:number = NaN; +var str:string = "abc"; +var empString:string = ""; +var undefinedValue:undefined = undefined; +var nullValue:null = null; +var arr : Array = [1, "a"]; +var obj : {[key:string]:any} = {name: "a"}; + +print(true || true); +print(true || false); +print(false || true); +print(false || false); +print(num1 || 1); +print(num2 || 1); +print(num3 || 1); +print(num4 || 1); +print(num5 || 1); +print(str || 1); +print(empString || 1); +print(undefinedValue || 1); +print(nullValue || 1); +print(arr || 1); +print(obj || 1); diff --git a/test/aottest/isfalse/isfalse_output.txt b/test/aottest/isfalse/isfalse_output.txt new file mode 100644 index 00000000..9d29b8d8 --- /dev/null +++ b/test/aottest/isfalse/isfalse_output.txt @@ -0,0 +1,28 @@ +# Copyright (c) 2022 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. + +true +true +true +false +123 +1 +1 +123.456 +1 +abc +1 +1 +1 +1,a +[object Object] diff --git a/test/aottest/istrue/BUILD.gn b/test/aottest/istrue/BUILD.gn new file mode 100644 index 00000000..63fca023 --- /dev/null +++ b/test/aottest/istrue/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("istrue") { + deps = [] +} diff --git a/test/aottest/istrue/istrue.ts b/test/aottest/istrue/istrue.ts new file mode 100644 index 00000000..f737b770 --- /dev/null +++ b/test/aottest/istrue/istrue.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 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. + */ + +declare function print(tmp:any):string; +var num1:number = 123; +var num2:number = 0; +var num3:number = -0; +var num4:number = 123.456; +var num5:number = NaN; +var str:string = "abc"; +var empString:string = ""; +var undefinedValue:undefined = undefined; +var nullValue:null = null; +var arr : Array = [1, "a"]; +var obj : {[key:string]:any} = {name: "a"}; + +print(true && true); +print(true && false); +print(false && true); +print(false && false); +print(num1 && 1); +print(num2 && 1); +print(num3 && 1); +print(num4 && 1); +print(num5 && 1); +print(str && 1); +print(empString && 1); +print(undefinedValue && 1); +print(nullValue && 1); +print(arr && 1); +print(obj && 1); diff --git a/test/aottest/istrue/istrue_output.txt b/test/aottest/istrue/istrue_output.txt new file mode 100644 index 00000000..03ccb516 --- /dev/null +++ b/test/aottest/istrue/istrue_output.txt @@ -0,0 +1,28 @@ +# Copyright (c) 2022 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. + +true +false +false +false +1 +0 +0 +1 +NaN +1 + +undefined +null +1 +1