Browse Source

Source Maps are now works for editor

rsredsq 10 years ago
parent
commit
1c0fca1c81

+ 1 - 1
Script/AtomicEditor/.gitignore

@@ -1 +1 @@
-*.js
+out/*

+ 3 - 1
Script/AtomicEditor/tsconfig.json

@@ -5,7 +5,9 @@
         "declaration": false,
         "declaration": false,
         "noImplicitAny": false,
         "noImplicitAny": false,
         "removeComments": true,
         "removeComments": true,
-        "noLib": false
+        "noLib": false,
+        "outDir": "out/",
+        "sourceMap": true
     },
     },
     "filesGlob": [
     "filesGlob": [
         "./**/*.ts"
         "./**/*.ts"

File diff suppressed because it is too large
+ 8 - 0
Script/AtomicEditor/utils/SourceMapHelper.js


+ 6 - 5
Source/AtomicEditor/Application/AEEditorApp.cpp

@@ -47,7 +47,7 @@ void AEEditorApp::Start()
 
 
     context_->RegisterSubsystem(new EditorMode(context_));
     context_->RegisterSubsystem(new EditorMode(context_));
 
 
-    vm_->SetModuleSearchPaths("AtomicEditor");
+    vm_->SetModuleSearchPaths("AtomicEditor/out");
 
 
     // Do not create bone structure by default when in the editor
     // Do not create bone structure by default when in the editor
     // this can be toggled temporarily, for example to setup an animation preview
     // this can be toggled temporarily, for example to setup an animation preview
@@ -67,7 +67,7 @@ void AEEditorApp::Start()
     jsapi_init_toolcore(vm_);
     jsapi_init_toolcore(vm_);
     jsapi_init_editor(vm_);
     jsapi_init_editor(vm_);
 
 
-    SharedPtr<File> file (GetSubsystem<ResourceCache>()->GetFile("AtomicEditor/main.js"));
+    SharedPtr<File> file (GetSubsystem<ResourceCache>()->GetFile("AtomicEditor/out/main.js"));
 
 
     if (file.Null())
     if (file.Null())
     {
     {
@@ -153,14 +153,15 @@ void AEEditorApp::HandleExitRequested(StringHash eventType, VariantMap& eventDat
 void AEEditorApp::HandleJSError(StringHash eventType, VariantMap& eventData)
 void AEEditorApp::HandleJSError(StringHash eventType, VariantMap& eventData)
 {
 {
     using namespace JSError;
     using namespace JSError;
+    int errLineNumber = vm_->GetRealLineNumber(eventData);
     //String errName = eventData[P_ERRORNAME].GetString();
     //String errName = eventData[P_ERRORNAME].GetString();
     String errMessage = eventData[P_ERRORMESSAGE].GetString();
     String errMessage = eventData[P_ERRORMESSAGE].GetString();
     String errFilename = eventData[P_ERRORFILENAME].GetString();
     String errFilename = eventData[P_ERRORFILENAME].GetString();
     //String errStack = eventData[P_ERRORSTACK].GetString();
     //String errStack = eventData[P_ERRORSTACK].GetString();
-    int errLineNumber = eventData[P_ERRORLINENUMBER].GetInt();
+    //int errLineNumber = eventData[P_ERRORLINENUMBER].GetInt();
+
+    String errorString = ToString("%s - %s - Line: %i", errFilename.CString(), errMessage.CString(), errLineNumber);
 
 
-    String errorString = ToString("%s - %s - Line: %i",
-                                  errFilename.CString(), errMessage.CString(), errLineNumber);
 
 
     ErrorExit(errorString);
     ErrorExit(errorString);
 
 

+ 27 - 0
Source/AtomicJS/Javascript/JSVM.cpp

@@ -247,6 +247,33 @@ void JSVM::SendJSErrorEvent(const String& filename)
 
 
 }
 }
 
 
+int JSVM::GetRealLineNumber(VariantMap& eventData) {
+
+    SharedPtr<File> file(GetSubsystem<ResourceCache>()->GetFile("AtomicEditor/utils/SourceMapHelper.js"));
+
+    String source;
+
+    file->ReadText(source);
+
+    duk_push_string(ctx_, source.CString());
+    duk_peval(ctx_);
+    duk_pop(ctx_);
+    String fileName = eventData[JSError::P_ERRORFILENAME].GetString();
+    String map;
+    SharedPtr<File> mapFile(GetSubsystem<ResourceCache>()->GetFile("AtomicEditor/out/" + fileName + ".js.map"));
+    mapFile->ReadText(map);
+    int lineNumber = eventData[JSError::P_ERRORLINENUMBER].GetInt();
+    duk_push_global_object(ctx_);
+    duk_get_prop_string(ctx_, -1 /*index*/, "getSourceLine");
+    duk_push_string(ctx_, map.CString());
+    duk_push_int(ctx_, lineNumber);
+    duk_pcall(ctx_, 2 /*nargs*/);
+    int realLineNumber = duk_to_int(ctx_, -1);
+    duk_pop(ctx_);
+
+    return realLineNumber;
+}
+
 bool JSVM::ExecuteScript(const String& scriptPath)
 bool JSVM::ExecuteScript(const String& scriptPath)
 {
 {
     String path = scriptPath;
     String path = scriptPath;

+ 2 - 0
Source/AtomicJS/Javascript/JSVM.h

@@ -162,6 +162,8 @@ public:
 
 
     void SendJSErrorEvent(const String& filename = String::EMPTY);
     void SendJSErrorEvent(const String& filename = String::EMPTY);
 
 
+    int GetRealLineNumber(VariantMap& eventData);
+
 private:
 private:
 
 
     void SubscribeToEvents();
     void SubscribeToEvents();

Some files were not shown because too many files changed in this diff