Skip to content
Permalink
Browse files

core, bugfix: check value before ToLocalChecked.

  • Loading branch information...
xicilion committed Sep 28, 2018
1 parent e810e20 commit 9be8689cb9b7629b10c20ba1daa9b3453b3f7a3e
Showing with 30 additions and 16 deletions.
  1. +8 −5 fibjs/include/JSHandler.h
  2. +7 −3 fibjs/include/object.h
  3. +8 −5 fibjs/src/mq/mq.cpp
  4. +7 −3 fibjs/src/sandbox/SandBox_require.cpp
@@ -62,12 +62,15 @@ class JSHandler : public Handler_base {
}

Isolate* isolate = Isolate::current();
v8::Local<v8::Value> _async = o->GetPrivate(o->CreationContext(),
v8::Private::ForApi(isolate->m_isolate, isolate->NewString("_async")))
.ToLocalChecked();
v8::MaybeLocal<v8::Value> mv = o->GetPrivate(o->CreationContext(),
v8::Private::ForApi(isolate->m_isolate, isolate->NewString("_async")));

if (!IsEmpty(_async))
retVal = new JSHandler(_async, true);
v8::Local<v8::Value> v;
if (!mv.IsEmpty())
v = mv.ToLocalChecked();

if (!IsEmpty(v))
retVal = new JSHandler(v, true);
else
retVal = new JSHandler(hdlr);

@@ -288,9 +288,13 @@ class object_base : public obj_base {
v8::Local<v8::Object> o = wrap();
Isolate* isolate = holder();

return o->GetPrivate(o->CreationContext(),
v8::Private::ForApi(isolate->m_isolate, isolate->NewString(key)))
.ToLocalChecked();
v8::MaybeLocal<v8::Value> mv = o->GetPrivate(o->CreationContext(),
v8::Private::ForApi(isolate->m_isolate, isolate->NewString(key)));

if (mv.IsEmpty())
return v8::Undefined(isolate->m_isolate);

return mv.ToLocalChecked();
}

void SetPrivate(exlib::string key, v8::Local<v8::Value> value)
@@ -47,12 +47,15 @@ result_t Handler_base::_new(v8::Local<v8::Function> hdlr, obj_ptr<Handler_base>&
v8::Local<v8::Object> This)
{
Isolate* isolate = Isolate::current();
v8::Local<v8::Value> _async = hdlr->GetPrivate(hdlr->CreationContext(),
v8::Private::ForApi(isolate->m_isolate, isolate->NewString("_async")))
.ToLocalChecked();
v8::MaybeLocal<v8::Value> mv = hdlr->GetPrivate(hdlr->CreationContext(),
v8::Private::ForApi(isolate->m_isolate, isolate->NewString("_async")));

if (!IsEmpty(_async))
retVal = new JSHandler(_async, true);
v8::Local<v8::Value> v;
if (!mv.IsEmpty())
v = mv.ToLocalChecked();

if (!IsEmpty(v))
retVal = new JSHandler(v, true);
else
retVal = new JSHandler(hdlr);

@@ -22,10 +22,14 @@ v8::Local<v8::Value> SandBox::get_module(v8::Local<v8::Object> mods, exlib::stri
return m;

v8::Local<v8::Object> module = v8::Local<v8::Object>::Cast(m);
v8::Local<v8::Value> v = module->GetPrivate(module->CreationContext(),
v8::Private::ForApi(isolate->m_isolate, strEntry))
.ToLocalChecked();
v8::Local<v8::Value> o = module->Get(strExports);

v8::MaybeLocal<v8::Value> mv = module->GetPrivate(module->CreationContext(),
v8::Private::ForApi(isolate->m_isolate, strEntry));
if (mv.IsEmpty())
return o;

v8::Local<v8::Value> v = mv.ToLocalChecked();
if (!o->IsUndefined() || !v->IsFunction())
return o;

0 comments on commit 9be8689

Please sign in to comment.
You can’t perform that action at this time.