forked from nodejs/node-addon-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: nodejs#333
- Loading branch information
Gabriel Schulhof
committed
Sep 26, 2018
1 parent
fd3c37b
commit 7f0a628
Showing
10 changed files
with
779 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
#ifndef SRC_NAPI_INL_DEPRECATED_H_ | ||
#define SRC_NAPI_INL_DEPRECATED_H_ | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// PropertyDescriptor class | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
template <typename Getter> | ||
inline PropertyDescriptor | ||
PropertyDescriptor::Accessor(const char* utf8name, | ||
Getter getter, | ||
napi_property_attributes attributes, | ||
void* /*data*/) { | ||
typedef details::CallbackData<Getter, Napi::Value> CbData; | ||
// TODO: Delete when the function is destroyed | ||
auto callbackData = new CbData({ getter, nullptr }); | ||
|
||
return PropertyDescriptor({ | ||
utf8name, | ||
nullptr, | ||
nullptr, | ||
CbData::Wrapper, | ||
nullptr, | ||
nullptr, | ||
attributes, | ||
callbackData | ||
}); | ||
} | ||
|
||
template <typename Getter> | ||
inline PropertyDescriptor PropertyDescriptor::Accessor(const std::string& utf8name, | ||
Getter getter, | ||
napi_property_attributes attributes, | ||
void* data) { | ||
return Accessor(utf8name.c_str(), getter, attributes, data); | ||
} | ||
|
||
template <typename Getter> | ||
inline PropertyDescriptor PropertyDescriptor::Accessor(napi_value name, | ||
Getter getter, | ||
napi_property_attributes attributes, | ||
void* /*data*/) { | ||
typedef details::CallbackData<Getter, Napi::Value> CbData; | ||
// TODO: Delete when the function is destroyed | ||
auto callbackData = new CbData({ getter, nullptr }); | ||
|
||
return PropertyDescriptor({ | ||
nullptr, | ||
name, | ||
nullptr, | ||
CbData::Wrapper, | ||
nullptr, | ||
nullptr, | ||
attributes, | ||
callbackData | ||
}); | ||
} | ||
|
||
template <typename Getter> | ||
inline PropertyDescriptor PropertyDescriptor::Accessor(Name name, | ||
Getter getter, | ||
napi_property_attributes attributes, | ||
void* data) { | ||
napi_value nameValue = name; | ||
return PropertyDescriptor::Accessor(nameValue, getter, attributes, data); | ||
} | ||
|
||
template <typename Getter, typename Setter> | ||
inline PropertyDescriptor PropertyDescriptor::Accessor(const char* utf8name, | ||
Getter getter, | ||
Setter setter, | ||
napi_property_attributes attributes, | ||
void* /*data*/) { | ||
typedef details::AccessorCallbackData<Getter, Setter> CbData; | ||
// TODO: Delete when the function is destroyed | ||
auto callbackData = new CbData({ getter, setter }); | ||
|
||
return PropertyDescriptor({ | ||
utf8name, | ||
nullptr, | ||
nullptr, | ||
CbData::GetterWrapper, | ||
CbData::SetterWrapper, | ||
nullptr, | ||
attributes, | ||
callbackData | ||
}); | ||
} | ||
|
||
template <typename Getter, typename Setter> | ||
inline PropertyDescriptor PropertyDescriptor::Accessor(const std::string& utf8name, | ||
Getter getter, | ||
Setter setter, | ||
napi_property_attributes attributes, | ||
void* data) { | ||
return Accessor(utf8name.c_str(), getter, setter, attributes, data); | ||
} | ||
|
||
template <typename Getter, typename Setter> | ||
inline PropertyDescriptor PropertyDescriptor::Accessor(napi_value name, | ||
Getter getter, | ||
Setter setter, | ||
napi_property_attributes attributes, | ||
void* /*data*/) { | ||
typedef details::AccessorCallbackData<Getter, Setter> CbData; | ||
// TODO: Delete when the function is destroyed | ||
auto callbackData = new CbData({ getter, setter }); | ||
|
||
return PropertyDescriptor({ | ||
nullptr, | ||
name, | ||
nullptr, | ||
CbData::GetterWrapper, | ||
CbData::SetterWrapper, | ||
nullptr, | ||
attributes, | ||
callbackData | ||
}); | ||
} | ||
|
||
template <typename Getter, typename Setter> | ||
inline PropertyDescriptor PropertyDescriptor::Accessor(Name name, | ||
Getter getter, | ||
Setter setter, | ||
napi_property_attributes attributes, | ||
void* data) { | ||
napi_value nameValue = name; | ||
return PropertyDescriptor::Accessor(nameValue, getter, setter, attributes, data); | ||
} | ||
|
||
template <typename Callable> | ||
inline PropertyDescriptor PropertyDescriptor::Function(const char* utf8name, | ||
Callable cb, | ||
napi_property_attributes attributes, | ||
void* /*data*/) { | ||
typedef decltype(cb(CallbackInfo(nullptr, nullptr))) ReturnType; | ||
typedef details::CallbackData<Callable, ReturnType> CbData; | ||
// TODO: Delete when the function is destroyed | ||
auto callbackData = new CbData({ cb, nullptr }); | ||
|
||
return PropertyDescriptor({ | ||
utf8name, | ||
nullptr, | ||
CbData::Wrapper, | ||
nullptr, | ||
nullptr, | ||
nullptr, | ||
attributes, | ||
callbackData | ||
}); | ||
} | ||
|
||
template <typename Callable> | ||
inline PropertyDescriptor PropertyDescriptor::Function(const std::string& utf8name, | ||
Callable cb, | ||
napi_property_attributes attributes, | ||
void* data) { | ||
return Function(utf8name.c_str(), cb, attributes, data); | ||
} | ||
|
||
template <typename Callable> | ||
inline PropertyDescriptor PropertyDescriptor::Function(napi_value name, | ||
Callable cb, | ||
napi_property_attributes attributes, | ||
void* /*data*/) { | ||
typedef decltype(cb(CallbackInfo(nullptr, nullptr))) ReturnType; | ||
typedef details::CallbackData<Callable, ReturnType> CbData; | ||
// TODO: Delete when the function is destroyed | ||
auto callbackData = new CbData({ cb, nullptr }); | ||
|
||
return PropertyDescriptor({ | ||
nullptr, | ||
name, | ||
CbData::Wrapper, | ||
nullptr, | ||
nullptr, | ||
nullptr, | ||
attributes, | ||
callbackData | ||
}); | ||
} | ||
|
||
template <typename Callable> | ||
inline PropertyDescriptor PropertyDescriptor::Function(Name name, | ||
Callable cb, | ||
napi_property_attributes attributes, | ||
void* data) { | ||
napi_value nameValue = name; | ||
return PropertyDescriptor::Function(nameValue, cb, attributes, data); | ||
} | ||
|
||
#endif // !SRC_NAPI_INL_DEPRECATED_H_ |
Oops, something went wrong.