From 63fcfafd32df2269dd672f316d76f00690ca5fb7 Mon Sep 17 00:00:00 2001 From: etkmao Date: Thu, 21 Sep 2023 10:42:41 +0800 Subject: [PATCH] fix(core): fix global strip when ld in app --- core/src/scope.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/core/src/scope.cc b/core/src/scope.cc index 0aec2e92d73..2849be9b03d 100644 --- a/core/src/scope.cc +++ b/core/src/scope.cc @@ -54,13 +54,16 @@ Scope::Scope(Engine* engine, std::string name, std::unique_ptr map) : engine_(engine), context_(nullptr), name_(std::move(name)), map_(std::move(map)) { - REGISTER_MODULE(ContextifyModule, RunInThisContext) - REGISTER_MODULE(ContextifyModule, LoadUntrustedContent) - REGISTER_MODULE(TimerModule, SetTimeout) - REGISTER_MODULE(TimerModule, ClearTimeout) - REGISTER_MODULE(TimerModule, SetInterval) - REGISTER_MODULE(TimerModule, ClearInterval) - REGISTER_MODULE(ConsoleModule, Log) + static std::once_flag flag; + std::call_once(flag, [] { + REGISTER_MODULE(ContextifyModule, RunInThisContext) + REGISTER_MODULE(ContextifyModule, LoadUntrustedContent) + REGISTER_MODULE(TimerModule, SetTimeout) + REGISTER_MODULE(TimerModule, ClearTimeout) + REGISTER_MODULE(TimerModule, SetInterval) + REGISTER_MODULE(TimerModule, ClearInterval) + REGISTER_MODULE(ConsoleModule, Log) + }); } Scope::~Scope() {