package.nan_maybe_43_inl.h Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nan Show documentation
Show all versions of nan Show documentation
Native Abstractions for Node.js: C++ header for Node 0.8 -> 18 compatibility
/*********************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2018 NAN contributors
*
* MIT License
********************************************************************/
#ifndef NAN_MAYBE_43_INL_H_
#define NAN_MAYBE_43_INL_H_
template
using MaybeLocal = v8::MaybeLocal;
inline
MaybeLocal ToDetailString(v8::Local val) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(val->ToDetailString(isolate->GetCurrentContext())
.FromMaybe(v8::Local()));
}
inline
MaybeLocal ToArrayIndex(v8::Local val) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(val->ToArrayIndex(isolate->GetCurrentContext())
.FromMaybe(v8::Local()));
}
inline
Maybe Equals(v8::Local a, v8::Local(b)) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return a->Equals(isolate->GetCurrentContext(), b);
}
inline
MaybeLocal NewInstance(v8::Local h) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(h->NewInstance(isolate->GetCurrentContext())
.FromMaybe(v8::Local()));
}
inline
MaybeLocal NewInstance(
v8::Local h
, int argc
, v8::Local argv[]) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(h->NewInstance(isolate->GetCurrentContext(), argc, argv)
.FromMaybe(v8::Local()));
}
inline
MaybeLocal NewInstance(v8::Local h) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(h->NewInstance(isolate->GetCurrentContext())
.FromMaybe(v8::Local()));
}
inline MaybeLocal GetFunction(
v8::Local t) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(t->GetFunction(isolate->GetCurrentContext())
.FromMaybe(v8::Local()));
}
inline Maybe Set(
v8::Local obj
, v8::Local key
, v8::Local value) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->Set(isolate->GetCurrentContext(), key, value);
}
inline Maybe Set(
v8::Local obj
, uint32_t index
, v8::Local value) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->Set(isolate->GetCurrentContext(), index, value);
}
#if NODE_MODULE_VERSION < NODE_4_0_MODULE_VERSION
#include "nan_define_own_property_helper.h" // NOLINT(build/include)
#endif
inline Maybe DefineOwnProperty(
v8::Local obj
, v8::Local key
, v8::Local value
, v8::PropertyAttribute attribs = v8::None) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
#if NODE_MODULE_VERSION >= NODE_4_0_MODULE_VERSION
return obj->DefineOwnProperty(isolate->GetCurrentContext(), key, value,
attribs);
#else
Maybe maybeCurrent =
obj->GetPropertyAttributes(isolate->GetCurrentContext(), key);
if (maybeCurrent.IsNothing()) {
return Nothing();
}
v8::PropertyAttribute current = maybeCurrent.FromJust();
return imp::DefineOwnPropertyHelper(current, obj, key, value, attribs);
#endif
}
NAN_DEPRECATED inline Maybe ForceSet(
v8::Local obj
, v8::Local key
, v8::Local value
, v8::PropertyAttribute attribs = v8::None) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
#if NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION
return key->IsName()
? obj->DefineOwnProperty(isolate->GetCurrentContext(),
key.As(), value, attribs)
: Nothing();
#else
return obj->ForceSet(isolate->GetCurrentContext(), key, value, attribs);
#endif
}
inline MaybeLocal Get(
v8::Local obj
, v8::Local key) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(obj->Get(isolate->GetCurrentContext(), key)
.FromMaybe(v8::Local()));
}
inline
MaybeLocal Get(v8::Local obj, uint32_t index) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(obj->Get(isolate->GetCurrentContext(), index)
.FromMaybe(v8::Local()));
}
inline v8::PropertyAttribute GetPropertyAttributes(
v8::Local obj
, v8::Local key) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->GetPropertyAttributes(isolate->GetCurrentContext(), key)
.FromJust();
}
inline Maybe Has(
v8::Local obj
, v8::Local key) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->Has(isolate->GetCurrentContext(), key);
}
inline Maybe Has(v8::Local obj, uint32_t index) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->Has(isolate->GetCurrentContext(), index);
}
inline Maybe Delete(
v8::Local obj
, v8::Local key) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->Delete(isolate->GetCurrentContext(), key);
}
inline
Maybe Delete(v8::Local obj, uint32_t index) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->Delete(isolate->GetCurrentContext(), index);
}
inline
MaybeLocal GetPropertyNames(v8::Local obj) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(obj->GetPropertyNames(isolate->GetCurrentContext())
.FromMaybe(v8::Local()));
}
inline
MaybeLocal GetOwnPropertyNames(v8::Local obj) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(obj->GetOwnPropertyNames(isolate->GetCurrentContext())
.FromMaybe(v8::Local()));
}
inline Maybe SetPrototype(
v8::Local obj
, v8::Local prototype) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->SetPrototype(isolate->GetCurrentContext(), prototype);
}
inline MaybeLocal ObjectProtoToString(
v8::Local obj) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(obj->ObjectProtoToString(isolate->GetCurrentContext())
.FromMaybe(v8::Local()));
}
inline Maybe HasOwnProperty(
v8::Local obj
, v8::Local key) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->HasOwnProperty(isolate->GetCurrentContext(), key);
}
inline Maybe HasRealNamedProperty(
v8::Local obj
, v8::Local key) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->HasRealNamedProperty(isolate->GetCurrentContext(), key);
}
inline Maybe HasRealIndexedProperty(
v8::Local obj
, uint32_t index) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->HasRealIndexedProperty(isolate->GetCurrentContext(), index);
}
inline Maybe HasRealNamedCallbackProperty(
v8::Local obj
, v8::Local key) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return obj->HasRealNamedCallbackProperty(isolate->GetCurrentContext(), key);
}
inline MaybeLocal GetRealNamedPropertyInPrototypeChain(
v8::Local obj
, v8::Local key) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(obj->GetRealNamedPropertyInPrototypeChain(
isolate->GetCurrentContext(), key)
.FromMaybe(v8::Local()));
}
inline MaybeLocal GetRealNamedProperty(
v8::Local obj
, v8::Local key) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(
obj->GetRealNamedProperty(isolate->GetCurrentContext(), key)
.FromMaybe(v8::Local()));
}
inline MaybeLocal CallAsFunction(
v8::Local obj
, v8::Local recv
, int argc
, v8::Local argv[]) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(
obj->CallAsFunction(isolate->GetCurrentContext(), recv, argc, argv)
.FromMaybe(v8::Local()));
}
inline MaybeLocal CallAsConstructor(
v8::Local obj
, int argc, v8::Local argv[]) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(
obj->CallAsConstructor(isolate->GetCurrentContext(), argc, argv)
.FromMaybe(v8::Local()));
}
inline
MaybeLocal GetSourceLine(v8::Local msg) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(msg->GetSourceLine(isolate->GetCurrentContext())
.FromMaybe(v8::Local()));
}
inline Maybe GetLineNumber(v8::Local msg) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return msg->GetLineNumber(isolate->GetCurrentContext());
}
inline Maybe GetStartColumn(v8::Local msg) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return msg->GetStartColumn(isolate->GetCurrentContext());
}
inline Maybe GetEndColumn(v8::Local msg) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
return msg->GetEndColumn(isolate->GetCurrentContext());
}
inline MaybeLocal CloneElementAt(
v8::Local array
, uint32_t index) {
#if (NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION)
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
v8::Local context = isolate->GetCurrentContext();
v8::Local elem;
v8::Local obj;
if (!array->Get(context, index).ToLocal(&elem)) {
return scope.Escape(obj);
}
if (!elem->ToObject(context).ToLocal(&obj)) {
return scope.Escape(v8::Local());
}
return scope.Escape(obj->Clone());
#else
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(array->CloneElementAt(isolate->GetCurrentContext(), index)
.FromMaybe(v8::Local()));
#endif
}
inline MaybeLocal Call(
v8::Local fun
, v8::Local recv
, int argc
, v8::Local argv[]) {
v8::Isolate *isolate = v8::Isolate::GetCurrent();
v8::EscapableHandleScope scope(isolate);
return scope.Escape(fun->Call(isolate->GetCurrentContext(), recv, argc, argv)
.FromMaybe(v8::Local()));
}
#endif // NAN_MAYBE_43_INL_H_
© 2015 - 2024 Weber Informatics LLC | Privacy Policy