Skip to content

Commit 8440c16

Browse files
author
Mihail Slavchev
committed
check always for cached module
1 parent 63affe0 commit 8440c16

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

src/jni/Module.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,9 @@ void Module::RequireCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
143143
// cache the required modules by full path, not name only, since there might be some collisions with relative paths and names
144144
string modulePath = ArgConverter::jstringToString((jstring) jsModulePath);
145145

146-
auto it = s_loadedModules.find(modulePath);
147-
148-
Local<Object> moduleObj;
149-
150146
auto isData = false;
151147

152-
if (it == s_loadedModules.end())
153-
{
154-
moduleObj = Load(modulePath, isData);
155-
}
156-
else
157-
{
158-
moduleObj = Local<Object>::New(isolate, *it->second);
159-
}
148+
auto moduleObj = Load(modulePath, isData);
160149

161150
if (isData)
162151
{
@@ -202,20 +191,30 @@ Local<Object> Module::Load(const string& path, bool& isData)
202191

203192
auto isolate = Isolate::GetCurrent();
204193

205-
if (Util::EndsWith(path, ".js") || Util::EndsWith(path, ".so"))
206-
{
207-
isData = false;
208-
result = LoadModule(isolate, path);
209-
}
210-
else if (Util::EndsWith(path, ".json"))
194+
auto it = s_loadedModules.find(path);
195+
196+
if (it == s_loadedModules.end())
211197
{
212-
isData = true;
213-
result = LoadData(isolate, path);
198+
if (Util::EndsWith(path, ".js") || Util::EndsWith(path, ".so"))
199+
{
200+
isData = false;
201+
result = LoadModule(isolate, path);
202+
}
203+
else if (Util::EndsWith(path, ".json"))
204+
{
205+
isData = true;
206+
result = LoadData(isolate, path);
207+
}
208+
else
209+
{
210+
string errMsg = "Unsupported file extension: " + path;
211+
throw NativeScriptException(errMsg);
212+
}
214213
}
215214
else
216215
{
217-
string errMsg = "Unsupported file extension: " + path;
218-
throw NativeScriptException(errMsg);
216+
isData = Util::EndsWith(path, ".json");
217+
result = Local<Object>::New(isolate, *it->second);
219218
}
220219

221220
return result;

0 commit comments

Comments
 (0)