Skip to content

Commit 6d81fc2

Browse files
committed
fix: hold lwnode.dat file handle when the runtime start
Signed-off-by: Hosung Kim [email protected]
1 parent 6738e53 commit 6d81fc2

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

deps/node/src/lwnode/lwnode-public.cc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
#include "trace.h"
2727
#include "v8.h"
2828

29+
namespace node {
30+
namespace native_module {
31+
extern bool initializeLWNodeBuiltinFile();
32+
}
33+
} // namespace node
34+
2935
using namespace node;
3036

3137
namespace lwnode {
@@ -47,10 +53,29 @@ class Runtime::Internal {
4753
kReleased
4854
};
4955

56+
enum ExitCode {
57+
kSuccess = 0,
58+
kFailure = 1,
59+
kNoBuiltinFile = 100,
60+
};
61+
62+
Internal() {
63+
LWNODE_DEV_LOG("[Runtime::Internal::Internal] new");
64+
65+
// Ensure that builtin file is loaded before initializing node.
66+
native_module::initializeLWNodeBuiltinFile();
67+
}
68+
5069
std::pair<bool, int> Init(int argc, char** argv) {
5170
if (state_ != State::kNotInitialized) {
5271
LWNODE_DEV_LOG("[Runtime::Internal::Init] already initialized");
53-
return std::make_pair(false, -1);
72+
return std::make_pair(true, ExitCode::kFailure);
73+
}
74+
75+
if (!native_module::initializeLWNodeBuiltinFile()) {
76+
LWNODE_DEV_LOG(
77+
"[Runtime::Internal::Init] failed to initialize builtin file");
78+
return std::make_pair(true, ExitCode::kNoBuiltinFile);
5479
}
5580

5681
LWNODE_DEV_LOG("[Runtime::Internal::Init]");

deps/node/src/node_main_lw_runner-inl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class LWNodeMainRunner {
214214

215215
v8::V8::ShutdownPlatform();
216216

217+
environment_ = nullptr;
217218
return exit_code;
218219
}
219220

deps/node/src/node_native_module_lwnode-inl.h

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ std::string getSelfProcPath() {
8686
return std::string(path);
8787
}
8888

89+
static std::string getExternalBuiltinsPath() {
90+
static std::string s_externalBuiltinsPath;
91+
if (s_externalBuiltinsPath.empty()) {
92+
std::string executablePath = getSelfProcPath();
93+
executablePath = executablePath.substr(0, executablePath.rfind('/') + 1);
94+
s_externalBuiltinsPath = executablePath + LWNODE_EXTERNAL_BUILTINS_FILENAME;
95+
}
96+
return s_externalBuiltinsPath;
97+
}
98+
99+
bool initializeLWNodeBuiltinFile() {
100+
#ifdef LWNODE_EXTERNAL_BUILTINS_FILENAME
101+
std::string externalBuiltinsPath = getExternalBuiltinsPath();
102+
103+
if (s_archiveFileScope.isFileOpened() == false) {
104+
s_archiveFileScope.open(externalBuiltinsPath.c_str());
105+
}
106+
107+
return s_archiveFileScope.isFileOpened();
108+
#else
109+
return true;
110+
#endif
111+
}
112+
89113
void setError(ReaderError error) {
90114
s_lastError = error;
91115
ERROR_AND_ABORT(s_lastError);
@@ -197,16 +221,8 @@ FileData readFileFromArchive(std::string filename,
197221
size_t bufferSize = 0;
198222
char* buffer = nullptr;
199223

200-
static std::string s_externalBuiltinsPath;
201-
202-
if (s_externalBuiltinsPath.empty()) {
203-
std::string executablePath = getSelfProcPath();
204-
executablePath = executablePath.substr(0, executablePath.rfind('/') + 1);
205-
s_externalBuiltinsPath = executablePath + LWNODE_EXTERNAL_BUILTINS_FILENAME;
206-
}
207-
208224
if (readFileFromArchive(
209-
s_externalBuiltinsPath, filename, &buffer, &bufferSize) == false) {
225+
getExternalBuiltinsPath(), filename, &buffer, &bufferSize) == false) {
210226
setError(ReaderError::READ_FILE_FROMARCHIVE);
211227
return FileData();
212228
}

include/lwnode/lwnode-version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818

1919
#define LWNODE_VERSION_MAJOR 1
2020
#define LWNODE_VERSION_MINOR 0
21-
#define LWNODE_VERSION_PATCH 10
22-
#define LWNODE_VERSION_TAG "v1.0.10"
21+
#define LWNODE_VERSION_PATCH 11
22+
#define LWNODE_VERSION_TAG "v1.0.11"

0 commit comments

Comments
 (0)