diff --git a/src/jsc/jsc_protected.hpp b/src/jsc/jsc_protected.hpp index 39a8e198..6c20d039 100644 --- a/src/jsc/jsc_protected.hpp +++ b/src/jsc/jsc_protected.hpp @@ -28,6 +28,7 @@ class Protected { JSGlobalContextRef m_context; public: + Protected() : m_context(nullptr) {} Protected(const Protected &other) : Protected(other.m_context) {} Protected(Protected &&other) : m_context(other.m_context) { other.m_context = nullptr; @@ -43,6 +44,9 @@ class Protected { operator JSGlobalContextRef() const { return m_context; } + operator bool() const { + return m_context != nullptr; + } }; template<> @@ -51,6 +55,7 @@ class Protected { JSValueRef m_value; public: + Protected() {} Protected(const Protected &other) : Protected(other.m_context, other.m_value) {} Protected(Protected &&other) : m_context(other.m_context), m_value(other.m_value) { other.m_context = nullptr; @@ -67,11 +72,15 @@ class Protected { operator JSValueRef() const { return m_value; } + operator bool() const { + return m_value != nullptr; + } }; template<> class Protected : public Protected { public: + Protected() : Protected() {} Protected(const Protected &other) : Protected(other) {} Protected(Protected &&other) : Protected(std::move(other)) {} Protected(JSContextRef ctx, JSObjectRef value) : Protected(ctx, value) {} diff --git a/src/node/node_protected.hpp b/src/node/node_protected.hpp index 7ae354f1..042a10a1 100644 --- a/src/node/node_protected.hpp +++ b/src/node/node_protected.hpp @@ -29,11 +29,15 @@ class Protected { Nan::Persistent> m_value; public: + Protected() {} Protected(v8::Local value) : m_value(value) {} operator v8::Local() const { return Nan::New(m_value); } + operator bool() const { + return m_value.isEmpty(); + } bool operator==(const v8::Local &other) const { return m_value == other; } @@ -55,6 +59,7 @@ namespace js { template<> class Protected : public node::Protected { public: + Protected() : node::Protected() {} Protected(v8::Local ctx) : node::Protected(ctx) {} operator v8::Isolate*() const { @@ -65,18 +70,21 @@ class Protected : public node::Protected class Protected : public node::Protected { public: + Protected() : node::Protected() {} Protected(v8::Isolate* isolate, v8::Local value) : node::Protected(value) {} }; template<> class Protected : public node::Protected { public: + Protected() : node::Protected() {} Protected(v8::Isolate* isolate, v8::Local object) : node::Protected(object) {} }; template<> class Protected : public node::Protected { public: + Protected() : node::Protected() {} Protected(v8::Isolate* isolate, v8::Local object) : node::Protected(object) {} };