diff --git a/src/jni/NativeScriptRuntime.cpp b/src/jni/NativeScriptRuntime.cpp index 1b31e78e5..909ff75d0 100644 --- a/src/jni/NativeScriptRuntime.cpp +++ b/src/jni/NativeScriptRuntime.cpp @@ -698,6 +698,21 @@ void NativeScriptRuntime::CreateGlobalCastFunctions(const Handle castFunctions.CreateGlobalCastFunctions(globalTemplate); } +void NativeScriptRuntime::RequireClearCacheCallback(const v8::FunctionCallbackInfo &args) +{ + SET_PROFILER_FRAME(); + ASSERT_MESSAGE(args.Length() == 1, "__clearRequireCachedItem should be called with one parameters"); + ASSERT_MESSAGE(!args[0]->IsUndefined() && !args[0]->IsNull(), "require called with undefined moduleName parameter"); + ASSERT_MESSAGE(args[0]->IsString(), "__clearRequireCachedItem should be called with string parameter"); + + string modulePath = ConvertToString(args[0].As()); + JEnv env; + + auto it = loadedModules.find(modulePath); + if (it != loadedModules.end()) { + loadedModules.erase(modulePath); + } +} void NativeScriptRuntime::RequireCallback(const v8::FunctionCallbackInfo& args) { @@ -739,6 +754,7 @@ void NativeScriptRuntime::RequireCallback(const v8::FunctionCallbackInfo moduleObj; @@ -746,6 +762,7 @@ void NativeScriptRuntime::RequireCallback(const v8::FunctionCallbackInfo exportObj = Object::New(isolate); auto tmpExportObj = new Persistent(isolate, exportObj.As()); loadedModules.insert(make_pair(modulePath, tmpExportObj)); diff --git a/src/jni/NativeScriptRuntime.h b/src/jni/NativeScriptRuntime.h index a115d8a9a..dcbd43c8a 100644 --- a/src/jni/NativeScriptRuntime.h +++ b/src/jni/NativeScriptRuntime.h @@ -69,6 +69,8 @@ namespace tns static void RequireCallback(const v8::FunctionCallbackInfo& args); + static void RequireClearCacheCallback(const v8::FunctionCallbackInfo &args); + static void CreateGlobalCastFunctions(const v8::Handle& globalTemplate); static std::vector GetTypeMetadata(const std::string& name, int index); diff --git a/src/jni/com_tns_Platform.cpp b/src/jni/com_tns_Platform.cpp index ec6c358d9..8f9149e09 100644 --- a/src/jni/com_tns_Platform.cpp +++ b/src/jni/com_tns_Platform.cpp @@ -122,6 +122,7 @@ void PrepareV8Runtime(Isolate *isolate, JEnv& env, jstring filesPath, jstring pa globalTemplate->Set(ConvertToV8String("__disableVerboseLogging"), FunctionTemplate::New(isolate, NativeScriptRuntime::DisableVerboseLoggingMethodCallback)); globalTemplate->Set(ConvertToV8String("__exit"), FunctionTemplate::New(isolate, NativeScriptRuntime::ExitMethodCallback)); globalTemplate->Set(ConvertToV8String("require"), FunctionTemplate::New(isolate, NativeScriptRuntime::RequireCallback)); + globalTemplate->Set(ConvertToV8String("__clearRequireCachedItem"), FunctionTemplate::New(isolate, NativeScriptRuntime::RequireClearCacheCallback)); globalTemplate->Set(ConvertToV8String("WeakRef"), FunctionTemplate::New(isolate, WeakRef::ConstructorCallback)); SimpleProfiler::Init(isolate, globalTemplate);