Skip to content

Commit b8325f0

Browse files
committed
Make script_origin to be like file:///...
1 parent 6fc5d3f commit b8325f0

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Source/V8/Private/JavascriptContext_Private.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ using namespace v8;
3232

3333
static const int kContextEmbedderDataIndex = 1;
3434
static 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

3654
static 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

Comments
 (0)