Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8a8c792
test: http2 client setNextStreamID errors
trivikr Feb 18, 2018
818c2fb
deps: cherry-pick 46c4979e86 from upstream v8
bnoordhuis Feb 21, 2018
bb51e95
src: clean up process.dlopen()
bnoordhuis Feb 22, 2018
1d1a241
src: make process.dlopen() load well-known symbol
bnoordhuis Feb 22, 2018
a243961
build: fix gocvr version used for coverage
mhdawson Mar 2, 2018
bc1038a
module: fix cyclical dynamic import
bmeck Feb 23, 2018
f79d726
doc: add simple example to rename function
punteek Feb 16, 2018
d03929d
doc: new team for bundlers or delivery of Node.js
mhdawson Mar 2, 2018
0ebc7b9
deps: cherry-pick 0bcb1d6f from upstream V8
jakobkummerow Dec 5, 2017
f691777
doc: add introduced_in metadata to _toc.md
Trott Mar 4, 2018
241d1b0
doc: update cc list
BridgeAR Mar 2, 2018
ae2009d
doc: remove tentativeness in pull-requests.md
Trott Mar 4, 2018
4387a2c
doc: remove subsystem from pull request template
Trott Mar 4, 2018
c1b3a15
src: refactor GetPeerCertificate
danbev Mar 2, 2018
8116019
src: use std::unique_ptr for STACK_OF(X509)
bnoordhuis Mar 2, 2018
7fa236b
test: move require http2 to after crypto check
danbev Mar 3, 2018
823f85f
src: #include <stdio.h>" to iculslocs
srl295 Mar 5, 2018
bbeb2a5
perf_hooks: fix timing
TimothyGu Feb 25, 2018
7b4c9a4
test: add more information to assert.strictEqual
ryzokuken Mar 6, 2018
7acf21a
src: handle exceptions in env->SetImmediates
jasnell Jan 26, 2018
d8fef17
src: prevent persistent handle resource leaks
bnoordhuis Feb 21, 2018
52e1830
src: remove unnecessary Reset() calls
bnoordhuis Feb 21, 2018
c5f3d78
src: don't touch js object in Http2Session dtor
bnoordhuis Feb 21, 2018
759b210
http2: no stream destroy while its data is on the wire
addaleax Feb 26, 2018
0d28e9c
util: use blue on non-windows systems for number
devsnek Feb 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
src: clean up process.dlopen()
Move some code around and clean up the DLib helper class as prep work
for a follow-up commit.

PR-URL: #18934
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matheus Marchini <matheus@sthima.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
bnoordhuis authored and MylesBorins committed Mar 6, 2018
commit bb51e952614d8c0ba4351ce3f9835c9145ef1cd3
114 changes: 61 additions & 53 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2472,46 +2472,62 @@ node_module* get_linked_module(const char* name) {
}

struct DLib {
std::string filename_;
std::string errmsg_;
void* handle_;
int flags_;

#ifdef __POSIX__
static const int kDefaultFlags = RTLD_LAZY;
#else
static const int kDefaultFlags = 0;
#endif

bool Open() {
handle_ = dlopen(filename_.c_str(), flags_);
if (handle_ != nullptr)
return true;
errmsg_ = dlerror();
return false;
}
inline DLib(const char* filename, int flags)
: filename_(filename), flags_(flags), handle_(nullptr) {}

void Close() {
if (handle_ != nullptr)
dlclose(handle_);
}
#else // !__POSIX__
static const int kDefaultFlags = 0;
inline bool Open();
inline void Close();

const std::string filename_;
const int flags_;
std::string errmsg_;
void* handle_;
#ifndef __POSIX__
uv_lib_t lib_;
#endif

bool Open() {
int ret = uv_dlopen(filename_.c_str(), &lib_);
if (ret == 0) {
handle_ = static_cast<void*>(lib_.handle);
return true;
}
errmsg_ = uv_dlerror(&lib_);
uv_dlclose(&lib_);
return false;
}
DISALLOW_COPY_AND_ASSIGN(DLib);
};


#ifdef __POSIX__
bool DLib::Open() {
handle_ = dlopen(filename_.c_str(), flags_);
if (handle_ != nullptr)
return true;
errmsg_ = dlerror();
return false;
}

void Close() {
uv_dlclose(&lib_);
void DLib::Close() {
if (handle_ == nullptr) return;
dlclose(handle_);
handle_ = nullptr;
}
#else // !__POSIX__
bool DLib::Open() {
int ret = uv_dlopen(filename_.c_str(), &lib_);
if (ret == 0) {
handle_ = static_cast<void*>(lib_.handle);
return true;
}
errmsg_ = uv_dlerror(&lib_);
uv_dlclose(&lib_);
return false;
}

void DLib::Close() {
if (handle_ == nullptr) return;
uv_dlclose(&lib_);
handle_ = nullptr;
}
#endif // !__POSIX__
};

// DLOpen is process.dlopen(module, filename, flags).
// Used to load 'module.node' dynamically shared objects.
Expand All @@ -2521,6 +2537,7 @@ struct DLib {
// cache that's a plain C list or hash table that's shared across contexts?
static void DLOpen(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
auto context = env->context();

CHECK_EQ(modpending, nullptr);

Expand All @@ -2530,16 +2547,21 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
}

int32_t flags = DLib::kDefaultFlags;
if (args.Length() > 2 && !args[2]->Int32Value(env->context()).To(&flags)) {
if (args.Length() > 2 && !args[2]->Int32Value(context).To(&flags)) {
return env->ThrowTypeError("flag argument must be an integer.");
}

Local<Object> module =
args[0]->ToObject(env->context()).ToLocalChecked(); // Cast
Local<Object> module;
Local<Object> exports;
Local<Value> exports_v;
if (!args[0]->ToObject(context).ToLocal(&module) ||
!module->Get(context, env->exports_string()).ToLocal(&exports_v) ||
!exports_v->ToObject(context).ToLocal(&exports)) {
return; // Exception pending.
}

node::Utf8Value filename(env->isolate(), args[1]); // Cast
DLib dlib;
dlib.filename_ = *filename;
dlib.flags_ = flags;
DLib dlib(*filename, flags);
bool is_opened = dlib.Open();

// Objects containing v14 or later modules will have registered themselves
Expand All @@ -2554,7 +2576,7 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
#ifdef _WIN32
// Windows needs to add the filename into the error message
errmsg = String::Concat(errmsg,
args[1]->ToString(env->context()).ToLocalChecked());
args[1]->ToString(context).ToLocalChecked());
#endif // _WIN32
env->isolate()->ThrowException(Exception::Error(errmsg));
return;
Expand Down Expand Up @@ -2601,22 +2623,8 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
mp->nm_link = modlist_addon;
modlist_addon = mp;

Local<String> exports_string = env->exports_string();
MaybeLocal<Value> maybe_exports =
module->Get(env->context(), exports_string);

if (maybe_exports.IsEmpty() ||
maybe_exports.ToLocalChecked()->ToObject(env->context()).IsEmpty()) {
dlib.Close();
return;
}

Local<Object> exports =
maybe_exports.ToLocalChecked()->ToObject(env->context())
.FromMaybe(Local<Object>());

if (mp->nm_context_register_func != nullptr) {
mp->nm_context_register_func(exports, module, env->context(), mp->nm_priv);
mp->nm_context_register_func(exports, module, context, mp->nm_priv);
} else if (mp->nm_register_func != nullptr) {
mp->nm_register_func(exports, module, mp->nm_priv);
} else {
Expand Down