mirror of
https://github.com/nodejs/node.git
synced 2025-05-11 19:50:13 +00:00

Currently there are a number of compiler warnings like the following: ../binding.cc:6:41: warning: 'NewFromUtf8' is deprecated: Use maybe version [-Wdeprecated-declarations] args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world")); ^ /node/deps/v8/include/v8.h:2883:10: note: 'NewFromUtf8' has been explicitly marked deprecated here static V8_DEPRECATE_SOON( ^ /node/deps/v8/include/v8config.h:341:29: note: expanded from macro 'V8_DEPRECATE_SOON' declarator __attribute__((deprecated(message))) ^ This commit updates the code to use the maybe versions. PR-URL: https://github.com/nodejs/node/pull/24216 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
#include <node.h>
|
|
#include <v8.h>
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <dlfcn.h>
|
|
|
|
extern "C" const char* dlopen_pong(void) {
|
|
return "pong";
|
|
}
|
|
|
|
namespace {
|
|
|
|
using v8::FunctionCallbackInfo;
|
|
using v8::Isolate;
|
|
using v8::Local;
|
|
using v8::Object;
|
|
using v8::NewStringType;
|
|
using v8::String;
|
|
using v8::Value;
|
|
|
|
typedef const char* (*ping)(void);
|
|
|
|
static ping ping_func;
|
|
|
|
void LoadLibrary(const FunctionCallbackInfo<Value>& args) {
|
|
const String::Utf8Value filename(args.GetIsolate(), args[0]);
|
|
void* handle = dlopen(*filename, RTLD_LAZY);
|
|
assert(handle != nullptr);
|
|
ping_func = reinterpret_cast<ping>(dlsym(handle, "dlopen_ping"));
|
|
assert(ping_func != nullptr);
|
|
}
|
|
|
|
void Ping(const FunctionCallbackInfo<Value>& args) {
|
|
Isolate* isolate = args.GetIsolate();
|
|
assert(ping_func != nullptr);
|
|
args.GetReturnValue().Set(String::NewFromUtf8(
|
|
isolate, ping_func(), NewStringType::kNormal).ToLocalChecked());
|
|
}
|
|
|
|
void init(Local<Object> exports) {
|
|
NODE_SET_METHOD(exports, "load", LoadLibrary);
|
|
NODE_SET_METHOD(exports, "ping", Ping);
|
|
}
|
|
|
|
NODE_MODULE(NODE_GYP_MODULE_NAME, init)
|
|
|
|
} // anonymous namespace
|
|
|
|
#endif // _WIN32
|