diff --git a/ecmascript/compiler/type.cpp b/ecmascript/compiler/type.cpp index ece2b2abc8..771846b494 100644 --- a/ecmascript/compiler/type.cpp +++ b/ecmascript/compiler/type.cpp @@ -29,35 +29,10 @@ std::string GateType::GetTypeStr() const { GlobalTSTypeRef gt = GlobalTSTypeRef(GetType()); ASSERT(gt.GetFlag() == 0); - if (IsPrimitiveTypeKind()) { - auto primitive = static_cast(gt.GetLocalId()); - switch (primitive) { - case TSPrimitiveType::ANY: - return "any"; - case TSPrimitiveType::NUMBER: - return "number"; - case TSPrimitiveType::BOOLEAN: - return "boolean"; - case TSPrimitiveType::VOID_TYPE: - return "void"; - case TSPrimitiveType::STRING: - return "string"; - case TSPrimitiveType::SYMBOL: - return "symbol"; - case TSPrimitiveType::NULL_TYPE: - return "null"; - case TSPrimitiveType::UNDEFINED: - return "undefined"; - case TSPrimitiveType::INT: - return "int"; - case TSPrimitiveType::BIG_INT: - return "big_int"; - default: - break; - } - } auto typeKind = static_cast(gt.GetKind()); switch (typeKind) { + case TSTypeKind::PRIMITIVE: + return GetPrimitiveStr(gt); case TSTypeKind::CLASS: return "class"; case TSTypeKind::CLASS_INSTANCE: @@ -75,8 +50,37 @@ std::string GateType::GetTypeStr() const case TSTypeKind::INTERFACE_KIND: return "interface"; default: - break; + UNREACHABLE(); + } +} + +std::string GateType::GetPrimitiveStr(const GlobalTSTypeRef gt) const +{ + ASSERT(IsPrimitiveTypeKind()); + auto primitive = static_cast(gt.GetLocalId()); + switch (primitive) { + case TSPrimitiveType::ANY: + return "any"; + case TSPrimitiveType::NUMBER: + return "number"; + case TSPrimitiveType::BOOLEAN: + return "boolean"; + case TSPrimitiveType::VOID_TYPE: + return "void"; + case TSPrimitiveType::STRING: + return "string"; + case TSPrimitiveType::SYMBOL: + return "symbol"; + case TSPrimitiveType::NULL_TYPE: + return "null"; + case TSPrimitiveType::UNDEFINED: + return "undefined"; + case TSPrimitiveType::INT: + return "int"; + case TSPrimitiveType::BIG_INT: + return "bigint"; + default: + UNREACHABLE(); } - return "gatetype:" + std::to_string(gt.GetType()); } }; // namespace panda::ecmascript::kungfu \ No newline at end of file diff --git a/ecmascript/compiler/type.h b/ecmascript/compiler/type.h index 5dec85bb89..f6200f135b 100644 --- a/ecmascript/compiler/type.h +++ b/ecmascript/compiler/type.h @@ -276,6 +276,8 @@ public: std::string GetTypeStr() const; + std::string GetPrimitiveStr(const GlobalTSTypeRef gt) const; + private: uint32_t type_ {0}; }; diff --git a/ecmascript/compiler/type_inference/type_infer.cpp b/ecmascript/compiler/type_inference/type_infer.cpp index 72e08ff177..ef37503416 100644 --- a/ecmascript/compiler/type_inference/type_infer.cpp +++ b/ecmascript/compiler/type_inference/type_infer.cpp @@ -145,7 +145,6 @@ bool TypeInfer::Infer(GateRef gate) case EcmaOpcode::EXPDYN_PREF_V8: case EcmaOpcode::STARRAYSPREAD_PREF_V8_V8: return SetNumberType(gate); - break; case EcmaOpcode::LDTRUE_PREF: case EcmaOpcode::LDFALSE_PREF: case EcmaOpcode::EQDYN_PREF_V8: @@ -163,56 +162,40 @@ bool TypeInfer::Infer(GateRef gate) case EcmaOpcode::SETOBJECTWITHPROTO_PREF_V8_V8: case EcmaOpcode::DELOBJPROP_PREF_V8_V8: return SetBooleanType(gate); - break; case EcmaOpcode::LDUNDEFINED_PREF: return InferLdUndefined(gate); - break; case EcmaOpcode::LDNULL_PREF: return InferLdNull(gate); - break; case EcmaOpcode::LDAI_DYN_IMM32: return InferLdaiDyn(gate); - break; case EcmaOpcode::FLDAI_DYN_IMM64: return InferFLdaiDyn(gate); - break; case EcmaOpcode::LDSYMBOL_PREF: return InferLdSymbol(gate); - break; case EcmaOpcode::THROWDYN_PREF: return InferThrowDyn(gate); - break; case EcmaOpcode::TYPEOFDYN_PREF: return InferTypeOfDyn(gate); - break; case EcmaOpcode::ADD2DYN_PREF_V8: return InferAdd2Dyn(gate); - break; case EcmaOpcode::LDOBJBYINDEX_PREF_V8_IMM32: return InferLdObjByIndex(gate); - break; case EcmaOpcode::STGLOBALVAR_PREF_ID32: case EcmaOpcode::STCONSTTOGLOBALRECORD_PREF_ID32: case EcmaOpcode::TRYSTGLOBALBYNAME_PREF_ID32: case EcmaOpcode::STLETTOGLOBALRECORD_PREF_ID32: case EcmaOpcode::STCLASSTOGLOBALRECORD_PREF_ID32: return SetStGlobalBcType(gate); - break; case EcmaOpcode::LDGLOBALVAR_PREF_ID32: return InferLdGlobalVar(gate); - break; case EcmaOpcode::RETURNUNDEFINED_PREF: return InferReturnUndefined(gate); - break; case EcmaOpcode::RETURN_DYN: return InferReturnDyn(gate); - break; case EcmaOpcode::LDOBJBYNAME_PREF_ID32_V8: return InferLdObjByName(gate); - break; case EcmaOpcode::LDA_STR_ID32: return InferLdStr(gate); - break; case EcmaOpcode::CALLARG0DYN_PREF_V8: case EcmaOpcode::CALLARG1DYN_PREF_V8_V8: case EcmaOpcode::CALLARGS2DYN_PREF_V8_V8_V8: @@ -221,23 +204,19 @@ bool TypeInfer::Infer(GateRef gate) case EcmaOpcode::CALLIRANGEDYN_PREF_IMM16_V8: case EcmaOpcode::CALLITHISRANGEDYN_PREF_IMM16_V8: return InferCallFunction(gate); - break; case EcmaOpcode::LDOBJBYVALUE_PREF_V8_V8: return InferLdObjByValue(gate); - break; case EcmaOpcode::GETNEXTPROPNAME_PREF_V8: return InferGetNextPropName(gate); - break; case EcmaOpcode::DEFINEGETTERSETTERBYVALUE_PREF_V8_V8_V8_V8: return InferDefineGetterSetterByValue(gate); - break; case EcmaOpcode::NEWOBJSPREADDYN_PREF_V8_V8: return InferNewObjSpread(gate); - break; case EcmaOpcode::SUPERCALL_PREF_IMM16_V8: case EcmaOpcode::SUPERCALLSPREAD_PREF_V8: return InferSuperCall(gate); - break; + case EcmaOpcode::TRYLDGLOBALBYNAME_PREF_ID32: + return InferTryLdGlobalByName(gate); default: break; } @@ -494,4 +473,17 @@ bool TypeInfer::InferSuperCall(GateRef gate) } return false; } + +bool TypeInfer::InferTryLdGlobalByName(GateRef gate) +{ + // todo by hongtao, should consider function of .d.ts + auto byteCodeInfo = builder_->GetByteCodeInfo(gate); + ASSERT(byteCodeInfo.inputs.size() == 1); + auto stringId = std::get(byteCodeInfo.inputs[0]).GetId(); + auto iter = stringIdToGateType_.find(stringId); + if (iter != stringIdToGateType_.end()) { + return UpdateType(gate, iter->second); + } + return false; +} } // namespace panda::ecmascript diff --git a/ecmascript/compiler/type_inference/type_infer.h b/ecmascript/compiler/type_inference/type_infer.h index 79d97aab71..30ec6bb96f 100644 --- a/ecmascript/compiler/type_inference/type_infer.h +++ b/ecmascript/compiler/type_inference/type_infer.h @@ -68,6 +68,7 @@ private: bool InferDefineGetterSetterByValue(GateRef gate); bool InferNewObjSpread(GateRef gate); bool InferSuperCall(GateRef gate); + bool InferTryLdGlobalByName(GateRef gate); void TypeInferPrint() const; BytecodeCircuitBuilder *builder_ {nullptr}; diff --git a/test/typeinfer/BUILD.gn b/test/typeinfer/BUILD.gn index 47955ab73c..202ddc805b 100644 --- a/test/typeinfer/BUILD.gn +++ b/test/typeinfer/BUILD.gn @@ -14,6 +14,11 @@ group("ark_typeinfer_test") { testonly = true deps = [ + "add2dyn_1:add2dyn_1AotTypeInferAction", + "add2dyn_2:add2dyn_2AotTypeInferAction", + "add2dyn_3:add2dyn_3AotTypeInferAction", + "add2dyn_4:add2dyn_4AotTypeInferAction", + "add2dyn_5:add2dyn_5AotTypeInferAction", "bitwise_op:bitwise_opAotTypeInferAction", "callarg0dyn:callarg0dynAotTypeInferAction", "callarg1dyn:callarg1dynAotTypeInferAction", @@ -21,8 +26,36 @@ group("ark_typeinfer_test") { "callargs3dyn:callargs3dynAotTypeInferAction", "callirangedyn:callirangedynAotTypeInferAction", "callithisrange:callithisrangeAotTypeInferAction", + "createemptyarray:createemptyarrayAotTypeInferAction", + "createemptyobject:createemptyobjectAotTypeInferAction", + "createobjecthavingmethod:createobjecthavingmethodAotTypeInferAction", + "defineasyncfunc:defineasyncfuncAotTypeInferAction", + "defineclasswithbuffer:defineclasswithbufferAotTypeInferAction", + "definegeneratorfunc:definegeneratorfuncAotTypeInferAction", + "div2dyn:div2dynAotTypeInferAction", + "eqdyn:eqdynAotTypeInferAction", + "ldboolean:ldbooleanAotTypeInferAction", + "ldglobalvar:ldglobalvarAotTypeInferAction", + "ldinfinity:ldinfinityAotTypeInferAction", + "ldnan:ldnanAotTypeInferAction", + "ldnull:ldnullAotTypeInferAction", + "ldobjbyindex:ldobjbyindexAotTypeInferAction", "ldobjbyname:ldobjbynameAotTypeInferAction", + "ldobjbyname_1:ldobjbyname_1AotTypeInferAction", "ldobjbyvalue:ldobjbyvalueAotTypeInferAction", + "ldundefined:ldundefinedAotTypeInferAction", + "lessdyn:lessdynAotTypeInferAction", + "lesseqdyn:lesseqdynAotTypeInferAction", "logic_op:logic_opAotTypeInferAction", + "mul2dyn:mul2dynAotTypeInferAction", + "newobjdynrange:newobjdynrangeAotTypeInferAction", + "stconsttoglobalrecord:stconsttoglobalrecordAotTypeInferAction", + "stglobalvar:stglobalvarAotTypeInferAction", + "stlettoglobalrecord:stlettoglobalrecordAotTypeInferAction", + "sub2dyn:sub2dynAotTypeInferAction", + "throwdyn_1:throwdyn_1AotTypeInferAction", + "throwdyn_2:throwdyn_2AotTypeInferAction", + "trystglobalbyname:trystglobalbynameAotTypeInferAction", + "typeof:typeofAotTypeInferAction", ] } diff --git a/test/typeinfer/add2dyn_1/BUILD.gn b/test/typeinfer/add2dyn_1/BUILD.gn new file mode 100644 index 0000000000..513a6d175a --- /dev/null +++ b/test/typeinfer/add2dyn_1/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_typeinfer_test_action("add2dyn_1") { + deps = [] +} diff --git a/test/typeinfer/add2dyn_1/add2dyn_1.ts b/test/typeinfer/add2dyn_1/add2dyn_1.ts new file mode 100644 index 0000000000..dc080599fc --- /dev/null +++ b/test/typeinfer/add2dyn_1/add2dyn_1.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let num1 : number = 1; + let num2 : number = 2; + let ans = num1 + num2; + typeof(ans); +} \ No newline at end of file diff --git a/test/typeinfer/add2dyn_1/expect_output.txt b/test/typeinfer/add2dyn_1/expect_output.txt new file mode 100644 index 0000000000..20bff8130d --- /dev/null +++ b/test/typeinfer/add2dyn_1/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. + +LDA_STR:string,ADD2DYN:number,TYPEOFDYN:number \ No newline at end of file diff --git a/test/typeinfer/add2dyn_2/BUILD.gn b/test/typeinfer/add2dyn_2/BUILD.gn new file mode 100644 index 0000000000..ed26366c8d --- /dev/null +++ b/test/typeinfer/add2dyn_2/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_typeinfer_test_action("add2dyn_2") { + deps = [] +} diff --git a/test/typeinfer/add2dyn_2/add2dyn_2.ts b/test/typeinfer/add2dyn_2/add2dyn_2.ts new file mode 100644 index 0000000000..36854dd3af --- /dev/null +++ b/test/typeinfer/add2dyn_2/add2dyn_2.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let arr1 : number[] = [1, 2]; + let arr2 : number[] = [1, 2]; + let ans = arr1[0] + arr2[0]; + typeof(ans) +} \ No newline at end of file diff --git a/test/typeinfer/add2dyn_2/expect_output.txt b/test/typeinfer/add2dyn_2/expect_output.txt new file mode 100644 index 0000000000..4d4b07e01a --- /dev/null +++ b/test/typeinfer/add2dyn_2/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. + +LDA_STR:string,CREATEARRAYWITHBUFFER:array,CREATEARRAYWITHBUFFER:array, +LDOBJBYINDEX:number,LDOBJBYINDEX:number,ADD2DYN:number,TYPEOFDYN:number \ No newline at end of file diff --git a/test/typeinfer/add2dyn_3/BUILD.gn b/test/typeinfer/add2dyn_3/BUILD.gn new file mode 100644 index 0000000000..72a87e4c0f --- /dev/null +++ b/test/typeinfer/add2dyn_3/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_typeinfer_test_action("add2dyn_3") { + deps = [] +} diff --git a/test/typeinfer/add2dyn_3/add2dyn_3.ts b/test/typeinfer/add2dyn_3/add2dyn_3.ts new file mode 100644 index 0000000000..10d4c22bee --- /dev/null +++ b/test/typeinfer/add2dyn_3/add2dyn_3.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let arr1 : string[] = ['1']; + let arr2 : string[] = ['1']; + let ans = arr1[0] + arr2[0]; + typeof(ans) +} \ No newline at end of file diff --git a/test/typeinfer/add2dyn_3/expect_output.txt b/test/typeinfer/add2dyn_3/expect_output.txt new file mode 100644 index 0000000000..e1870c911d --- /dev/null +++ b/test/typeinfer/add2dyn_3/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. + +LDA_STR:string,CREATEARRAYWITHBUFFER:array,CREATEARRAYWITHBUFFER:array, +LDOBJBYINDEX:string,LDOBJBYINDEX:string,ADD2DYN:string,TYPEOFDYN:string \ No newline at end of file diff --git a/test/typeinfer/add2dyn_4/BUILD.gn b/test/typeinfer/add2dyn_4/BUILD.gn new file mode 100644 index 0000000000..bcd4643a82 --- /dev/null +++ b/test/typeinfer/add2dyn_4/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_typeinfer_test_action("add2dyn_4") { + deps = [] +} diff --git a/test/typeinfer/add2dyn_4/add2dyn_4.ts b/test/typeinfer/add2dyn_4/add2dyn_4.ts new file mode 100644 index 0000000000..edee088c79 --- /dev/null +++ b/test/typeinfer/add2dyn_4/add2dyn_4.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let str1 : string = '1'; + let str2 : string = '2'; + let str3 = str1 + str2; + typeof(str3); +} \ No newline at end of file diff --git a/test/typeinfer/add2dyn_4/expect_output.txt b/test/typeinfer/add2dyn_4/expect_output.txt new file mode 100644 index 0000000000..f61a707664 --- /dev/null +++ b/test/typeinfer/add2dyn_4/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. + +LDA_STR:string,LDA_STR:string,ADD2DYN:string,TYPEOFDYN:string \ No newline at end of file diff --git a/test/typeinfer/add2dyn_5/BUILD.gn b/test/typeinfer/add2dyn_5/BUILD.gn new file mode 100644 index 0000000000..f899f556d3 --- /dev/null +++ b/test/typeinfer/add2dyn_5/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_typeinfer_test_action("add2dyn_5") { + deps = [] +} diff --git a/test/typeinfer/add2dyn_5/add2dyn_5.ts b/test/typeinfer/add2dyn_5/add2dyn_5.ts new file mode 100644 index 0000000000..f33ec7365e --- /dev/null +++ b/test/typeinfer/add2dyn_5/add2dyn_5.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let arr1 : number[] = [1, 2]; + let arr2 : string[] = ['0']; + let d = arr1[0] + arr2[0]; + typeof(d) +} \ No newline at end of file diff --git a/test/typeinfer/add2dyn_5/expect_output.txt b/test/typeinfer/add2dyn_5/expect_output.txt new file mode 100644 index 0000000000..61a9f07d28 --- /dev/null +++ b/test/typeinfer/add2dyn_5/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. + +CREATEARRAYWITHBUFFER:array,CREATEARRAYWITHBUFFER:array, +LDOBJBYINDEX:number,LDOBJBYINDEX:string,ADD2DYN:string,TYPEOFDYN:string \ No newline at end of file diff --git a/test/typeinfer/createemptyarray/BUILD.gn b/test/typeinfer/createemptyarray/BUILD.gn new file mode 100644 index 0000000000..46dfc9be48 --- /dev/null +++ b/test/typeinfer/createemptyarray/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_typeinfer_test_action("createemptyarray") { + deps = [] +} diff --git a/test/typeinfer/createemptyarray/createemptyarray.ts b/test/typeinfer/createemptyarray/createemptyarray.ts new file mode 100644 index 0000000000..e3e607a48d --- /dev/null +++ b/test/typeinfer/createemptyarray/createemptyarray.ts @@ -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. + */ + +{ + let arr:boolean[]= []; + typeof(arr); +} \ No newline at end of file diff --git a/test/typeinfer/createemptyarray/expect_output.txt b/test/typeinfer/createemptyarray/expect_output.txt new file mode 100644 index 0000000000..e6b3b70da5 --- /dev/null +++ b/test/typeinfer/createemptyarray/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. + +LDA_STR:string,CREATEEMPTYARRAY:array,TYPEOFDYN:array \ No newline at end of file diff --git a/test/typeinfer/createemptyobject/BUILD.gn b/test/typeinfer/createemptyobject/BUILD.gn new file mode 100644 index 0000000000..6fa9107170 --- /dev/null +++ b/test/typeinfer/createemptyobject/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_typeinfer_test_action("createemptyobject") { + deps = [] +} diff --git a/test/typeinfer/createemptyobject/createemptyobject.ts b/test/typeinfer/createemptyobject/createemptyobject.ts new file mode 100644 index 0000000000..f6a799b919 --- /dev/null +++ b/test/typeinfer/createemptyobject/createemptyobject.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +{ + let obj : { + + } = { + + }; + typeof(obj); +} \ No newline at end of file diff --git a/test/typeinfer/createemptyobject/expect_output.txt b/test/typeinfer/createemptyobject/expect_output.txt new file mode 100644 index 0000000000..c39c4ff4c1 --- /dev/null +++ b/test/typeinfer/createemptyobject/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. + +LDA_STR:string,CREATEEMPTYOBJECT:object,TYPEOFDYN:object \ No newline at end of file diff --git a/test/typeinfer/createobjecthavingmethod/BUILD.gn b/test/typeinfer/createobjecthavingmethod/BUILD.gn new file mode 100644 index 0000000000..945312f330 --- /dev/null +++ b/test/typeinfer/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_typeinfer_test_action("createobjecthavingmethod") { + deps = [] +} diff --git a/test/typeinfer/createobjecthavingmethod/createobjecthavingmethod.ts b/test/typeinfer/createobjecthavingmethod/createobjecthavingmethod.ts new file mode 100644 index 0000000000..b2d4a83d03 --- /dev/null +++ b/test/typeinfer/createobjecthavingmethod/createobjecthavingmethod.ts @@ -0,0 +1,27 @@ +/* + * 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. + */ + +{ + let xiaoming : { + age : number, + fun() : number, + } = { + age : 1, + fun() { + return 1; + }, + } + typeof(xiaoming.age); +} \ No newline at end of file diff --git a/test/typeinfer/createobjecthavingmethod/expect_output.txt b/test/typeinfer/createobjecthavingmethod/expect_output.txt new file mode 100644 index 0000000000..cfbb439dc7 --- /dev/null +++ b/test/typeinfer/createobjecthavingmethod/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. + +LDA_STR:string,CREATEOBJECTHAVINGMETHOD:object, +LDOBJBYNAME:number,TYPEOFDYN:number \ No newline at end of file diff --git a/test/typeinfer/defineasyncfunc/BUILD.gn b/test/typeinfer/defineasyncfunc/BUILD.gn new file mode 100644 index 0000000000..5f09c26626 --- /dev/null +++ b/test/typeinfer/defineasyncfunc/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_typeinfer_test_action("defineasyncfunc") { + deps = [] +} diff --git a/test/typeinfer/defineasyncfunc/defineasyncfunc.ts b/test/typeinfer/defineasyncfunc/defineasyncfunc.ts new file mode 100644 index 0000000000..fcbb74e2f6 --- /dev/null +++ b/test/typeinfer/defineasyncfunc/defineasyncfunc.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. + */ + +{ + async function add(num1:number, num2:number):Promise { + let ans = num1 + num2; + return ans; + } + typeof(add(1, 2)); +} \ No newline at end of file diff --git a/test/typeinfer/defineasyncfunc/expect_output.txt b/test/typeinfer/defineasyncfunc/expect_output.txt new file mode 100644 index 0000000000..3fa03ee1e9 --- /dev/null +++ b/test/typeinfer/defineasyncfunc/expect_output.txt @@ -0,0 +1,16 @@ +# 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. + +LDA_STR:string,DEFINEASYNCFUNC:function,LDAI_DYN:number,LDAI_DYN:number,RETURNUNDEFINED:undefined +---- +LDTRUE:boolean,ADD2DYN:number \ No newline at end of file diff --git a/test/typeinfer/defineclasswithbuffer/BUILD.gn b/test/typeinfer/defineclasswithbuffer/BUILD.gn new file mode 100644 index 0000000000..b593c744c4 --- /dev/null +++ b/test/typeinfer/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_typeinfer_test_action("defineclasswithbuffer") { + deps = [] +} diff --git a/test/typeinfer/defineclasswithbuffer/defineclasswithbuffer.ts b/test/typeinfer/defineclasswithbuffer/defineclasswithbuffer.ts new file mode 100644 index 0000000000..0b3e7ba55f --- /dev/null +++ b/test/typeinfer/defineclasswithbuffer/defineclasswithbuffer.ts @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + class Student { + name : number; + constructor(name : number) { + this.name = name; + } + } + let stu = new Student(10); + typeof(stu); +} \ No newline at end of file diff --git a/test/typeinfer/defineclasswithbuffer/expect_output.txt b/test/typeinfer/defineclasswithbuffer/expect_output.txt new file mode 100644 index 0000000000..0e67a8d570 --- /dev/null +++ b/test/typeinfer/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. + +LDA_STR:string,DEFINECLASSWITHBUFFER:class,NEWOBJDYNRANGE:class_instance,TYPEOFDYN:class_instance +---- \ No newline at end of file diff --git a/test/typeinfer/definefunctiondyn/BUILD.gn b/test/typeinfer/definefunctiondyn/BUILD.gn new file mode 100644 index 0000000000..c98e4e555f --- /dev/null +++ b/test/typeinfer/definefunctiondyn/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_typeinfer_test_action("definefunctiondyn") { + deps = [] +} diff --git a/test/typeinfer/definefunctiondyn/definefunctiondyn.ts b/test/typeinfer/definefunctiondyn/definefunctiondyn.ts new file mode 100644 index 0000000000..5ea73ddb3a --- /dev/null +++ b/test/typeinfer/definefunctiondyn/definefunctiondyn.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. + */ + +{ + function add():string { + return 1 + '2'; + } + + function sub(a:number, b:number):number { + return a + b; + } + add(); + sub(1,2); +} \ No newline at end of file diff --git a/test/typeinfer/definefunctiondyn/expect_output.txt b/test/typeinfer/definefunctiondyn/expect_output.txt new file mode 100644 index 0000000000..89f2cb5fe3 --- /dev/null +++ b/test/typeinfer/definefunctiondyn/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. + +LDA_STR:string,DEFINEFUNCDYN:function,DEFINEFUNCDYN:function, +CALLARG0DYN:string,CALLARGS2DYN:number +---- +LDA_STR:string,ADD2DYN:string +---- +ADD2DYN:number \ No newline at end of file diff --git a/test/typeinfer/definegeneratorfunc/BUILD.gn b/test/typeinfer/definegeneratorfunc/BUILD.gn new file mode 100644 index 0000000000..3e0017d461 --- /dev/null +++ b/test/typeinfer/definegeneratorfunc/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_typeinfer_test_action("definegeneratorfunc") { + deps = [] +} diff --git a/test/typeinfer/definegeneratorfunc/definegeneratorfunc.ts b/test/typeinfer/definegeneratorfunc/definegeneratorfunc.ts new file mode 100644 index 0000000000..52f0556007 --- /dev/null +++ b/test/typeinfer/definegeneratorfunc/definegeneratorfunc.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +{ + function* genfunc() { + yield "1"; + yield "2"; + } + let gen = genfunc(); + gen.next() +} \ No newline at end of file diff --git a/test/typeinfer/definegeneratorfunc/expect_output.txt b/test/typeinfer/definegeneratorfunc/expect_output.txt new file mode 100644 index 0000000000..8e01433e32 --- /dev/null +++ b/test/typeinfer/definegeneratorfunc/expect_output.txt @@ -0,0 +1,17 @@ +# 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. + +LDA_STR:string,DEFINEGENERATORFUNC:function,RETURNUNDEFINED:undefined +---- +LDFALSE:boolean,LDUNDEFINED:undefined,LDAI_DYN:number,LDAI_DYN:number,LDA_STR:string,LDAI_DYN:number, +LDAI_DYN:number,LDA_STR:string,LDAI_DYN:number,LDAI_DYN:number,EQDYN:boolean,RETURNUNDEFINED:undefined \ No newline at end of file diff --git a/test/typeinfer/div2dyn/BUILD.gn b/test/typeinfer/div2dyn/BUILD.gn new file mode 100644 index 0000000000..4fa00ce231 --- /dev/null +++ b/test/typeinfer/div2dyn/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_typeinfer_test_action("div2dyn") { + deps = [] +} diff --git a/test/typeinfer/div2dyn/div2dyn.ts b/test/typeinfer/div2dyn/div2dyn.ts new file mode 100644 index 0000000000..d5e7c88009 --- /dev/null +++ b/test/typeinfer/div2dyn/div2dyn.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let num1 : number = 1; + let num2 : number = 2; + let ans = num1 / num2; + typeof(ans); +} \ No newline at end of file diff --git a/test/typeinfer/div2dyn/expect_output.txt b/test/typeinfer/div2dyn/expect_output.txt new file mode 100644 index 0000000000..014103fcb4 --- /dev/null +++ b/test/typeinfer/div2dyn/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. + +LDA_STR:string,DIV2DYN:number,TYPEOFDYN:number \ No newline at end of file diff --git a/test/typeinfer/eqdyn/BUILD.gn b/test/typeinfer/eqdyn/BUILD.gn new file mode 100644 index 0000000000..48d4edf32e --- /dev/null +++ b/test/typeinfer/eqdyn/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_typeinfer_test_action("eqdyn") { + deps = [] +} diff --git a/test/typeinfer/eqdyn/eqdyn.ts b/test/typeinfer/eqdyn/eqdyn.ts new file mode 100644 index 0000000000..a06ccb7dd7 --- /dev/null +++ b/test/typeinfer/eqdyn/eqdyn.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let num1 : number = 1; + let num2 : number = 2; + let ans = (num1 == num2); + typeof(ans); +} \ No newline at end of file diff --git a/test/typeinfer/eqdyn/expect_output.txt b/test/typeinfer/eqdyn/expect_output.txt new file mode 100644 index 0000000000..46f1077ae6 --- /dev/null +++ b/test/typeinfer/eqdyn/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. + +LDA_STR:string,EQDYN:boolean,TYPEOFDYN:boolean \ No newline at end of file diff --git a/test/typeinfer/ldboolean/BUILD.gn b/test/typeinfer/ldboolean/BUILD.gn new file mode 100644 index 0000000000..8b5fe853de --- /dev/null +++ b/test/typeinfer/ldboolean/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_typeinfer_test_action("ldboolean") { + deps = [] +} diff --git a/test/typeinfer/ldboolean/expect_output.txt b/test/typeinfer/ldboolean/expect_output.txt new file mode 100644 index 0000000000..bf4093a8b8 --- /dev/null +++ b/test/typeinfer/ldboolean/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. + +LDA_STR:string,STLETTOGLOBALRECORD:boolean,TRYLDGLOBALBYNAME:boolean,TYPEOFDYN:boolean, +TRYSTGLOBALBYNAME:boolean,TRYLDGLOBALBYNAME:boolean,TYPEOFDYN:boolean \ No newline at end of file diff --git a/test/typeinfer/ldboolean/ldboolean.ts b/test/typeinfer/ldboolean/ldboolean.ts new file mode 100644 index 0000000000..b6ff70ccca --- /dev/null +++ b/test/typeinfer/ldboolean/ldboolean.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +let variable = true; +typeof(variable) + +variable = false; +typeof(variable); \ No newline at end of file diff --git a/test/typeinfer/ldglobalvar/BUILD.gn b/test/typeinfer/ldglobalvar/BUILD.gn new file mode 100644 index 0000000000..88693d5212 --- /dev/null +++ b/test/typeinfer/ldglobalvar/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_typeinfer_test_action("ldglobalvar") { + deps = [] +} diff --git a/test/typeinfer/ldglobalvar/expect_output.txt b/test/typeinfer/ldglobalvar/expect_output.txt new file mode 100644 index 0000000000..fb37af6ab3 --- /dev/null +++ b/test/typeinfer/ldglobalvar/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. + +LDA_STR:string,STGLOBALVAR:number,STGLOBALVAR:number,STGLOBALVAR:number, +STGLOBALVAR:number,LDGLOBALVAR:number,STGLOBALVAR:number \ No newline at end of file diff --git a/test/typeinfer/ldglobalvar/ldglobalvar.ts b/test/typeinfer/ldglobalvar/ldglobalvar.ts new file mode 100644 index 0000000000..87c3e21510 --- /dev/null +++ b/test/typeinfer/ldglobalvar/ldglobalvar.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +var num1:number = 1; +num1 = 2; +num1 = 3; +num1 =10; +var ans = num1; \ No newline at end of file diff --git a/test/typeinfer/ldinfinity/BUILD.gn b/test/typeinfer/ldinfinity/BUILD.gn new file mode 100644 index 0000000000..bfa5a904e0 --- /dev/null +++ b/test/typeinfer/ldinfinity/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_typeinfer_test_action("ldinfinity") { + deps = [] +} diff --git a/test/typeinfer/ldinfinity/expect_output.txt b/test/typeinfer/ldinfinity/expect_output.txt new file mode 100644 index 0000000000..3343e61b21 --- /dev/null +++ b/test/typeinfer/ldinfinity/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. + +LDA_STR:string,STLETTOGLOBALRECORD:number,TRYLDGLOBALBYNAME:number,TYPEOFDYN:number \ No newline at end of file diff --git a/test/typeinfer/ldinfinity/ldinfinity.ts b/test/typeinfer/ldinfinity/ldinfinity.ts new file mode 100644 index 0000000000..132305e35a --- /dev/null +++ b/test/typeinfer/ldinfinity/ldinfinity.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +let num = Infinity; +typeof(num); \ No newline at end of file diff --git a/test/typeinfer/ldnan/BUILD.gn b/test/typeinfer/ldnan/BUILD.gn new file mode 100644 index 0000000000..8a8bdeed77 --- /dev/null +++ b/test/typeinfer/ldnan/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_typeinfer_test_action("ldnan") { + deps = [] +} diff --git a/test/typeinfer/ldnan/expect_output.txt b/test/typeinfer/ldnan/expect_output.txt new file mode 100644 index 0000000000..3343e61b21 --- /dev/null +++ b/test/typeinfer/ldnan/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. + +LDA_STR:string,STLETTOGLOBALRECORD:number,TRYLDGLOBALBYNAME:number,TYPEOFDYN:number \ No newline at end of file diff --git a/test/typeinfer/ldnan/ldnan.ts b/test/typeinfer/ldnan/ldnan.ts new file mode 100644 index 0000000000..7d0051c115 --- /dev/null +++ b/test/typeinfer/ldnan/ldnan.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +let num = NaN; +typeof(num); \ No newline at end of file diff --git a/test/typeinfer/ldnull/BUILD.gn b/test/typeinfer/ldnull/BUILD.gn new file mode 100644 index 0000000000..c6369c7ec1 --- /dev/null +++ b/test/typeinfer/ldnull/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_typeinfer_test_action("ldnull") { + deps = [] +} diff --git a/test/typeinfer/ldnull/expect_output.txt b/test/typeinfer/ldnull/expect_output.txt new file mode 100644 index 0000000000..d26a73b16a --- /dev/null +++ b/test/typeinfer/ldnull/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. + +LDA_STR:string,STLETTOGLOBALRECORD:null,TRYLDGLOBALBYNAME:null,TYPEOFDYN:null \ No newline at end of file diff --git a/test/typeinfer/ldnull/ldnull.ts b/test/typeinfer/ldnull/ldnull.ts new file mode 100644 index 0000000000..e95289fab4 --- /dev/null +++ b/test/typeinfer/ldnull/ldnull.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +let num = null; +typeof(num); \ No newline at end of file diff --git a/test/typeinfer/ldobjbyindex/BUILD.gn b/test/typeinfer/ldobjbyindex/BUILD.gn new file mode 100644 index 0000000000..44929d8df8 --- /dev/null +++ b/test/typeinfer/ldobjbyindex/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_typeinfer_test_action("ldobjbyindex") { + deps = [] +} diff --git a/test/typeinfer/ldobjbyindex/expect_output.txt b/test/typeinfer/ldobjbyindex/expect_output.txt new file mode 100644 index 0000000000..3cea0381a5 --- /dev/null +++ b/test/typeinfer/ldobjbyindex/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. + +LDA_STR:string,CREATEARRAYWITHBUFFER:array,LDOBJBYINDEX:string,TYPEOFDYN:string \ No newline at end of file diff --git a/test/typeinfer/ldobjbyindex/ldobjbyindex.ts b/test/typeinfer/ldobjbyindex/ldobjbyindex.ts new file mode 100644 index 0000000000..69db29f330 --- /dev/null +++ b/test/typeinfer/ldobjbyindex/ldobjbyindex.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +{ + let arr : string[] = ['1']; + let ans = arr[0]; + typeof(ans); +} \ No newline at end of file diff --git a/test/typeinfer/ldobjbyname_1/BUILD.gn b/test/typeinfer/ldobjbyname_1/BUILD.gn new file mode 100644 index 0000000000..091e5cc48d --- /dev/null +++ b/test/typeinfer/ldobjbyname_1/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_typeinfer_test_action("ldobjbyname_1") { + deps = [] +} diff --git a/test/typeinfer/ldobjbyname_1/expect_output.txt b/test/typeinfer/ldobjbyname_1/expect_output.txt new file mode 100644 index 0000000000..c0647d0513 --- /dev/null +++ b/test/typeinfer/ldobjbyname_1/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. + +LDA_STR:string,CREATEOBJECTWITHBUFFER:object, +LDOBJBYNAME:number,TYPEOFDYN:number,LDOBJBYNAME:string,TYPEOFDYN:string \ No newline at end of file diff --git a/test/typeinfer/ldobjbyname_1/ldobjbyname_1.ts b/test/typeinfer/ldobjbyname_1/ldobjbyname_1.ts new file mode 100644 index 0000000000..fe21d6c590 --- /dev/null +++ b/test/typeinfer/ldobjbyname_1/ldobjbyname_1.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. + */ + +{ + let obj : { + num : number, + str : string, + } = { + num : 1, + str : "hello", + } + typeof(obj.num); + typeof(obj.str); +} \ No newline at end of file diff --git a/test/typeinfer/ldundefined/BUILD.gn b/test/typeinfer/ldundefined/BUILD.gn new file mode 100644 index 0000000000..007aa325b6 --- /dev/null +++ b/test/typeinfer/ldundefined/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_typeinfer_test_action("ldundefined") { + deps = [] +} diff --git a/test/typeinfer/ldundefined/expect_output.txt b/test/typeinfer/ldundefined/expect_output.txt new file mode 100644 index 0000000000..5db811b856 --- /dev/null +++ b/test/typeinfer/ldundefined/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. + +LDA_STR:string,STLETTOGLOBALRECORD:undefined,TRYLDGLOBALBYNAME:undefined,TYPEOFDYN:undefined \ No newline at end of file diff --git a/test/typeinfer/ldundefined/ldundefined.ts b/test/typeinfer/ldundefined/ldundefined.ts new file mode 100644 index 0000000000..f5ac5f4811 --- /dev/null +++ b/test/typeinfer/ldundefined/ldundefined.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +let num = undefined; +typeof(num); \ No newline at end of file diff --git a/test/typeinfer/lessdyn/BUILD.gn b/test/typeinfer/lessdyn/BUILD.gn new file mode 100644 index 0000000000..a689d963ba --- /dev/null +++ b/test/typeinfer/lessdyn/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_typeinfer_test_action("lessdyn") { + deps = [] +} diff --git a/test/typeinfer/lessdyn/expect_output.txt b/test/typeinfer/lessdyn/expect_output.txt new file mode 100644 index 0000000000..675a8758dd --- /dev/null +++ b/test/typeinfer/lessdyn/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. + +LDA_STR:string,LESSDYN:boolean,TYPEOFDYN:boolean \ No newline at end of file diff --git a/test/typeinfer/lessdyn/lessdyn.ts b/test/typeinfer/lessdyn/lessdyn.ts new file mode 100644 index 0000000000..ce55976b1b --- /dev/null +++ b/test/typeinfer/lessdyn/lessdyn.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let num1 : number = 1; + let num2 : number = 2; + let ans = (num1 < num2); + typeof(ans); +} \ No newline at end of file diff --git a/test/typeinfer/lesseqdyn/BUILD.gn b/test/typeinfer/lesseqdyn/BUILD.gn new file mode 100644 index 0000000000..37960f2e99 --- /dev/null +++ b/test/typeinfer/lesseqdyn/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_typeinfer_test_action("lesseqdyn") { + deps = [] +} diff --git a/test/typeinfer/lesseqdyn/expect_output.txt b/test/typeinfer/lesseqdyn/expect_output.txt new file mode 100644 index 0000000000..d5e87de0e5 --- /dev/null +++ b/test/typeinfer/lesseqdyn/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. + +LDA_STR:string,LESSEQDYN:boolean,TYPEOFDYN:boolean \ No newline at end of file diff --git a/test/typeinfer/lesseqdyn/lesseqdyn.ts b/test/typeinfer/lesseqdyn/lesseqdyn.ts new file mode 100644 index 0000000000..925aefaa54 --- /dev/null +++ b/test/typeinfer/lesseqdyn/lesseqdyn.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let num1 : number = 1; + let num2 : number = 2; + let ans = (num1 <= num2); + typeof(ans); +} \ No newline at end of file diff --git a/test/typeinfer/mod2dyn/BUILD.gn b/test/typeinfer/mod2dyn/BUILD.gn new file mode 100644 index 0000000000..c8fede9e3f --- /dev/null +++ b/test/typeinfer/mod2dyn/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_typeinfer_test_action("mod2dyn") { + deps = [] +} diff --git a/test/typeinfer/mod2dyn/expect_output.txt b/test/typeinfer/mod2dyn/expect_output.txt new file mode 100644 index 0000000000..bff7821da9 --- /dev/null +++ b/test/typeinfer/mod2dyn/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. + +LDA_STR:string,MOD2DYN:number,TYPEOFDYN:number \ No newline at end of file diff --git a/test/typeinfer/mod2dyn/mod2dyn.ts b/test/typeinfer/mod2dyn/mod2dyn.ts new file mode 100644 index 0000000000..a2d44070a0 --- /dev/null +++ b/test/typeinfer/mod2dyn/mod2dyn.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let num1 : number = 1; + let num2 : number = 2; + let ans = num1 % num2; + typeof(ans); +} \ No newline at end of file diff --git a/test/typeinfer/mul2dyn/BUILD.gn b/test/typeinfer/mul2dyn/BUILD.gn new file mode 100644 index 0000000000..7d127c3bdb --- /dev/null +++ b/test/typeinfer/mul2dyn/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_typeinfer_test_action("mul2dyn") { + deps = [] +} diff --git a/test/typeinfer/mul2dyn/expect_output.txt b/test/typeinfer/mul2dyn/expect_output.txt new file mode 100644 index 0000000000..07efa7874e --- /dev/null +++ b/test/typeinfer/mul2dyn/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. + +LDA_STR:string,MUL2DYN:number,TYPEOFDYN:number \ No newline at end of file diff --git a/test/typeinfer/mul2dyn/mul2dyn.ts b/test/typeinfer/mul2dyn/mul2dyn.ts new file mode 100644 index 0000000000..2e426bf304 --- /dev/null +++ b/test/typeinfer/mul2dyn/mul2dyn.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let num1 : number = 1; + let num2 : number = 2; + let ans = num1 * num2; + typeof(ans); +} \ No newline at end of file diff --git a/test/typeinfer/newobjdynrange/BUILD.gn b/test/typeinfer/newobjdynrange/BUILD.gn new file mode 100644 index 0000000000..59a07ae9dd --- /dev/null +++ b/test/typeinfer/newobjdynrange/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_typeinfer_test_action("newobjdynrange") { + deps = [] +} diff --git a/test/typeinfer/newobjdynrange/expect_output.txt b/test/typeinfer/newobjdynrange/expect_output.txt new file mode 100644 index 0000000000..bbfacab2e8 --- /dev/null +++ b/test/typeinfer/newobjdynrange/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. + +LDA_STR:string,DEFINECLASSWITHBUFFER:class,LDA_STR:string,NEWOBJDYNRANGE:class_instance,LDOBJBYNAME:string,TYPEOFDYN:string +---- \ No newline at end of file diff --git a/test/typeinfer/newobjdynrange/newobjdynrange.ts b/test/typeinfer/newobjdynrange/newobjdynrange.ts new file mode 100644 index 0000000000..1b97f3a0c7 --- /dev/null +++ b/test/typeinfer/newobjdynrange/newobjdynrange.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. + */ + +{ + class Student { + name : string; + constructor(name:string){ + this.name = name; + } + } + let stu = new Student("xiaoming"); + let ans = stu.name + typeof(ans); +} \ No newline at end of file diff --git a/test/typeinfer/noteqdyn/BUILD.gn b/test/typeinfer/noteqdyn/BUILD.gn new file mode 100644 index 0000000000..11b4294ca0 --- /dev/null +++ b/test/typeinfer/noteqdyn/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_typeinfer_test_action("noteqdyn") { + deps = [] +} diff --git a/test/typeinfer/noteqdyn/expect_output.txt b/test/typeinfer/noteqdyn/expect_output.txt new file mode 100644 index 0000000000..231fd49504 --- /dev/null +++ b/test/typeinfer/noteqdyn/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. + +LDA_STR:string,NOTEQDYN:boolean,TYPEOFDYN:boolean \ No newline at end of file diff --git a/test/typeinfer/noteqdyn/noteqdyn.ts b/test/typeinfer/noteqdyn/noteqdyn.ts new file mode 100644 index 0000000000..50320d75ae --- /dev/null +++ b/test/typeinfer/noteqdyn/noteqdyn.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let num1 : number = 1; + let num2 : number = 2; + let ans = (num1 != num2); + typeof(ans); +} \ No newline at end of file diff --git a/test/typeinfer/stconsttoglobalrecord/BUILD.gn b/test/typeinfer/stconsttoglobalrecord/BUILD.gn new file mode 100644 index 0000000000..c474bf936d --- /dev/null +++ b/test/typeinfer/stconsttoglobalrecord/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_typeinfer_test_action("stconsttoglobalrecord") { + deps = [] +} diff --git a/test/typeinfer/stconsttoglobalrecord/expect_output.txt b/test/typeinfer/stconsttoglobalrecord/expect_output.txt new file mode 100644 index 0000000000..d4f52ab9a8 --- /dev/null +++ b/test/typeinfer/stconsttoglobalrecord/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. + +LDA_STR:string,STCONSTTOGLOBALRECORD:number, +TRYLDGLOBALBYNAME:number,TYPEOFDYN:number \ No newline at end of file diff --git a/test/typeinfer/stconsttoglobalrecord/stconsttoglobalrecord.ts b/test/typeinfer/stconsttoglobalrecord/stconsttoglobalrecord.ts new file mode 100644 index 0000000000..141f4069c3 --- /dev/null +++ b/test/typeinfer/stconsttoglobalrecord/stconsttoglobalrecord.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +const num:number = 1; +typeof(num) \ No newline at end of file diff --git a/test/typeinfer/stglobalvar/BUILD.gn b/test/typeinfer/stglobalvar/BUILD.gn new file mode 100644 index 0000000000..125525b357 --- /dev/null +++ b/test/typeinfer/stglobalvar/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_typeinfer_test_action("stglobalvar") { + deps = [] +} diff --git a/test/typeinfer/stglobalvar/expect_output.txt b/test/typeinfer/stglobalvar/expect_output.txt new file mode 100644 index 0000000000..3407b9606f --- /dev/null +++ b/test/typeinfer/stglobalvar/expect_output.txt @@ -0,0 +1,16 @@ +# 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. + +STGLOBALVAR:undefined,STGLOBALVAR:undefined, +LDA_STR:string,LDA_STR:string,STGLOBALVAR:string,LDA_STR:string, +STGLOBALVAR:string,LDGLOBALVAR:string,STGLOBALVAR:string diff --git a/test/typeinfer/stglobalvar/stglobalvar.ts b/test/typeinfer/stglobalvar/stglobalvar.ts new file mode 100644 index 0000000000..5c132f739c --- /dev/null +++ b/test/typeinfer/stglobalvar/stglobalvar.ts @@ -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. + */ + +var str:string = '1'; +str = '2'; +var ans = str; \ No newline at end of file diff --git a/test/typeinfer/stlettoglobalrecord/BUILD.gn b/test/typeinfer/stlettoglobalrecord/BUILD.gn new file mode 100644 index 0000000000..05253ac9f1 --- /dev/null +++ b/test/typeinfer/stlettoglobalrecord/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_typeinfer_test_action("stlettoglobalrecord") { + deps = [] +} diff --git a/test/typeinfer/stlettoglobalrecord/expect_output.txt b/test/typeinfer/stlettoglobalrecord/expect_output.txt new file mode 100644 index 0000000000..0505789964 --- /dev/null +++ b/test/typeinfer/stlettoglobalrecord/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. + +LDA_STR:string,LDA_STR:string,STLETTOGLOBALRECORD:string, +TRYLDGLOBALBYNAME:string,TYPEOFDYN:string \ No newline at end of file diff --git a/test/typeinfer/stlettoglobalrecord/stlettoglobalrecord.ts b/test/typeinfer/stlettoglobalrecord/stlettoglobalrecord.ts new file mode 100644 index 0000000000..b36890445b --- /dev/null +++ b/test/typeinfer/stlettoglobalrecord/stlettoglobalrecord.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +let str:string = '1'; +typeof(str); \ No newline at end of file diff --git a/test/typeinfer/sub2dyn/BUILD.gn b/test/typeinfer/sub2dyn/BUILD.gn new file mode 100644 index 0000000000..5e436a7342 --- /dev/null +++ b/test/typeinfer/sub2dyn/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_typeinfer_test_action("sub2dyn") { + deps = [] +} diff --git a/test/typeinfer/sub2dyn/expect_output.txt b/test/typeinfer/sub2dyn/expect_output.txt new file mode 100644 index 0000000000..26ade393f7 --- /dev/null +++ b/test/typeinfer/sub2dyn/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. + +LDA_STR:string,SUB2DYN:number,TYPEOFDYN:number \ No newline at end of file diff --git a/test/typeinfer/sub2dyn/sub2dyn.ts b/test/typeinfer/sub2dyn/sub2dyn.ts new file mode 100644 index 0000000000..eba7530930 --- /dev/null +++ b/test/typeinfer/sub2dyn/sub2dyn.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +{ + let num1 : number = 1; + let num2 : number = 2; + let ans = num1 - num2; + typeof(ans); +} \ No newline at end of file diff --git a/test/typeinfer/throwdyn_1/BUILD.gn b/test/typeinfer/throwdyn_1/BUILD.gn new file mode 100644 index 0000000000..8de2122dcd --- /dev/null +++ b/test/typeinfer/throwdyn_1/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_typeinfer_test_action("throwdyn_1") { + deps = [] +} diff --git a/test/typeinfer/throwdyn_1/expect_output.txt b/test/typeinfer/throwdyn_1/expect_output.txt new file mode 100644 index 0000000000..a4ab63e801 --- /dev/null +++ b/test/typeinfer/throwdyn_1/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. + +LDA_STR:string,CREATEARRAYWITHBUFFER:array,THROWDYN:array \ No newline at end of file diff --git a/test/typeinfer/throwdyn_1/throwdyn_1.ts b/test/typeinfer/throwdyn_1/throwdyn_1.ts new file mode 100644 index 0000000000..ca31919b3b --- /dev/null +++ b/test/typeinfer/throwdyn_1/throwdyn_1.ts @@ -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. + */ + +{ + let arr1 :number[] = [1, 2, 3]; + throw arr1; +} \ No newline at end of file diff --git a/test/typeinfer/throwdyn_2/BUILD.gn b/test/typeinfer/throwdyn_2/BUILD.gn new file mode 100644 index 0000000000..928060c2ef --- /dev/null +++ b/test/typeinfer/throwdyn_2/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_typeinfer_test_action("throwdyn_2") { + deps = [] +} diff --git a/test/typeinfer/throwdyn_2/expect_output.txt b/test/typeinfer/throwdyn_2/expect_output.txt new file mode 100644 index 0000000000..0f40992fe1 --- /dev/null +++ b/test/typeinfer/throwdyn_2/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. + +LDA_STR:string,CREATEOBJECTWITHBUFFER:object,THROWDYN:object \ No newline at end of file diff --git a/test/typeinfer/throwdyn_2/throwdyn_2.ts b/test/typeinfer/throwdyn_2/throwdyn_2.ts new file mode 100644 index 0000000000..1b4d84cc54 --- /dev/null +++ b/test/typeinfer/throwdyn_2/throwdyn_2.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +{ + let test : { + age : number, + } = { + age : 10, + } + throw test; +} \ No newline at end of file diff --git a/test/typeinfer/tryldglobalbyname/BUILD.gn b/test/typeinfer/tryldglobalbyname/BUILD.gn new file mode 100644 index 0000000000..4710b6ddda --- /dev/null +++ b/test/typeinfer/tryldglobalbyname/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_typeinfer_test_action("tryldglobalbyname") { + deps = [] +} diff --git a/test/typeinfer/tryldglobalbyname/expect_output.txt b/test/typeinfer/tryldglobalbyname/expect_output.txt new file mode 100644 index 0000000000..a03a4eed28 --- /dev/null +++ b/test/typeinfer/tryldglobalbyname/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. + +LDA_STR:string,STLETTOGLOBALRECORD:string,TRYLDGLOBALBYNAME:string, +STGLOBALVAR:string,LDGLOBALVAR:string,TYPEOFDYN:string \ No newline at end of file diff --git a/test/typeinfer/tryldglobalbyname/tryldglobalbyname.ts b/test/typeinfer/tryldglobalbyname/tryldglobalbyname.ts new file mode 100644 index 0000000000..2a0605b80c --- /dev/null +++ b/test/typeinfer/tryldglobalbyname/tryldglobalbyname.ts @@ -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. + */ + +let str : string = 'str'; +var ans = str; +typeof(ans); \ No newline at end of file diff --git a/test/typeinfer/trystglobalbyname/BUILD.gn b/test/typeinfer/trystglobalbyname/BUILD.gn new file mode 100644 index 0000000000..2506686803 --- /dev/null +++ b/test/typeinfer/trystglobalbyname/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_typeinfer_test_action("trystglobalbyname") { + deps = [] +} diff --git a/test/typeinfer/trystglobalbyname/expect_output.txt b/test/typeinfer/trystglobalbyname/expect_output.txt new file mode 100644 index 0000000000..6a3da7c02b --- /dev/null +++ b/test/typeinfer/trystglobalbyname/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. + +LDA_STR:string,STLETTOGLOBALRECORD:number,TRYSTGLOBALBYNAME:number, +TRYLDGLOBALBYNAME:number,TYPEOFDYN:number \ No newline at end of file diff --git a/test/typeinfer/trystglobalbyname/trystglobalbyname.ts b/test/typeinfer/trystglobalbyname/trystglobalbyname.ts new file mode 100644 index 0000000000..71893fdcf1 --- /dev/null +++ b/test/typeinfer/trystglobalbyname/trystglobalbyname.ts @@ -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. + */ + +let num : number = 1; +num = 2; +typeof(num); \ No newline at end of file diff --git a/test/typeinfer/typeof/BUILD.gn b/test/typeinfer/typeof/BUILD.gn new file mode 100644 index 0000000000..52a3cbf684 --- /dev/null +++ b/test/typeinfer/typeof/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_typeinfer_test_action("typeof") { + deps = [] +} diff --git a/test/typeinfer/typeof/expect_output.txt b/test/typeinfer/typeof/expect_output.txt new file mode 100644 index 0000000000..e6b3b70da5 --- /dev/null +++ b/test/typeinfer/typeof/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. + +LDA_STR:string,CREATEEMPTYARRAY:array,TYPEOFDYN:array \ No newline at end of file diff --git a/test/typeinfer/typeof/typeof.ts b/test/typeinfer/typeof/typeof.ts new file mode 100644 index 0000000000..d831a6bb77 --- /dev/null +++ b/test/typeinfer/typeof/typeof.ts @@ -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. + */ + +{ + let arr1:string[]= []; + typeof(arr1); +} \ No newline at end of file