Skip to content

Commit 9197143

Browse files
author
Mihail Slavchev
committed
make global object read only
1 parent 2d58799 commit 9197143

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/jni/com_tns_Platform.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ void PrepareV8Runtime(Isolate *isolate, JEnv& env, jstring filesPath, jstring pa
113113

114114
auto globalTemplate = ObjectTemplate::New();
115115

116+
const auto readOnlyFlags = static_cast<PropertyAttribute>(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
117+
116118
globalTemplate->Set(ConvertToV8String("__startNDKProfiler"), FunctionTemplate::New(isolate, Profiler::StartNDKProfilerCallback));
117119
globalTemplate->Set(ConvertToV8String("__stopNDKProfiler"), FunctionTemplate::New(isolate, Profiler::StopNDKProfilerCallback));
118120
globalTemplate->Set(ConvertToV8String("__startCPUProfiler"), FunctionTemplate::New(isolate, Profiler::StartCPUProfilerCallback));
@@ -143,10 +145,10 @@ void PrepareV8Runtime(Isolate *isolate, JEnv& env, jstring filesPath, jstring pa
143145
auto appTemplate = ObjectTemplate::New();
144146
appTemplate->Set(ConvertToV8String("init"), FunctionTemplate::New(isolate, AppInitCallback));
145147
auto appInstance = appTemplate->NewInstance();
146-
global->Set(ConvertToV8String("app"), appInstance);
148+
global->ForceSet(ConvertToV8String("app"), appInstance, readOnlyFlags);
147149

148-
global->Set(ConvertToV8String("global"), global);
149-
global->Set(ConvertToV8String("__global"), global);
150+
global->ForceSet(ConvertToV8String("global"), global, readOnlyFlags);
151+
global->ForceSet(ConvertToV8String("__global"), global, readOnlyFlags);
150152

151153
ArgConverter::Init(g_jvm);
152154

0 commit comments

Comments
 (0)