Skip to content

Commit

Permalink
Clear tasks and detach inspector client on runtime shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
tdermendjiev committed Apr 4, 2024
1 parent b1350e7 commit 1b18e9c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
21 changes: 7 additions & 14 deletions NativeScript/NativeScript.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ - (void)runMainApplication {
runtime_->RunMainScript();

CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);

tns::Tasks::Drain();
}

Expand All @@ -57,20 +56,16 @@ - (bool)liveSync {
}

- (void)shutdownRuntime {
if (RuntimeConfig.IsDebug) {
Console::DetachInspectorClient();
}
tns::Tasks::ClearTasks();
if (runtime_ != nullptr) {
Isolate* isolate = runtime_->GetIsolate();
{
v8::Locker l(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);

isolate->Dispose();
}
runtime_ = nullptr;
}
}

- (void)initializeWithConfig:(Config*)config {
- (instancetype)initializeWithConfig:(Config*)config {
if (self = [super init]) {
RuntimeConfig.BaseDir = [config.BaseDir UTF8String];
if (config.ApplicationPath != nil) {
Expand Down Expand Up @@ -108,14 +103,12 @@ - (void)initializeWithConfig:(Config*)config {
Console::AttachInspectorClient(inspectorClient);
}
}
return self;

}

- (instancetype)initWithConfig:(Config*)config {
if (self = [super init]) {
[self initializeWithConfig:config];
}
return self;
return [self initializeWithConfig:config];
}

- (void)restartWithConfig:(Config*)config {
Expand Down
4 changes: 4 additions & 0 deletions NativeScript/runtime/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ void Console::AttachInspectorClient(v8_inspector::JsV8InspectorClient* aInspecto
inspector = aInspector;
}

void Console::DetachInspectorClient() {
inspector = nullptr;
}

void Console::LogCallback(const FunctionCallbackInfo<Value>& args) {
// TODO: implement 'forceLog' override option like android has, to force logs in prod if desired
if (!RuntimeConfig.LogToSystemConsole) {
Expand Down
1 change: 1 addition & 0 deletions NativeScript/runtime/Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Console {
public:
static void Init(v8::Local<v8::Context> context);
static void AttachInspectorClient(v8_inspector::JsV8InspectorClient* inspector);
static void DetachInspectorClient();
private:
using ConsoleAPIType = v8_inspector::ConsoleAPIType;

Expand Down
4 changes: 4 additions & 0 deletions NativeScript/runtime/Tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ void Tasks::Drain() {
}
}

void Tasks::ClearTasks() {
tasks_.clear();
}

std::vector<std::function<void()>> Tasks::tasks_;

}
1 change: 1 addition & 0 deletions NativeScript/runtime/Tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Tasks {
public:
static void Register(std::function<void()> task);
static void Drain();
static void ClearTasks();
private:
static std::vector<std::function<void()>> tasks_;
};
Expand Down
8 changes: 6 additions & 2 deletions v8ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
2B5088A62BBEB92300F6EB68 /* metadata-arm64.bin in Resources */ = {isa = PBXBuildFile; fileRef = 2BFE21ED2AC1AC3100307752 /* metadata-arm64.bin */; };
2B5088A72BBEC1BC00F6EB68 /* TNSWidgets.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C20525A72577D86600C12A5C /* TNSWidgets.xcframework */; };
2B5088A82BBEC1BC00F6EB68 /* TNSWidgets.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C20525A72577D86600C12A5C /* TNSWidgets.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2B7EA6AF2353477000E5184E /* NativeScriptException.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2B7EA6AD2353476F00E5184E /* NativeScriptException.mm */; };
2B7EA6B02353477000E5184E /* NativeScriptException.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B7EA6AE2353477000E5184E /* NativeScriptException.h */; };
2BFE22062AC1C93100307752 /* metadata-arm64.bin in Resources */ = {isa = PBXBuildFile; fileRef = 2BFE22052AC1C93100307752 /* metadata-arm64.bin */; };
Expand Down Expand Up @@ -46,7 +49,6 @@
91B25A0B29DAC83D00E3CE04 /* ns-v8-tracing-agent-impl.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B25A0929DAC83D00E3CE04 /* ns-v8-tracing-agent-impl.h */; };
C205257F2577D6F900C12A5C /* NativeScript.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2DDEB32229EAB3B00345BFE /* NativeScript.framework */; };
C20525802577D6F900C12A5C /* NativeScript.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C2DDEB32229EAB3B00345BFE /* NativeScript.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
C20525A82577D86600C12A5C /* TNSWidgets.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C20525A72577D86600C12A5C /* TNSWidgets.xcframework */; };
C20AB5E626E1015300E2B41D /* OneByteStringResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C20AB5E426E1015200E2B41D /* OneByteStringResource.cpp */; };
C20AB5E726E1015300E2B41D /* OneByteStringResource.h in Headers */ = {isa = PBXBuildFile; fileRef = C20AB5E526E1015200E2B41D /* OneByteStringResource.h */; };
C22536B5241A318900192740 /* ffitarget.h in Headers */ = {isa = PBXBuildFile; fileRef = C22536B0241A318900192740 /* ffitarget.h */; };
Expand Down Expand Up @@ -391,6 +393,7 @@
dstSubfolderSpec = 10;
files = (
C20525802577D6F900C12A5C /* NativeScript.framework in Embed Frameworks */,
2B5088A82BBEC1BC00F6EB68 /* TNSWidgets.xcframework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -848,7 +851,7 @@
buildActionMask = 2147483647;
files = (
C205257F2577D6F900C12A5C /* NativeScript.framework in Frameworks */,
C20525A82577D86600C12A5C /* TNSWidgets.xcframework in Frameworks */,
2B5088A72BBEC1BC00F6EB68 /* TNSWidgets.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1834,6 +1837,7 @@
files = (
C27E5DB522F3206B00498ED0 /* app in Resources */,
C27E5DBA22F324C200498ED0 /* [email protected] in Resources */,
2B5088A62BBEB92300F6EB68 /* metadata-arm64.bin in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 1b18e9c

Please sign in to comment.