Browse Source

Fixed a bug with strings, which was happening if js file ends with comment

rsredsq 10 years ago
parent
commit
27cfcb924c

+ 1 - 3
Source/Atomic/IO/File.cpp

@@ -535,11 +535,9 @@ void File::ReadText(String& text)
     if (!size_)
     if (!size_)
         return;
         return;
 
 
-    text.Resize(size_ + 1);
+    text.Resize(size_);
 
 
     Read((void*)text.CString(), size_);
     Read((void*)text.CString(), size_);
-
-    text[size_] = '\0';
 }
 }
 
 
 // ATOMIC BEGIN
 // ATOMIC BEGIN

+ 3 - 1
Source/AtomicJS/Javascript/JSRequire.cpp

@@ -133,7 +133,9 @@ namespace Atomic
             vm->SetLastModuleSearchFile(jsfile->GetFullPath());
             vm->SetLastModuleSearchFile(jsfile->GetFullPath());
             String source;
             String source;
             jsfile->ReadText(source);
             jsfile->ReadText(source);
-            source.At(source.Length() - 1) = '\n';
+            //Appending a new line at the end of a script
+            source.AppendUTF8(0x0D);
+            source.AppendUTF8(0x0A);
             duk_push_string(ctx, source.CString());
             duk_push_string(ctx, source.CString());
             return 1;
             return 1;
         }
         }

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

@@ -252,6 +252,9 @@ int JSVM::GetRealLineNumber(const String& fileName, const int lineNumber) {
     String path = fileName;
     String path = fileName;
     if (!path.EndsWith(".js.map"))
     if (!path.EndsWith(".js.map"))
         path += ".js.map";
         path += ".js.map";
+    if (path.EndsWith(".js")) {
+        return realLineNumber;
+    }
     SharedPtr<File> mapFile(GetSubsystem<ResourceCache>()->GetFile(path));
     SharedPtr<File> mapFile(GetSubsystem<ResourceCache>()->GetFile(path));
     //if there's no source map file, maybe you use a pure js, so give an error, or maybe forgot to generate source-maps :(
     //if there's no source map file, maybe you use a pure js, so give an error, or maybe forgot to generate source-maps :(
     if (mapFile.Null()) 
     if (mapFile.Null()) 
@@ -307,6 +310,9 @@ bool JSVM::ExecuteScript(const String& scriptPath)
     String source;
     String source;
 
 
     file->ReadText(source);
     file->ReadText(source);
+    //Appending a new line at the end of a script
+    source.AppendUTF8(0x0D);
+    source.AppendUTF8(0x0A);
 
 
     duk_push_string(ctx_, file->GetFullPath().CString());
     duk_push_string(ctx_, file->GetFullPath().CString());
     if (duk_eval_raw(ctx_, source.CString(), 0,
     if (duk_eval_raw(ctx_, source.CString(), 0,
@@ -332,6 +338,9 @@ bool JSVM::ExecuteFile(File *file)
     String source;
     String source;
 
 
     file->ReadText(source);
     file->ReadText(source);
+    //Appending a new line at the end of a script
+    source.AppendUTF8(0x0D);
+    source.AppendUTF8(0x0A);
 
 
     duk_push_string(ctx_, file->GetFullPath().CString());
     duk_push_string(ctx_, file->GetFullPath().CString());
     if (duk_eval_raw(ctx_, source.CString(), 0,
     if (duk_eval_raw(ctx_, source.CString(), 0,