|
47 | 47 | #define NODE_18_0_MODULE_VERSION 108 |
48 | 48 | #define NODE_19_0_MODULE_VERSION 111 |
49 | 49 | #define NODE_20_0_MODULE_VERSION 115 |
| 50 | +#define NODE_21_0_MODULE_VERSION 120 |
| 51 | +#define NODE_22_0_MODULE_VERSION 127 |
| 52 | +#define NODE_23_0_MODULE_VERSION 131 |
| 53 | +#define NODE_24_0_MODULE_VERSION 137 |
| 54 | +#define NODE_25_0_MODULE_VERSION 141 |
50 | 55 |
|
51 | 56 | #ifdef _MSC_VER |
52 | 57 | # define NAN_HAS_CPLUSPLUS_11 (_MSC_VER >= 1800) |
@@ -2414,6 +2419,33 @@ enum Encoding {ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER}; |
2414 | 2419 | # include "nan_string_bytes.h" // NOLINT(build/include) |
2415 | 2420 | #endif |
2416 | 2421 |
|
| 2422 | +#if NODE_MAJOR_VERSION >= 24 |
| 2423 | +inline MaybeLocal<v8::Value> TryEncode( |
| 2424 | + const void *buf, size_t len, enum Encoding encoding = BINARY) { |
| 2425 | + v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 2426 | + node::encoding node_enc = static_cast<node::encoding>(encoding); |
| 2427 | + |
| 2428 | + if (encoding == UCS2) { |
| 2429 | + return node::TryEncode( |
| 2430 | + isolate |
| 2431 | + , reinterpret_cast<const uint16_t *>(buf) |
| 2432 | + , len / 2); |
| 2433 | + } else { |
| 2434 | + return node::TryEncode( |
| 2435 | + isolate |
| 2436 | + , reinterpret_cast<const char *>(buf) |
| 2437 | + , len |
| 2438 | + , node_enc); |
| 2439 | + } |
| 2440 | +} |
| 2441 | + |
| 2442 | +inline v8::Local<v8::Value> Encode( |
| 2443 | + const void *buf, size_t len, enum Encoding encoding = BINARY) { |
| 2444 | + return TryEncode(buf, len, encoding).ToLocalChecked(); |
| 2445 | +} |
| 2446 | + |
| 2447 | +#else |
| 2448 | + |
2417 | 2449 | inline v8::Local<v8::Value> Encode( |
2418 | 2450 | const void *buf, size_t len, enum Encoding encoding = BINARY) { |
2419 | 2451 | #if (NODE_MODULE_VERSION >= ATOM_0_21_MODULE_VERSION) |
@@ -2445,6 +2477,7 @@ inline v8::Local<v8::Value> Encode( |
2445 | 2477 | # endif |
2446 | 2478 | #endif |
2447 | 2479 | } |
| 2480 | +#endif |
2448 | 2481 |
|
2449 | 2482 | inline ssize_t DecodeBytes( |
2450 | 2483 | v8::Local<v8::Value> val, enum Encoding encoding = BINARY) { |
|
0 commit comments