Skip to content
Prev Previous commit
src: return if Get or ToObject return an empty before call ToLocalChe…
…cked
  • Loading branch information
Leko committed Nov 30, 2017
commit d7cc3414fad1ebf515db7a4e36a7bc28f2ae9e88
12 changes: 11 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2366,8 +2366,18 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
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 =
module->Get(env->context(), exports_string).ToLocalChecked().As<Object>();
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);
Expand Down