This repository has been archived by the owner on Dec 14, 2024. It is now read-only.
forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnode_types.cc
89 lines (75 loc) · 3.72 KB
/
node_types.cc
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
#include "env-inl.h"
#include "node.h"
#include "node_external_reference.h"
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::Local;
using v8::Object;
using v8::Value;
namespace node {
namespace {
#define VALUE_METHOD_MAP(V) \
V(External) \
V(Date) \
V(ArgumentsObject) \
V(BigIntObject) \
V(BooleanObject) \
V(NumberObject) \
V(StringObject) \
V(SymbolObject) \
V(NativeError) \
V(RegExp) \
V(AsyncFunction) \
V(GeneratorFunction) \
V(GeneratorObject) \
V(Promise) \
V(Map) \
V(Set) \
V(MapIterator) \
V(SetIterator) \
V(WeakMap) \
V(WeakSet) \
V(ArrayBuffer) \
V(DataView) \
V(SharedArrayBuffer) \
V(Proxy) \
V(ModuleNamespaceObject) \
#define V(type) \
static void Is##type(const FunctionCallbackInfo<Value>& args) { \
args.GetReturnValue().Set(args[0]->Is##type()); \
}
VALUE_METHOD_MAP(V)
#undef V
static void IsAnyArrayBuffer(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(
args[0]->IsArrayBuffer() || args[0]->IsSharedArrayBuffer());
}
static void IsBoxedPrimitive(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(
args[0]->IsNumberObject() ||
args[0]->IsStringObject() ||
args[0]->IsBooleanObject() ||
args[0]->IsBigIntObject() ||
args[0]->IsSymbolObject());
}
void InitializeTypes(Local<Object> target,
Local<Value> unused,
Local<Context> context,
void* priv) {
#define V(type) SetMethodNoSideEffect(context, target, "is" #type, Is##type);
VALUE_METHOD_MAP(V)
#undef V
SetMethodNoSideEffect(context, target, "isAnyArrayBuffer", IsAnyArrayBuffer);
SetMethodNoSideEffect(context, target, "isBoxedPrimitive", IsBoxedPrimitive);
}
} // anonymous namespace
void RegisterTypesExternalReferences(ExternalReferenceRegistry* registry) {
#define V(type) registry->Register(Is##type);
VALUE_METHOD_MAP(V)
#undef V
registry->Register(IsAnyArrayBuffer);
registry->Register(IsBoxedPrimitive);
}
} // namespace node
NODE_BINDING_CONTEXT_AWARE_INTERNAL(types, node::InitializeTypes)
NODE_BINDING_EXTERNAL_REFERENCE(types, node::RegisterTypesExternalReferences)