From 34acbc9f0aaeea7d7def469eb37a174f983cb9ff Mon Sep 17 00:00:00 2001 From: hecunmao Date: Fri, 7 Feb 2025 14:03:02 +0800 Subject: [PATCH] Cherry-Pick 10577 to 5.0.2 CreateRealm Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IBKMIE Signed-off-by: hecunmao Change-Id: Idc0ddf5d64a448496bf91dde55b5e2b9b3fb1300 --- ecmascript/builtins/builtins.cpp | 2 +- test/aottest/BUILD.gn | 1 + test/aottest/realm/BUILD.gn | 18 +++++++++++++++ test/aottest/realm/expect_output.txt | 14 ++++++++++++ test/aottest/realm/realm.ts | 30 +++++++++++++++++++++++++ test/moduletest/BUILD.gn | 3 +++ test/moduletest/realm/BUILD.gn | 18 +++++++++++++++ test/moduletest/realm/expect_output.txt | 14 ++++++++++++ test/moduletest/realm/realm.js | 29 ++++++++++++++++++++++++ 9 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 test/aottest/realm/BUILD.gn create mode 100644 test/aottest/realm/expect_output.txt create mode 100644 test/aottest/realm/realm.ts create mode 100644 test/moduletest/realm/BUILD.gn create mode 100644 test/moduletest/realm/expect_output.txt create mode 100644 test/moduletest/realm/realm.js diff --git a/ecmascript/builtins/builtins.cpp b/ecmascript/builtins/builtins.cpp index 52520c0268..805ab89077 100644 --- a/ecmascript/builtins/builtins.cpp +++ b/ecmascript/builtins/builtins.cpp @@ -395,7 +395,7 @@ void Builtins::Initialize(const JSHandle &env, JSThread *thread, bool thread_->ResetGuardians(); thread->CheckSafepointIfSuspended(); - if (vm_->GetJSOptions().IsEnableLoweringBuiltin()) { + if (vm_->GetJSOptions().IsEnableLoweringBuiltin() && !isRealm) { if (!lazyInit) { thread_->InitializeBuiltinObject(); } diff --git a/test/aottest/BUILD.gn b/test/aottest/BUILD.gn index b1e5bd2369..8f5cf09577 100644 --- a/test/aottest/BUILD.gn +++ b/test/aottest/BUILD.gn @@ -261,6 +261,7 @@ group("ark_aot_ts_test") { "privateproperty", "privateproperty_js", "resumegenerator", + "realm", "rodata", "setobjectwithproto", "set", diff --git a/test/aottest/realm/BUILD.gn b/test/aottest/realm/BUILD.gn new file mode 100644 index 0000000000..54072ac453 --- /dev/null +++ b/test/aottest/realm/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2024 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("//arkcompiler/ets_runtime/test/test_helper.gni") + +host_aot_test_action("realm") { + deps = [] +} diff --git a/test/aottest/realm/expect_output.txt b/test/aottest/realm/expect_output.txt new file mode 100644 index 0000000000..e2726c6e1d --- /dev/null +++ b/test/aottest/realm/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2024 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. + +---------------test createRealm suc!---------------- \ No newline at end of file diff --git a/test/aottest/realm/realm.ts b/test/aottest/realm/realm.ts new file mode 100644 index 0000000000..2583ba1225 --- /dev/null +++ b/test/aottest/realm/realm.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 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. + */ + +/* + * @tc.name:realm + * @tc.desc:test realm + * @tc.type: FUNC + * @tc.require: issueIBAJYP + */ +declare function print(arg:any):void; + +{ + let obj = globalThis["Object"]; + globalThis["Object"] = undefined; + createRealm(); + globalThis["Object"] = obj; + print("---------------test createRealm suc!----------------") +} \ No newline at end of file diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn index 76a8f9e277..7ba306a712 100644 --- a/test/moduletest/BUILD.gn +++ b/test/moduletest/BUILD.gn @@ -125,6 +125,7 @@ group("ark_js_moduletest") { "propertydetector", "protobuf", "proxy", + "realm", "regressproxy", "rangeerror", "regexpcallthrow", @@ -344,6 +345,7 @@ group("ark_asm_test") { "promise", "propertydetector", "proxy", + "realm", "rangeerror", "regexpcallthrow", "regexpflagd", @@ -527,6 +529,7 @@ group("ark_asm_single_step_test") { "promise", "propertydetector", "proxy", + "realm", "rangeerror", "regexpcallthrow", "regexpflagd", diff --git a/test/moduletest/realm/BUILD.gn b/test/moduletest/realm/BUILD.gn new file mode 100644 index 0000000000..538cadfaf8 --- /dev/null +++ b/test/moduletest/realm/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2024 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("//arkcompiler/ets_runtime/test/test_helper.gni") + +host_moduletest_action("realm") { + deps = [] +} diff --git a/test/moduletest/realm/expect_output.txt b/test/moduletest/realm/expect_output.txt new file mode 100644 index 0000000000..e2726c6e1d --- /dev/null +++ b/test/moduletest/realm/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2024 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. + +---------------test createRealm suc!---------------- \ No newline at end of file diff --git a/test/moduletest/realm/realm.js b/test/moduletest/realm/realm.js new file mode 100644 index 0000000000..57aff432f1 --- /dev/null +++ b/test/moduletest/realm/realm.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 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. + */ + +/* + * @tc.name:realm + * @tc.desc:test realm + * @tc.type: FUNC + * @tc.require: issueIBAJYP + */ + +{ + let obj = globalThis["Object"]; + globalThis["Object"] = undefined; + createRealm(); + globalThis["Object"] = obj; + print("---------------test createRealm suc!----------------") +} \ No newline at end of file -- Gitee