Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/jni/NativeScriptRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,21 @@ void NativeScriptRuntime::CreateGlobalCastFunctions(const Handle<ObjectTemplate>
castFunctions.CreateGlobalCastFunctions(globalTemplate);
}

void NativeScriptRuntime::RequireClearCacheCallback(const v8::FunctionCallbackInfo<v8::Value> &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<String>());
JEnv env;

auto it = loadedModules.find(modulePath);
if (it != loadedModules.end()) {
loadedModules.erase(modulePath);
}
}

void NativeScriptRuntime::RequireCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
Expand Down Expand Up @@ -739,13 +754,15 @@ void NativeScriptRuntime::RequireCallback(const v8::FunctionCallbackInfo<v8::Val
return;
}


auto it = loadedModules.find(modulePath);

Handle<Object> moduleObj;
bool hasError = false;

if (it == loadedModules.end())
{

Local<Value> exportObj = Object::New(isolate);
auto tmpExportObj = new Persistent<Object>(isolate, exportObj.As<Object>());
loadedModules.insert(make_pair(modulePath, tmpExportObj));
Expand Down
2 changes: 2 additions & 0 deletions src/jni/NativeScriptRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace tns

static void RequireCallback(const v8::FunctionCallbackInfo<v8::Value>& args);

static void RequireClearCacheCallback(const v8::FunctionCallbackInfo<v8::Value> &args);

static void CreateGlobalCastFunctions(const v8::Handle<v8::ObjectTemplate>& globalTemplate);

static std::vector<std::string> GetTypeMetadata(const std::string& name, int index);
Expand Down
1 change: 1 addition & 0 deletions src/jni/com_tns_Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down