1 #include "env-inl.h"
2 #include "node.h"
3
4 using v8::Context;
5 using v8::FunctionCallbackInfo;
6 using v8::Local;
7 using v8::Object;
8 using v8::Value;
9
10 namespace node {
11 namespace {
12
13 #define VALUE_METHOD_MAP(V) \
14 V(External) \
15 V(Date) \
16 V(ArgumentsObject) \
17 V(BigIntObject) \
18 V(BooleanObject) \
19 V(NumberObject) \
20 V(StringObject) \
21 V(SymbolObject) \
22 V(NativeError) \
23 V(RegExp) \
24 V(AsyncFunction) \
25 V(GeneratorFunction) \
26 V(GeneratorObject) \
27 V(Promise) \
28 V(Map) \
29 V(Set) \
30 V(MapIterator) \
31 V(SetIterator) \
32 V(WeakMap) \
33 V(WeakSet) \
34 V(ArrayBuffer) \
35 V(DataView) \
36 V(SharedArrayBuffer) \
37 V(Proxy) \
38 V(ModuleNamespaceObject) \
39
40
41 #define V(type) \
42 static void Is##type(const FunctionCallbackInfo<Value>& args) { \
43 args.GetReturnValue().Set(args[0]->Is##type()); \
44 }
45
VALUE_METHOD_MAP(V)46 VALUE_METHOD_MAP(V)
47 #undef V
48
49 static void IsAnyArrayBuffer(const FunctionCallbackInfo<Value>& args) {
50 args.GetReturnValue().Set(
51 args[0]->IsArrayBuffer() || args[0]->IsSharedArrayBuffer());
52 }
53
IsBoxedPrimitive(const FunctionCallbackInfo<Value> & args)54 static void IsBoxedPrimitive(const FunctionCallbackInfo<Value>& args) {
55 args.GetReturnValue().Set(
56 args[0]->IsNumberObject() ||
57 args[0]->IsStringObject() ||
58 args[0]->IsBooleanObject() ||
59 args[0]->IsBigIntObject() ||
60 args[0]->IsSymbolObject());
61 }
62
InitializeTypes(Local<Object> target,Local<Value> unused,Local<Context> context,void * priv)63 void InitializeTypes(Local<Object> target,
64 Local<Value> unused,
65 Local<Context> context,
66 void* priv) {
67 Environment* env = Environment::GetCurrent(context);
68
69 #define V(type) env->SetMethodNoSideEffect(target, \
70 "is" #type, \
71 Is##type);
72 VALUE_METHOD_MAP(V)
73 #undef V
74
75 env->SetMethodNoSideEffect(target, "isAnyArrayBuffer", IsAnyArrayBuffer);
76 env->SetMethodNoSideEffect(target, "isBoxedPrimitive", IsBoxedPrimitive);
77 }
78
79 } // anonymous namespace
80 } // namespace node
81
82 NODE_MODULE_CONTEXT_AWARE_INTERNAL(types, node::InitializeTypes)
83