1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include "common/test_helper.h"
#include "napi.h"
using namespace Napi;
#define TYPE_CAST_TYPES(V) \
V(Boolean) \
V(Number) \
V(BigInt) \
V(Date) \
V(String) \
V(Symbol) \
V(Object) \
V(Array) \
V(ArrayBuffer) \
V(TypedArray) \
V(DataView) \
V(Function) \
V(Promise)
// The following types are tested individually.
// External
// TypedArrayOf
// Buffer
namespace {
#define V(Type) \
void TypeCast##Type(const CallbackInfo& info) { USE(info[0].As<Type>()); }
TYPE_CAST_TYPES(V)
#undef V
void TypeCastBuffer(const CallbackInfo& info) {
USE(info[0].As<Buffer<uint8_t>>());
}
void TypeCastExternal(const CallbackInfo& info) {
USE(info[0].As<External<void>>());
}
void TypeCastTypeArrayOfUint8(const CallbackInfo& info) {
USE(info[0].As<TypedArrayOf<uint8_t>>());
}
} // namespace
Object InitValueTypeCast(Env env, Object exports) {
exports["external"] = External<void>::New(env, nullptr);
#define V(Type) exports["typeCast" #Type] = Function::New(env, TypeCast##Type);
TYPE_CAST_TYPES(V)
#undef V
exports["typeCastBuffer"] = Function::New(env, TypeCastBuffer);
exports["typeCastExternal"] = Function::New(env, TypeCastExternal);
exports["typeCastTypeArrayOfUint8"] =
Function::New(env, TypeCastTypeArrayOfUint8);
return exports;
}
NODE_API_MODULE(addon, InitValueTypeCast)
|