Skip to content

Commit 1473619

Browse files
author
Nako Sung
committed
merged
2 parents 65ab8c8 + b001cb7 commit 1473619

File tree

8 files changed

+333
-172
lines changed

8 files changed

+333
-172
lines changed

Plugins/UnrealJS/Source/JavascriptEditor/JavascriptEditor.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
#include "IV8.h"
77
#include "ScopedTransaction.h"
88
#if WITH_EDITOR
9+
// Settings
10+
#include "JavascriptSettings.h"
11+
#include "ISettingsModule.h"
912
#include "Settings/EditorLoadingSavingSettings.h"
1013
#endif
1114

15+
#define LOCTEXT_NAMESPACE "UnrealJSEditor"
16+
1217
class FJavascriptEditorModule : public IJavascriptEditorModule
1318
{
1419
// Begin IModuleInterface
@@ -29,6 +34,25 @@ class FJavascriptEditorModule : public IJavascriptEditorModule
2934
bool bRegistered{ false };
3035

3136
void Unregister();
37+
38+
void RegisterSettings()
39+
{
40+
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
41+
{
42+
SettingsModule->RegisterSettings("Project", "Plugins", "UnrealJS",
43+
LOCTEXT("RuntimeSettingsName", "UnrealJS"),
44+
LOCTEXT("RuntimeSettingsDescription", "Configure the UnrealJS plugin"),
45+
GetMutableDefault<UJavascriptSettings>());
46+
}
47+
}
48+
49+
void UnregisterSettings()
50+
{
51+
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
52+
{
53+
SettingsModule->UnregisterSettings("Project", "Plugins", "UnrealJS");
54+
}
55+
}
3256
#endif
3357
};
3458

@@ -86,6 +110,8 @@ static void PatchReimportRule()
86110
void FJavascriptEditorModule::StartupModule()
87111
{
88112
#if WITH_EDITOR
113+
RegisterSettings();
114+
89115
PatchReimportRule();
90116

91117
auto Isolate = NewObject<UJavascriptIsolate>();
@@ -117,6 +143,11 @@ void FJavascriptEditorModule::ShutdownModule()
117143
{
118144
#if WITH_EDITOR
119145
Unregister();
146+
147+
if (UObjectInitialized())
148+
{
149+
UnregisterSettings();
150+
}
120151
#endif
121152
}
122153

Plugins/UnrealJS/Source/V8/Private/JavascriptIsolate_Private.cpp

Lines changed: 0 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
338338
ExportMemory(ObjectTemplate);
339339

340340
ExportMisc(ObjectTemplate);
341-
342-
ExportProfiler(ObjectTemplate);
343341
}
344342

345343
~FJavascriptIsolateImplementation()
@@ -796,173 +794,6 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
796794
ReadOnly);
797795
}
798796

