From 7fae0f86c06ff6e2393826ad4d1fdd92c7102a2b Mon Sep 17 00:00:00 2001 From: professorK Date: Sun, 19 Nov 2023 22:10:04 -0500 Subject: [PATCH 01/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f394755e..19060875 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Unreal.js-core +# Unreal.js-core kesselman dev fork - core component of [Unreal.js](https://github.com/ncsoft/Unreal.js) - Please visit [project repo](https://github.com/ncsoft/Unreal.js). From 3274c665ec19155d0317b454efd19b0d97ca3277 Mon Sep 17 00:00:00 2001 From: professorK Date: Wed, 22 Nov 2023 23:30:08 -0500 Subject: [PATCH 02/10] first checkback of changes for EC6 Loads simple MJS. import needs work --- .../V8/Private/JavaScriptModuleCompiler.cpp | 195 ++++++++++++++++++ Source/V8/Private/JavaScriptModuleCompiler.h | 39 ++++ .../V8/Private/JavascriptContext_Private.cpp | 63 +++++- UnrealJS.uplugin | 6 +- 4 files changed, 298 insertions(+), 5 deletions(-) create mode 100644 Source/V8/Private/JavaScriptModuleCompiler.cpp create mode 100644 Source/V8/Private/JavaScriptModuleCompiler.h diff --git a/Source/V8/Private/JavaScriptModuleCompiler.cpp b/Source/V8/Private/JavaScriptModuleCompiler.cpp new file mode 100644 index 00000000..db3f7585 --- /dev/null +++ b/Source/V8/Private/JavaScriptModuleCompiler.cpp @@ -0,0 +1,195 @@ +#include "JavaScriptModuleCompiler.h" + +namespace module_compiler +{ + /***************************************************************************** + * char* readFile + * Reads file contents to a null-terminated string. + *****************************************************************************/ + char* readFile(char filename[]) { + + // Opening file; ifstream::ate is use to determine file size + std::ifstream file; + file.open(filename, std::ifstream::ate); + char* contents; + if (!file) { + contents = new char[1]; + return contents; + } + + // Get file size + size_t file_size = file.tellg(); + + // Return file pointer from end of the file (set by ifstream::ate) to beginning + file.seekg(0); + + // Reading file to char array and returing it + std::filebuf* file_buf = file.rdbuf(); + contents = new char[file_size + 1](); + file_buf->sgetn(contents, file_size); + file.close(); + return contents; + } + + /***************************************************************************** + * void print + * Binding of simple console print function to the VM + *****************************************************************************/ + void print(const v8::FunctionCallbackInfo& args) { + + // Getting arguments; error handling + v8::Isolate* isolate = args.GetIsolate(); + v8::String::Utf8Value val(isolate, args[0]); + if (*val == nullptr) + isolate->ThrowException( + v8::String::NewFromUtf8(isolate, "First argument of function is empty") + .ToLocalChecked()); + + // Printing + printf("%s\n", *val); + } + + /***************************************************************************** + * v8::MaybeLocal loadModule + * Loads module from code[] without checking it + *****************************************************************************/ + v8::MaybeLocal JSModuleCompiler::loadModule(char code[], + char name[], + v8::Local cx) { + + // Convert char[] to VM's string type + v8::Local vcode = + v8::String::NewFromUtf8(cx->GetIsolate(), code).ToLocalChecked(); + + // Create script origin to determine if it is module or not. + // Only first and last argument matters; other ones are default values. + // First argument gives script name (useful in error messages), last + // informs that it is a module. + v8::ScriptOrigin origin( + v8::String::NewFromUtf8(cx->GetIsolate(), name).ToLocalChecked(), + v8::Integer::New(cx->GetIsolate(), 0), + v8::Integer::New(cx->GetIsolate(), 0), v8::False(cx->GetIsolate()), + v8::Local(), v8::Local(), + v8::False(cx->GetIsolate()), v8::False(cx->GetIsolate()), + v8::True(cx->GetIsolate())); + + // Compiling module from source (code + origin) + v8::Context::Scope context_scope(cx); + v8::ScriptCompiler::Source source(vcode, origin); + v8::MaybeLocal mod; + mod = v8::ScriptCompiler::CompileModule(cx->GetIsolate(), &source); + if (mod.IsEmpty()) + { + UE_LOG(LogTemp, Warning, TEXT("Script failed to load")); + } + // Returning non-checked module + return mod; + } + + /***************************************************************************** + * v8::Local checkModule + * Checks out module (if it isn't nullptr/empty) + *****************************************************************************/ + v8::Local JSModuleCompiler::checkModule(v8::MaybeLocal maybeModule, + v8::Local cx) { + + // Checking out + v8::Local mod; + if (!maybeModule.ToLocal(&mod)) { + printf("Error loading module!\n"); + exit(EXIT_FAILURE); + } + + // Instantianing (including checking out depedencies). It uses callResolve + // as callback: check # + v8::Maybe result = mod->InstantiateModule(cx, JSModuleCompiler::callResolve); + if (result.IsNothing()) { + printf("\nCan't instantiate module.\n"); + exit(EXIT_FAILURE); + } + + // Returning check-out module + return mod; + } + + /***************************************************************************** + * v8::Local execModule + * Executes module's code + *****************************************************************************/ + v8::Local JSModuleCompiler::execModule(v8::Local mod, + v8::Local cx, + bool nsObject) { + + // Executing module with return value + v8::Local retValue; + if (!mod->Evaluate(cx).ToLocal(&retValue)) { + printf("Error evaluating module!\n"); + exit(EXIT_FAILURE); + } + + // nsObject determins, if module namespace or return value has to be returned. + // Module namespace is required during import callback; see lines # and #. + if (nsObject) + return mod->GetModuleNamespace(); + else + return retValue; + } + + /***************************************************************************** + * v8::MaybeLocal callResolve + * Callback from static import. + *****************************************************************************/ + v8::MaybeLocal JSModuleCompiler::callResolve(v8::Local context, + v8::Local specifier, + v8::Local referrer) { + + v8::String::Utf8Value str(context->GetIsolate(), specifier); + + // Return unchecked module + return loadModule(readFile(*str), *str, context); + } + + /***************************************************************************** + * v8::MaybeLocal callDynamic + * Callback from dynamic import. + *****************************************************************************/ + v8::MaybeLocal JSModuleCompiler::callDynamic(v8::Local context, + v8::Local referrer, + v8::Local specifier, + v8::Local import_assertions) { + + // Promise resolver: that way promise for dynamic import can be rejected + // or full-filed + v8::Local resolver = + v8::Promise::Resolver::New(context).ToLocalChecked(); + v8::MaybeLocal promise(resolver->GetPromise()); + + // Loading module (with checking) + v8::String::Utf8Value name(context->GetIsolate(), specifier); + v8::Local mod = + checkModule(loadModule(readFile(*name), *name, context), context); + v8::Local retValue = execModule(mod, context, true); + + // Resolving (fulfilling) promise with module global namespace + resolver->Resolve(context, retValue); + return promise; + } + + /***************************************************************************** + * void callMeta + * Callback for module metadata. + *****************************************************************************/ + void JSModuleCompiler::callMeta(v8::Local context, + v8::Local module, + v8::Local meta) { + + // In this example, this is throw-away function. But it shows that you can + // bind module's url. Here, placeholder is used. + meta->Set( + context, + v8::String::NewFromUtf8(context->GetIsolate(), "url").ToLocalChecked(), + v8::String::NewFromUtf8(context->GetIsolate(), "https://something.sh") + .ToLocalChecked()); + } + +} diff --git a/Source/V8/Private/JavaScriptModuleCompiler.h b/Source/V8/Private/JavaScriptModuleCompiler.h new file mode 100644 index 00000000..5a29a922 --- /dev/null +++ b/Source/V8/Private/JavaScriptModuleCompiler.h @@ -0,0 +1,39 @@ +#pragma once +/********************************************************** + * Javascript EC6 (modules) compiler + * by Jeffrey Kesselman (jpkessel@purdue.edu) + * + * Heavily cribbed from https://gist.github.com/surusek/4c05e4dcac6b82d18a1a28e6742fc23e + * + **********************************************************/ +#include +#include + +namespace module_compiler +{ + class JSModuleCompiler + { + private: + static v8::MaybeLocal callResolve(v8::Local context, v8::Local specifier, + v8::Local referrer); + static v8::MaybeLocal callDynamic(v8::Local context, v8::Local referrer, + v8::Local specifier, + v8::Local import_assertions); + static void callMeta(v8::Local context, v8::Local module, v8::Local meta); + + public: + static v8::MaybeLocal loadModule(char code[], + char name[], + v8::Local cx); + + // Check, if module isn't empty (or pointer to it); line #221 + static v8::Local checkModule(v8::MaybeLocal maybeModule, + v8::Local cx); + + // Executes module; line #247 + static v8::Local execModule(v8::Local mod, + v8::Local cx, + bool nsObject = false); + + }; +} diff --git a/Source/V8/Private/JavascriptContext_Private.cpp b/Source/V8/Private/JavascriptContext_Private.cpp index 6912005b..74796745 100644 --- a/Source/V8/Private/JavascriptContext_Private.cpp +++ b/Source/V8/Private/JavascriptContext_Private.cpp @@ -30,8 +30,10 @@ #include "JavascriptStats.h" #include "../../Launch/Resources/Version.h" +#include "JavaScriptModuleCompiler.h" using namespace v8; +using namespace module_compiler; static const int kContextEmbedderDataIndex = 0; static const int32 MagicNumber = 0x2852abd3; @@ -1797,8 +1799,14 @@ class FJavascriptContextImplementation : public FJavascriptContext { Text = FString::Printf(TEXT("(function (global,__filename,__dirname) { %s\n;}(this,'%s','%s'));"), *Script, *ScriptPath, *FPaths::GetPath(ScriptPath)); } - - auto ret = RunScript(ScriptPath, Text, 0); + Local ret; + if (Filename.EndsWith(".mjs")) + { + ret = RunModule(ScriptPath, Text, 0); + } else + { + ret = RunScript(ScriptPath, Text, 0); + } return ret.IsEmpty()? TEXT("(empty)") : StringFromV8(isolate(), ret); } @@ -1870,6 +1878,57 @@ class FJavascriptContextImplementation : public FJavascriptContext } } + Local RunModule(const FString& Filename, const FString& Script, int line_offset = 0) + { + Isolate::Scope isolate_scope(isolate()); + Context::Scope context_scope(context()); + + TryCatch try_catch(isolate()); + try_catch.SetVerbose(true); + + auto Path = Filename; +#if PLATFORM_WINDOWS + // HACK for Visual Studio Code + if (Path.Len() && Path[1] == ':') + { + Path = Path.Mid(0, 1).ToLower() + Path.Mid(1); + } +#endif + + int lastDotIndex; + Filename.FindLastChar('/',lastDotIndex); + FString filename = Filename.Right(Filename.Len()-(lastDotIndex+1)); + FString filePath = Filename.Left(lastDotIndex); + auto ctx = context(); + ctx->SetEmbedderData(0, + String::NewFromUtf8( + ctx->GetIsolate(),TCHAR_TO_ANSI(*filename)).ToLocalChecked()); + ctx->SetEmbedderData(1, + String::NewFromUtf8( + ctx->GetIsolate(),TCHAR_TO_ANSI(*filePath)).ToLocalChecked()); + MaybeLocal MaybeMod = + JSModuleCompiler::loadModule( TCHAR_TO_ANSI(*Script), + TCHAR_TO_ANSI(*Filename),ctx); + if (MaybeMod.IsEmpty()) + { + UE_LOG(LogTemp, Warning, TEXT("Script load failed")); + return Local(); + } else + { + MaybeMod = JSModuleCompiler::checkModule(MaybeMod,ctx); + if (MaybeMod.IsEmpty()) + { + UE_LOG(LogTemp, Warning, TEXT("Script check failed")); + return Local(); + } else + { + return JSModuleCompiler::execModule(MaybeMod.ToLocalChecked(), ctx); + } + } + + + } + void FindPathFile(FString TargetRootPath, FString TargetFileName, TArray& OutFiles) { IFileManager::Get().FindFilesRecursive(OutFiles, TargetRootPath.GetCharArray().GetData(), TargetFileName.GetCharArray().GetData(), true, false); diff --git a/UnrealJS.uplugin b/UnrealJS.uplugin index eff3a885..4363b99e 100644 --- a/UnrealJS.uplugin +++ b/UnrealJS.uplugin @@ -1,14 +1,14 @@ { "FileVersion": 3, - "FriendlyName": "Unreal.js - Javascript Runtime", + "FriendlyName": "Unreal.js.jpk - Fork of Javascript Runtime", "Version": 2, "VersionName": "0.6.4", "FriendlyVersion": "0.6.4", "EngineVersion": "5.1.0", "Description": "Javascript powered UnrealEngine", "Category": "Programming", - "CreatedBy": "NCSOFT Corporation", - "CreatedByURL": "http://github.com/ncsoft", + "CreatedBy": "Professor K", + "CreatedByURL": "http://github.com/profk", "EnabledByDefault": true, "MarketplaceURL" : "com.epicgames.launcher://ue/marketplace/content/be751eedc4a14cc09e39945bc5a531c4", "Modules": [ From bd92bc1b5ba5bea0d44447ee3456f681723069ac Mon Sep 17 00:00:00 2001 From: professorK Date: Thu, 23 Nov 2023 01:22:58 -0500 Subject: [PATCH 03/10] Running .mjs with import statem,ents, bug in import code loading Loads module code unwrapped (you cant wrap import statements they must be at the top.) Current limitation, no argument parametres loads initial code file, fails to load import properly --- Source/V8/Private/JavaScriptModuleCompiler.cpp | 12 +++++++++--- Source/V8/Private/JavascriptContext_Private.cpp | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Source/V8/Private/JavaScriptModuleCompiler.cpp b/Source/V8/Private/JavaScriptModuleCompiler.cpp index db3f7585..9608bfa4 100644 --- a/Source/V8/Private/JavaScriptModuleCompiler.cpp +++ b/Source/V8/Private/JavaScriptModuleCompiler.cpp @@ -6,7 +6,7 @@ namespace module_compiler * char* readFile * Reads file contents to a null-terminated string. *****************************************************************************/ - char* readFile(char filename[]) { + char* readFile(const char filename[]) { // Opening file; ifstream::ate is use to determine file size std::ifstream file; @@ -120,6 +120,8 @@ namespace module_compiler v8::Local cx, bool nsObject) { + cx->GetIsolate()->SetHostImportModuleDynamicallyCallback(callDynamic); + // Executing module with return value v8::Local retValue; if (!mod->Evaluate(cx).ToLocal(&retValue)) { @@ -144,9 +146,13 @@ namespace module_compiler v8::Local referrer) { v8::String::Utf8Value str(context->GetIsolate(), specifier); - + v8::String::Utf8Value fileroot(context->GetIsolate(), + context->GetEmbedderData(0)); + std::string fqn(*fileroot); + fqn = fqn+std::string("/")+std::string(*str); + // Return unchecked module - return loadModule(readFile(*str), *str, context); + return loadModule(readFile(fqn.c_str()), *str, context); } /***************************************************************************** diff --git a/Source/V8/Private/JavascriptContext_Private.cpp b/Source/V8/Private/JavascriptContext_Private.cpp index 74796745..97bad6ad 100644 --- a/Source/V8/Private/JavascriptContext_Private.cpp +++ b/Source/V8/Private/JavascriptContext_Private.cpp @@ -1784,7 +1784,10 @@ class FJavascriptContextImplementation : public FJavascriptContext auto ScriptPath = GetScriptFileFullPath(Filename); FString Text; - if (Args.Num() > 0) + if (Filename.EndsWith(".mjs")){ // imports cannto be wrapped + // no argument support atm + Text = Script; + } else if (Args.Num() > 0) { FString strArgs = FString::Printf(TEXT("\'%s\'"), *Args[0]); for (int32 i = 1; i < Args.Num(); ++i) From 8859395afe835b73a4817b8149db66cc8f082d99 Mon Sep 17 00:00:00 2001 From: professorK Date: Thu, 23 Nov 2023 15:12:39 -0500 Subject: [PATCH 04/10] Now loads and runs module files Will load and run a file with extensions ".mjs" now as an EC6 module --- .../V8/Private/JavaScriptModuleCompiler.cpp | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Source/V8/Private/JavaScriptModuleCompiler.cpp b/Source/V8/Private/JavaScriptModuleCompiler.cpp index 9608bfa4..91228d79 100644 --- a/Source/V8/Private/JavaScriptModuleCompiler.cpp +++ b/Source/V8/Private/JavaScriptModuleCompiler.cpp @@ -1,5 +1,8 @@ #include "JavaScriptModuleCompiler.h" +#include "IV8.h" +#include "Misc/FileHelper.h" + namespace module_compiler { /***************************************************************************** @@ -145,14 +148,24 @@ namespace module_compiler v8::Local specifier, v8::Local referrer) { - v8::String::Utf8Value str(context->GetIsolate(), specifier); + v8::String::Utf8Value filename(context->GetIsolate(), specifier); v8::String::Utf8Value fileroot(context->GetIsolate(), - context->GetEmbedderData(0)); - std::string fqn(*fileroot); - fqn = fqn+std::string("/")+std::string(*str); - + context->GetEmbedderData(1)); + FString fqn(*fileroot); + fqn = fqn.Append(FString("/"))+FString(*filename); + auto foo = *fileroot; // Return unchecked module - return loadModule(readFile(fqn.c_str()), *str, context); + FString Text; + if (!FFileHelper::LoadFileToString(Text, *fqn)) + { + std::string sfilename(*filename); + FString msg = TEXT("Failed to read script file '%s'"); + UE_LOG(LogJavascript, Warning, + TEXT("Failed to read script file '%s'"), + sfilename.c_str()); + } + + return loadModule(TCHAR_TO_ANSI(*Text), *filename, context); } /***************************************************************************** From 46fdd113566fad2259781b3c47d24d474a9229be Mon Sep 17 00:00:00 2001 From: professorK Date: Thu, 23 Nov 2023 15:16:14 -0500 Subject: [PATCH 05/10] Cleaned up a bit and added header comment --- Source/V8/Private/JavaScriptModuleCompiler.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/V8/Private/JavaScriptModuleCompiler.cpp b/Source/V8/Private/JavaScriptModuleCompiler.cpp index 91228d79..87591a80 100644 --- a/Source/V8/Private/JavaScriptModuleCompiler.cpp +++ b/Source/V8/Private/JavaScriptModuleCompiler.cpp @@ -3,6 +3,14 @@ #include "IV8.h" #include "Misc/FileHelper.h" +/******************************************************************** + * A static class that handles loading and execution EC6 module files + * to the V8 engine in the UE5 environment. + * Written by Professor Jeff Kesselman MS MFA + * Purdue University + * 11/23/2023 + * jpkessel@purdue.edu + * ***********************************/ namespace module_compiler { /***************************************************************************** @@ -153,7 +161,7 @@ namespace module_compiler context->GetEmbedderData(1)); FString fqn(*fileroot); fqn = fqn.Append(FString("/"))+FString(*filename); - auto foo = *fileroot; + // Return unchecked module FString Text; if (!FFileHelper::LoadFileToString(Text, *fqn)) From 1b54a110317305865e0d2a44a0a3eeb4acc9300f Mon Sep 17 00:00:00 2001 From: professorK Date: Fri, 24 Nov 2023 15:33:43 -0500 Subject: [PATCH 06/10] Added a run module node to blueprints Added a run module node to blueprints --- Source/V8/Private/JavascriptContext_Private.cpp | 16 ++++++++++++++++ Source/V8/Private/JavascriptContext_Private.h | 3 ++- Source/V8/Private/V8Implementation.cpp | 9 +++++++++ Source/V8/Public/JavascriptContext.h | 4 ++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Source/V8/Private/JavascriptContext_Private.cpp b/Source/V8/Private/JavascriptContext_Private.cpp index 97bad6ad..c4663229 100644 --- a/Source/V8/Private/JavascriptContext_Private.cpp +++ b/Source/V8/Private/JavascriptContext_Private.cpp @@ -1834,6 +1834,22 @@ class FJavascriptContextImplementation : public FJavascriptContext return str; } + FString Public_RunModule(const FString& Script, bool bOutput = true) + { + Isolate::Scope isolate_scope(isolate()); + HandleScope handle_scope(isolate()); + Context::Scope context_scope(context()); + + auto ret = RunModule(TEXT("(inline)"), Script); + auto str = ret.IsEmpty() ? TEXT("(empty)") : StringFromV8(isolate(), ret); + + if (bOutput && !ret.IsEmpty()) + { + UE_LOG(LogJavascript, Log, TEXT("%s"), *str); + } + return str; + } + void RequestV8GarbageCollection() { isolate()->LowMemoryNotification(); diff --git a/Source/V8/Private/JavascriptContext_Private.h b/Source/V8/Private/JavascriptContext_Private.h index dead2d5f..105a0ac7 100644 --- a/Source/V8/Private/JavascriptContext_Private.h +++ b/Source/V8/Private/JavascriptContext_Private.h @@ -47,6 +47,7 @@ struct FJavascriptContext : TSharedFromThis virtual FString GetScriptFileFullPath(const FString& Filename) = 0; virtual FString ReadScriptFile(const FString& Filename) = 0; virtual FString Public_RunScript(const FString& Script, bool bOutput = true) = 0; + virtual FString Public_RunModule(const FString& String, bool bOutput) = 0; virtual void RequestV8GarbageCollection() = 0; virtual FString Public_RunFile(const FString& Filename, const TArray& Args) = 0; virtual void FindPathFile(const FString TargetRootPath, const FString TargetFileName, TArray& OutFiles) = 0; @@ -65,7 +66,7 @@ struct FJavascriptContext : TSharedFromThis virtual v8::Local context() = 0; virtual v8::Local ExportObject(UObject* Object, bool bForce = false) = 0; virtual v8::Local GetProxyFunction(v8::Local Context, UObject* Object, const TCHAR* Name) = 0; - + static FJavascriptContext* FromV8(v8::Local Context); static FJavascriptContext* Create(TSharedPtr InEnvironment, TArray& InPaths); diff --git a/Source/V8/Private/V8Implementation.cpp b/Source/V8/Private/V8Implementation.cpp index 0b890c3b..85d7cac1 100644 --- a/Source/V8/Private/V8Implementation.cpp +++ b/Source/V8/Private/V8Implementation.cpp @@ -159,6 +159,15 @@ FString UJavascriptContext::RunScript(FString Script, bool bOutput) return TEXT(""); } +FString UJavascriptContext::RunModule(FString Script, bool bOutput) +{ + if (JavascriptContext.IsValid()) + { + return JavascriptContext->Public_RunModule(Script, bOutput); + } + return TEXT(""); +} + void UJavascriptContext::RegisterConsoleCommand(FString Command, FString Help, FJavascriptFunction Function) { #if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) diff --git a/Source/V8/Public/JavascriptContext.h b/Source/V8/Public/JavascriptContext.h index 9642e4e4..a786faa5 100644 --- a/Source/V8/Public/JavascriptContext.h +++ b/Source/V8/Public/JavascriptContext.h @@ -73,6 +73,10 @@ class V8_API UJavascriptContext : public UObject UFUNCTION(BlueprintCallable, Category = "Scripting|Javascript") FString RunScript(FString Script, bool bOutput = true); + // Added by JPK on 11/24/2023 + UFUNCTION(BlueprintCallable, Category = "Scripting|Javascript") + FString RunModule(FString Script, bool bOutput = true); + UFUNCTION(BlueprintCallable, Category = "Scripting|Javascript") void RegisterConsoleCommand(FString Command, FString Help, FJavascriptFunction Function); From 40139e17044bc085a8e5f9c65c4973a4ba3d65e1 Mon Sep 17 00:00:00 2001 From: professorK Date: Sat, 25 Nov 2023 12:28:53 -0500 Subject: [PATCH 07/10] Updated UJavascriptIsolate for UE5 UJavascriptIsolate updated for UE5 to use UCLASS(BlueprintType) so it is constructable within a blueprint Added trivial blueprint example to Content because there are none currently --- Source/V8/Public/JavascriptIsolate.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/V8/Public/JavascriptIsolate.h b/Source/V8/Public/JavascriptIsolate.h index 509cc143..98db1935 100644 --- a/Source/V8/Public/JavascriptIsolate.h +++ b/Source/V8/Public/JavascriptIsolate.h @@ -103,7 +103,7 @@ struct V8_API FJavascriptHeapStatistics bool bDoesZapGarbage = false; }; -UCLASS() +UCLASS(BlueprintType) class V8_API UJavascriptIsolate : public UObject { GENERATED_UCLASS_BODY() @@ -113,6 +113,8 @@ class V8_API UJavascriptIsolate : public UObject TSharedPtr JavascriptIsolate; + + UFUNCTION(BlueprintCallable, Category = "Scripting|Javascript") void Init(bool bIsEditor); From 1bd659400e340177207e550f93d30ed309406f82 Mon Sep 17 00:00:00 2001 From: professorK Date: Sat, 25 Nov 2023 13:05:26 -0500 Subject: [PATCH 08/10] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 19060875..eb2591a1 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,6 @@ - core component of [Unreal.js](https://github.com/ncsoft/Unreal.js) - Please visit [project repo](https://github.com/ncsoft/Unreal.js). + +Sample Blueprint: https://imgur.com/nexH05q + From ebfa2079ddb81d429ea0967124b51698a1de3770 Mon Sep 17 00:00:00 2001 From: professorK Date: Mon, 15 Jan 2024 18:55:23 -0500 Subject: [PATCH 09/10] string fixes slight changes in 5.3 to TargetArchitecture. Usedto be a string. Is now an object you have to do ToString() on. --- Source/JavascriptWebSocket/JavascriptWebSocket.Build.cs | 2 +- Source/V8/V8.Build.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/JavascriptWebSocket/JavascriptWebSocket.Build.cs b/Source/JavascriptWebSocket/JavascriptWebSocket.Build.cs index d8671e50..c434e417 100644 --- a/Source/JavascriptWebSocket/JavascriptWebSocket.Build.cs +++ b/Source/JavascriptWebSocket/JavascriptWebSocket.Build.cs @@ -48,7 +48,7 @@ private void HackWebSocketIncludeDir(String WebsocketPath, ReadOnlyTargetRules T } else if (Target.Platform == UnrealTargetPlatform.Linux) { - PlatformSubdir = Path.Combine(PlatformSubdir, Target.Architecture); + PlatformSubdir = Path.Combine(PlatformSubdir, Target.Architecture.ToString()); } PrivateDependencyModuleNames.Add("libWebSockets"); diff --git a/Source/V8/V8.Build.cs b/Source/V8/V8.Build.cs index d7396264..a0479755 100644 --- a/Source/V8/V8.Build.cs +++ b/Source/V8/V8.Build.cs @@ -85,7 +85,7 @@ private void HackWebSocketIncludeDir(String WebsocketPath, ReadOnlyTargetRules T } else if (Target.Platform == UnrealTargetPlatform.Linux) { - PlatformSubdir = Path.Combine(PlatformSubdir, Target.Architecture); + PlatformSubdir = Path.Combine(PlatformSubdir, Target.Architecture.ToString()); } PrivateDependencyModuleNames.Add("libWebSockets"); From c38572af3cce4eda8414cbdc889435e3a85afaec Mon Sep 17 00:00:00 2001 From: professorK Date: Tue, 16 Jan 2024 13:15:03 -0500 Subject: [PATCH 10/10] updqted for 5.3 Small but significant fixes in the v8 plugin codebase for UE 5.3 build environmenht --- Source/JavascriptEditor/JavascriptEditorViewport.cpp | 2 +- Source/JavascriptEditor/JavascriptUICommands.cpp | 2 +- Source/JavascriptHttp/JavascriptHttpRequest.h | 2 +- Source/JavascriptUMG/JavascriptGameViewport.cpp | 2 +- Source/JavascriptUMG/JavascriptWindow.cpp | 2 +- Source/V8/Private/JavascriptIsolate_Private.cpp | 2 +- Source/V8/Private/JavascriptLibrary.cpp | 2 +- Source/V8/Private/Translator.cpp | 2 +- UnrealJS.uplugin | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/JavascriptEditor/JavascriptEditorViewport.cpp b/Source/JavascriptEditor/JavascriptEditorViewport.cpp index c501ec7c..9cebe1fa 100644 --- a/Source/JavascriptEditor/JavascriptEditorViewport.cpp +++ b/Source/JavascriptEditor/JavascriptEditorViewport.cpp @@ -6,7 +6,7 @@ #include "Engine/Canvas.h" #include "Components/OverlaySlot.h" #include "AssetViewerSettings.h" -#include "Launch/Resources/Version.h" +#include "Runtime/Launch/Resources/Version.h" #include "Components/DirectionalLightComponent.h" #if ENGINE_MAJOR_VERSION > 4 #include "UnrealWidget.h" diff --git a/Source/JavascriptEditor/JavascriptUICommands.cpp b/Source/JavascriptEditor/JavascriptUICommands.cpp index aa89380d..bfa4d219 100644 --- a/Source/JavascriptEditor/JavascriptUICommands.cpp +++ b/Source/JavascriptEditor/JavascriptUICommands.cpp @@ -1,7 +1,7 @@ #include "JavascriptUICommands.h" #include "JavascriptMenuLibrary.h" #include "Framework/Commands/Commands.h" -#include "Launch/Resources/Version.h" +#include "Runtime/Launch/Resources/Version.h" //PRAGMA_DISABLE_OPTIMIZATION diff --git a/Source/JavascriptHttp/JavascriptHttpRequest.h b/Source/JavascriptHttp/JavascriptHttpRequest.h index e8182cc7..5dda2f96 100644 --- a/Source/JavascriptHttp/JavascriptHttpRequest.h +++ b/Source/JavascriptHttp/JavascriptHttpRequest.h @@ -7,7 +7,7 @@ #include "Interfaces/IHttpRequest.h" #include "Interfaces/IHttpResponse.h" #include "HttpModule.h" -#include "Launch/Resources/Version.h" +#include "Runtime/Launch/Resources/Version.h" #include "JavascriptHttpRequest.generated.h" diff --git a/Source/JavascriptUMG/JavascriptGameViewport.cpp b/Source/JavascriptUMG/JavascriptGameViewport.cpp index 08f80164..3e5f4e6b 100644 --- a/Source/JavascriptUMG/JavascriptGameViewport.cpp +++ b/Source/JavascriptUMG/JavascriptGameViewport.cpp @@ -8,7 +8,7 @@ #include "SceneView.h" #include "CanvasTypes.h" #include "Widgets/SViewport.h" -#include "Launch/Resources/Version.h" +#include "Runtime/Launch/Resources/Version.h" #define LOCTEXT_NAMESPACE "UMG" diff --git a/Source/JavascriptUMG/JavascriptWindow.cpp b/Source/JavascriptUMG/JavascriptWindow.cpp index 170f7511..8e704f90 100644 --- a/Source/JavascriptUMG/JavascriptWindow.cpp +++ b/Source/JavascriptUMG/JavascriptWindow.cpp @@ -1,6 +1,6 @@ #include "JavascriptWindow.h" #include "Widgets/SWindow.h" -#include "Launch/Resources/Version.h" +#include "Runtime/Launch/Resources/Version.h" UJavascriptWindow::UJavascriptWindow(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) diff --git a/Source/V8/Private/JavascriptIsolate_Private.cpp b/Source/V8/Private/JavascriptIsolate_Private.cpp index 42b6a626..974f9174 100644 --- a/Source/V8/Private/JavascriptIsolate_Private.cpp +++ b/Source/V8/Private/JavascriptIsolate_Private.cpp @@ -1788,7 +1788,7 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate auto Function = reinterpret_cast((Local::Cast(info.Data()))->Value()); // Determine 'this' - auto Object = (Function->FunctionFlags & FUNC_Static) ? Function->GetOwnerClass()->ClassDefaultObject : UObjectFromV8(isolate->GetCurrentContext(), self); + TObjectPtr Object = (Function->FunctionFlags & FUNC_Static) ? Function->GetOwnerClass()->ClassDefaultObject : TObjectPtr(UObjectFromV8(isolate->GetCurrentContext(), self)); // Check 'this' is valid if (!IsValid(Object)) diff --git a/Source/V8/Private/JavascriptLibrary.cpp b/Source/V8/Private/JavascriptLibrary.cpp index d9813155..91677be3 100644 --- a/Source/V8/Private/JavascriptLibrary.cpp +++ b/Source/V8/Private/JavascriptLibrary.cpp @@ -6,7 +6,7 @@ #include "Sockets.h" #include "NavigationSystem.h" #include "HAL/PlatformApplicationMisc.h" -#include "Launch/Resources/Version.h" +#include "Runtime/Launch/Resources/Version.h" #include "Misc/FileHelper.h" #include "Misc/Paths.h" #include "UObject/MetaData.h" diff --git a/Source/V8/Private/Translator.cpp b/Source/V8/Private/Translator.cpp index 704e31ee..c701d649 100644 --- a/Source/V8/Private/Translator.cpp +++ b/Source/V8/Private/Translator.cpp @@ -1,6 +1,6 @@ #include "Translator.h" #include "Engine/UserDefinedStruct.h" -#include "Launch/Resources/Version.h" +#include "Runtime/Launch/Resources/Version.h" namespace v8 { diff --git a/UnrealJS.uplugin b/UnrealJS.uplugin index 4363b99e..895ceecb 100644 --- a/UnrealJS.uplugin +++ b/UnrealJS.uplugin @@ -4,7 +4,7 @@ "Version": 2, "VersionName": "0.6.4", "FriendlyVersion": "0.6.4", - "EngineVersion": "5.1.0", + "EngineVersion": "5.3", "Description": "Javascript powered UnrealEngine", "Category": "Programming", "CreatedBy": "Professor K",