Browse Source

Cleanup for JS module loading

Josh Engebretson 10 years ago
parent
commit
ed7ba52a60
1 changed files with 12 additions and 14 deletions
  1. 12 14
      Source/AtomicJS/Javascript/JSRequire.cpp

+ 12 - 14
Source/AtomicJS/Javascript/JSRequire.cpp

@@ -60,9 +60,16 @@ namespace Atomic
  
         }
 
-        SharedPtr<File> jsfile(cache->GetFile(path, false));
-
-        if (!jsfile)
+        if (cache->Exists(path))
+        {
+            SharedPtr<File> jsfile(cache->GetFile(path, false));
+            vm->SetLastModuleSearchFile(jsfile->GetFullPath());
+            String source;
+            jsfile->ReadText(source);
+            duk_push_string(ctx, source.CString());
+            return 1;
+        }
+        else
         {
             // we're not a JS file, so check if we're a native module
             const Vector<String>& resourceDirs = cache->GetResourceDirs();
@@ -95,19 +102,10 @@ namespace Atomic
                 }
             }
 
-            duk_push_sprintf(ctx, "Failed loading module: %s", path.CString());
-            duk_throw(ctx);
-
-        }
-        else
-        {
-            vm->SetLastModuleSearchFile(jsfile->GetFullPath());
-            String source;
-            jsfile->ReadText(source);
-            duk_push_string(ctx, source.CString());
         }
 
-        return 1;
+        duk_push_sprintf(ctx, "Failed loading module: %s", path.CString());
+        duk_throw(ctx);
 
     }