@@ -32,6 +32,24 @@ using namespace v8;
3232
3333static const int kContextEmbedderDataIndex = 1 ;
3434static const int32 MagicNumber = 0x2852abd3 ;
35+ static const FString URL_FilePrefix (TEXT(" file:///" ));
36+
37+ static FString LocalPathToURL (FString Path)
38+ {
39+ return URL_FilePrefix + Path.Replace (TEXT (" \\ " ), TEXT (" /" )).Replace (TEXT (" " ), TEXT (" %20" ));
40+ }
41+
42+ static FString URLToLocalPath (FString URL)
43+ {
44+ if (URL.StartsWith (*URL_FilePrefix))
45+ {
46+ URL = URL.Mid (URL_FilePrefix.Len ()).Replace (TEXT (" %20" ), TEXT (" " ));
47+ }
48+ #if PLATFORM_WINDOWS
49+ URL = URL.Replace (TEXT (" \\ " ), TEXT (" /" ));
50+ #endif
51+ return URL;
52+ }
3553
3654static TArray<FString> StringArrayFromV8 (Handle<Value> InArray)
3755{
@@ -1465,9 +1483,7 @@ class FJavascriptContextImplementation : public FJavascriptContext
14651483 };
14661484
14671485 auto current_script_path = FPaths::GetPath (StringFromV8 (StackTrace::CurrentStackTrace (isolate, 1 , StackTrace::kScriptName )->GetFrame (0 )->GetScriptName ()));
1468- #if PLATFORM_WINDOWS
1469- current_script_path = current_script_path.Replace (TEXT (" \\ " ), TEXT (" /" ));
1470- #endif
1486+ current_script_path = URLToLocalPath (current_script_path);
14711487
14721488 if (!(required_module[0 ] == ' .' && inner2 (current_script_path)))
14731489 {
@@ -1727,8 +1743,7 @@ class FJavascriptContextImplementation : public FJavascriptContext
17271743 }
17281744#endif
17291745 auto source = V8_String (isolate (), Script);
1730- auto path = V8_String (isolate (), Path);
1731- // auto path = V8_String(isolate(), FString(TEXT("file:///"))+Path.Replace(TEXT("\\"),TEXT("/")).Replace(TEXT(" "), TEXT("%20")));
1746+ auto path = V8_String (isolate (), LocalPathToURL (Path));
17321747 ScriptOrigin origin (path, Integer::New (isolate (), -line_offset));
17331748 auto script = Script::Compile (source, &origin);
17341749 if (script.IsEmpty ())
0 commit comments