Browse Source

Require out/main.js instead of raw evaling it

rsredsq 10 years ago
parent
commit
37f8cfa2ff
2 changed files with 16 additions and 10 deletions
  1. 12 2
      Script/AtomicEditor/main.ts
  2. 4 8
      Source/AtomicJS/Javascript/JSVM.cpp

+ 12 - 2
Script/AtomicEditor/main.ts

@@ -3,6 +3,16 @@
 /// <reference path="../TypeScript/Editor.d.ts" />
 /// <reference path="../TypeScript/Editor.d.ts" />
 /// <reference path="../TypeScript/AtomicWork.d.ts" />
 /// <reference path="../TypeScript/AtomicWork.d.ts" />
 
 
-import __Editor = require("./editor/Editor");
+import Editor = require("editor/Editor");
 
 
-var TheEditor = new __Editor();
+class Main {
+    static Editor:Editor;
+
+    static main() {
+        Main.Editor = new Editor();
+    }
+}
+
+Main.main();
+
+export = Main;

+ 4 - 8
Source/AtomicJS/Javascript/JSVM.cpp

@@ -335,16 +335,12 @@ bool JSVM::ExecuteFile(File *file)
 
 
     String source;
     String source;
 
 
-    file->ReadText(source);
-    source.Append('\n');
+    duk_get_global_string(ctx_, "require");
+    duk_push_string(ctx_, "main");
 
 
-    duk_push_string(ctx_, file->GetFullPath().CString());
-    if (duk_eval_raw(ctx_, source.CString(), 0,
-                     DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN) != 0)
+    if (duk_pcall(ctx_, 1) != 0)
     {
     {
-        SendJSErrorEvent(file->GetFullPath());
-
-        duk_pop(ctx_);
+        SendJSErrorEvent();
         return false;
         return false;
     }
     }