blob: 1889d8c304110b2c690c97df2ffd34a6809585f0 (
plain)
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
|
#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) {
Environment* env = Environment::GetCurrent(context);
#define V(type) env->SetMethodNoSideEffect(target, \
"is" #type, \
Is##type);
VALUE_METHOD_MAP(V)
#undef V
env->SetMethodNoSideEffect(target, "isAnyArrayBuffer", IsAnyArrayBuffer);
env->SetMethodNoSideEffect(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_MODULE_CONTEXT_AWARE_INTERNAL(types, node::InitializeTypes)
NODE_MODULE_EXTERNAL_REFERENCE(types, node::RegisterTypesExternalReferences)
|