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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include "napi.h"
#include "test_helper.h"
using namespace Napi;
namespace {
int testData = 1;
// Helpers for testing non-Javascript values.
Value CreateExternal(const CallbackInfo& info) {
return External<int>::New(info.Env(), &testData);
}
} // end anonymous namespace
static Value IsEmpty(const CallbackInfo& info) {
Value value;
return Boolean::New(info.Env(), value.IsEmpty());
}
static Value IsUndefined(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsUndefined());
}
static Value IsNull(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsNull());
}
static Value IsBoolean(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsBoolean());
}
static Value IsNumber(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsNumber());
}
static Value IsString(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsString());
}
static Value IsSymbol(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsSymbol());
}
static Value IsArray(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsArray());
}
static Value IsArrayBuffer(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsArrayBuffer());
}
static Value IsTypedArray(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsTypedArray());
}
static Value IsObject(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsObject());
}
static Value IsFunction(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsFunction());
}
static Value IsPromise(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsPromise());
}
static Value IsDataView(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsDataView());
}
static Value IsExternal(const CallbackInfo& info) {
return Boolean::New(info.Env(), info[0].IsExternal());
}
static Value ToBoolean(const CallbackInfo& info) {
return MaybeUnwrap(info[0].ToBoolean());
}
static Value ToNumber(const CallbackInfo& info) {
return MaybeUnwrap(info[0].ToNumber());
}
static Value ToString(const CallbackInfo& info) {
return MaybeUnwrap(info[0].ToString());
}
static Value ToObject(const CallbackInfo& info) {
return MaybeUnwrap(info[0].ToObject());
}
Object InitBasicTypesValue(Env env) {
Object exports = Object::New(env);
exports["isEmpty"] = Function::New(env, IsEmpty);
exports["isUndefined"] = Function::New(env, IsUndefined);
exports["isNull"] = Function::New(env, IsNull);
exports["isBoolean"] = Function::New(env, IsBoolean);
exports["isNumber"] = Function::New(env, IsNumber);
exports["isString"] = Function::New(env, IsString);
exports["isSymbol"] = Function::New(env, IsSymbol);
exports["isArray"] = Function::New(env, IsArray);
exports["isArrayBuffer"] = Function::New(env, IsArrayBuffer);
exports["isTypedArray"] = Function::New(env, IsTypedArray);
exports["isObject"] = Function::New(env, IsObject);
exports["isFunction"] = Function::New(env, IsFunction);
exports["isPromise"] = Function::New(env, IsPromise);
exports["isDataView"] = Function::New(env, IsDataView);
exports["isExternal"] = Function::New(env, IsExternal);
exports["toBoolean"] = Function::New(env, ToBoolean);
exports["toNumber"] = Function::New(env, ToNumber);
exports["toString"] = Function::New(env, ToString);
exports["toObject"] = Function::New(env, ToObject);
exports["createExternal"] = Function::New(env, CreateExternal);
return exports;
}
|