Skip to content

Commit 5676459

Browse files
committed
Fix build on older versions
1 parent 1ee6ed1 commit 5676459

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

module.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <future>
33
#include <mutex>
44
#include <node.h>
5+
#include <node_version.h>
56

67
// Platform-specific includes for time functions
78
#ifdef _WIN32
@@ -97,6 +98,7 @@ JsStackFrames GetStackFrames(Isolate *isolate) {
9798
return frames;
9899
}
99100

101+
#if NODE_MAJOR_VERSION >= 22
100102
static std::string ToJSONOrEmpty(Isolate *isolate, v8::Local<v8::Value> value) {
101103
auto context = isolate->GetCurrentContext();
102104
MaybeLocal<String> maybe_json = v8::JSON::Stringify(context, value);
@@ -109,10 +111,12 @@ static std::string ToJSONOrEmpty(Isolate *isolate, v8::Local<v8::Value> value) {
109111
}
110112
return "";
111113
}
114+
#endif
112115

113116
// Function to fetch the thread state from the async context store
114117
std::string GetThreadState(Isolate *isolate,
115118
v8::Global<v8::Value> async_local_storage) {
119+
#if NODE_MAJOR_VERSION >= 22
116120
// Node.js stores the async local storage in the isolate's
117121
// "ContinuationPreservedEmbedderData" map, keyed by the
118122
// AsyncLocalStorage instance.
@@ -129,6 +133,7 @@ std::string GetThreadState(Isolate *isolate,
129133
return ToJSONOrEmpty(isolate, val.ToLocalChecked());
130134
}
131135
}
136+
#endif
132137

133138
return "";
134139
}

0 commit comments

Comments
 (0)