799-
static Local<Object> Visit(Isolate* isolate, const v8::CpuProfileNode* node)
800-
{
801-
static TMap<const v8::CpuProfileNode*, Handle<Object>> Visited;
802-
803-
if (!isolate)
804-
{
805-
Visited.Empty();
806-
return Local<Object>();
807-
}
808-
auto Existing = Visited.Find(node);
809-
if (Existing) return *Existing;
810-
811-
FIsolateHelper I(isolate);
812-
813-
auto Out = Object::New(isolate);
814-
815-
Visited.Add(node, Out);
816-
817-
Out->Set(I.Keyword("ScriptResourceName"), node->GetScriptResourceName());
818-
Out->Set(I.Keyword("FunctionName"), node->GetFunctionName());
819-
Out->Set(I.Keyword("HitCount"), Integer::NewFromUnsigned(isolate,node->GetHitCount()));
820-
Out->Set(I.Keyword("LineNumber"), Integer::New(isolate,node->GetLineNumber()));
821-
Out->Set(I.Keyword("ColumnNumber"), Integer::New(isolate,node->GetColumnNumber()));
822-
Out->Set(I.Keyword("ScriptId"), Integer::New(isolate, node->GetScriptId()));
823-
824-
{
825-
uint32_t Num = node->GetHitLineCount();
826-
TArray<v8::CpuProfileNode::LineTick> Buffer;
827-
Buffer.AddDefaulted(Num);
828-
node->GetLineTicks(Buffer.GetData(), Num);
829-
830-
auto Arr = Array::New(isolate, Num);
831-
for (uint32_t Index = 0; Index < Num; ++Index)
832-
{
833-
const auto& info = Buffer[Index];
834-
auto item = Object::New(isolate);
835-
item->Set(I.Keyword("line"), Integer::New(isolate,info.line));
836-
item->Set(I.Keyword("hit_count"), Integer::New(isolate, info.hit_count));
837-
Arr->Set(Index, item);
838-
}
839-
Out->Set(I.Keyword("LineTicks"), Arr);
840-
}
841-
842-
auto BailOutReason = node->GetBailoutReason();
843-
if (BailOutReason)
844-
{
845-
Out->Set(I.Keyword("BailOutReason"), I.Keyword(BailOutReason));
846-
}
847-
848-
{
849-
const auto& deopt = node->GetDeoptInfos();
850-
uint32_t Num = deopt.size();
851-
if (Num)
852-
{
853-
auto Arr = Array::New(isolate, deopt.size());
854-
for (uint32_t Index = 0; Index < Num; ++Index)
855-
{
856-
const auto& info = deopt[Index];
857-
FString out;
858-
for (const auto& frame : info.stack)
859-
{
860-
out.Append(FString::Printf(TEXT("%d:%d "), (int)frame.script_id, (int)frame.position));
861-
}
862-
auto item = Object::New(isolate);
863-
item->Set(I.Keyword("reason"), I.Keyword(deopt[Index].deopt_reason));
864-
item->Set(I.Keyword("stack"), I.String(out));
865-
Arr->Set(Index, item);
866-
}
867-
Out->Set(I.Keyword("DeoptInfos"), Arr);
868-
}
869-
}
870-
871-
uint32_t Num = node->GetChildrenCount();
872-
if (Num)
873-
{
874-
auto Arr = Array::New(isolate, Num);
875-
for (uint32_t Index = 0; Index < Num; ++Index)
876-
{
877-
Arr->Set(Index, Visit(isolate, node->GetChild(Index)));
878-
}
879-
Out->Set(I.Keyword("Children"), Arr);
880-
}
881-
return Out;
882-
};
883-
884-
void ExportProfiler(Local<ObjectTemplate> global_templ)
885-
{
886-
FIsolateHelper I(isolate_);
887-
888-
Local<FunctionTemplate> Template = I.FunctionTemplate();
889-
890-
auto add_fn = [&](const char* name, FunctionCallback fn) {
891-
Template->PrototypeTemplate()->Set(I.Keyword(name), I.FunctionTemplate(fn));
892-
};
893-
894-
add_fn("SetSamplingInterval", [](const FunctionCallbackInfo<Value>& info)
895-
{
896-
FIsolateHelper I(info.GetIsolate());
897-
898-
auto profiler = info.GetIsolate()->GetCpuProfiler();
899-
900-
if (info.Length() == 1)
901-
{
902-
profiler->SetSamplingInterval(info[0]->IntegerValue());
903-
}
904-
});
905-
906-
add_fn("StartProfiling", [](const FunctionCallbackInfo<Value>& info)
907-
{
908-
FIsolateHelper I(info.GetIsolate());
909-
910-
auto profiler = info.GetIsolate()->GetCpuProfiler();
911-
912-
if (info.Length() == 2)
913-
{
914-
profiler->StartProfiling(info[0].As<String>(), info[1]->BooleanValue());
915-
info.GetReturnValue().Set(true);
916-
}
917-
});
918-
919-
add_fn("StopProfiling", [](const FunctionCallbackInfo<Value>& info)
920-
{
921-
auto isolate = info.GetIsolate();
922-
FIsolateHelper I(isolate);
923-
924-
auto profiler = isolate->GetCpuProfiler();
925-
926-
if (info.Length() == 1)
927-
{
928-
auto Profile = profiler->StopProfiling(info[0].As<String>());
929-
if (!Profile) return;
930-
931-
auto Out = Object::New(isolate);
932-
Out->Set(I.Keyword("Root"), Visit(isolate, Profile->GetTopDownRoot()));
933-
Out->Set(I.Keyword("Title"), Profile->GetTitle());
934-
935-
{
936-
uint32_t Num = Profile->GetSamplesCount();
937-
if (Num)
938-
{
939-
auto Arr = Array::New(isolate, Num);
940-
for (uint32_t Index = 0; Index < Num; ++Index)
941-
{
942-
Arr->Set(Index, Visit(isolate, Profile->GetSample(Index)));
943-
}
944-
Out->Set(I.Keyword("Samples"), Arr);
945-
}
946-
}
947-
948-
949-
// cleanup
950-
Visit(nullptr, nullptr);
951-
952-
info.GetReturnValue().Set(Out);
953-
954-
Profile->Delete();
955-
}
956-
});
957-
958-
global_templ->Set(
959-
I.Keyword("v8"),
960-
// Create an instance
961-
Template->GetFunction()->NewInstance(),
962-
// Do not modify!
963-
ReadOnly);
964-
}
965-
966797
void ExportMisc(Local<ObjectTemplate> global_templ)
967798
{
968799
FIsolateHelper I(isolate_);

0 commit comments

Comments
 (0)