forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode_types.cc
More file actions
128 lines (109 loc) Β· 5.51 KB
/
node_types.cc
File metadata and controls
128 lines (109 loc) Β· 5.51 KB
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
121
122
123
124
125
126
127
128
#include "env-inl.h"
#include "node.h"
#include "node_debug.h"
#include "node_external_reference.h"
using v8::CFunction;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::Local;
using v8::Object;
using v8::Value;
namespace node {
namespace {
#define VALUE_METHOD_MAP(V) \
V(ArgumentsObject) \
V(ArrayBuffer) \
V(AsyncFunction) \
V(BigIntObject) \
V(BooleanObject) \
V(Date) \
V(External) \
V(GeneratorFunction) \
V(GeneratorObject) \
V(Map) \
V(MapIterator) \
V(ModuleNamespaceObject) \
V(NativeError) \
V(NumberObject) \
V(Promise) \
V(Proxy) \
V(RegExp) \
V(Set) \
V(SetIterator) \
V(SharedArrayBuffer) \
V(StringObject) \
V(SymbolObject) \
V(WeakMap) \
V(WeakSet)
#define V(type) \
static void Is##type(const FunctionCallbackInfo<Value>& args) { \
args.GetReturnValue().Set(args[0]->Is##type()); \
} \
static bool Is##type##FastApi(Local<Value> unused, Local<Value> value) { \
TRACK_V8_FAST_API_CALL("types.is" #type); \
return value->Is##type(); \
} \
static CFunction fast_is_##type##_ = CFunction::Make(Is##type##FastApi);
VALUE_METHOD_MAP(V)
#undef V
static void IsAnyArrayBuffer(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(
args[0]->IsArrayBuffer() || args[0]->IsSharedArrayBuffer());
}
static bool IsAnyArrayBufferFastApi(Local<Value> unused, Local<Value> value) {
TRACK_V8_FAST_API_CALL("types.isAnyArrayBuffer");
return value->IsArrayBuffer() || value->IsSharedArrayBuffer();
}
static CFunction fast_is_any_array_buffer_ =
CFunction::Make(IsAnyArrayBufferFastApi);
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());
}
static bool IsBoxedPrimitiveFastApi(Local<Value> unused, Local<Value> value) {
TRACK_V8_FAST_API_CALL("types.isBoxedPrimitive");
return value->IsNumberObject() || value->IsStringObject() ||
value->IsBooleanObject() || value->IsBigIntObject() ||
value->IsSymbolObject();
}
static CFunction fast_is_boxed_primitive_ =
CFunction::Make(IsBoxedPrimitiveFastApi);
void InitializeTypes(Local<Object> target,
Local<Value> unused,
Local<Context> context,
void* priv) {
#define V(type) \
SetFastMethodNoSideEffect( \
context, target, "is" #type, Is##type, &fast_is_##type##_);
VALUE_METHOD_MAP(V)
#undef V
SetFastMethodNoSideEffect(context,
target,
"isAnyArrayBuffer",
IsAnyArrayBuffer,
&fast_is_any_array_buffer_);
SetFastMethodNoSideEffect(context,
target,
"isBoxedPrimitive",
IsBoxedPrimitive,
&fast_is_boxed_primitive_);
}
} // anonymous namespace
void RegisterTypesExternalReferences(ExternalReferenceRegistry* registry) {
#define V(type) \
registry->Register(Is##type); \
registry->Register(fast_is_##type##_);
VALUE_METHOD_MAP(V)
#undef V
registry->Register(IsAnyArrayBuffer);
registry->Register(fast_is_any_array_buffer_);
registry->Register(IsBoxedPrimitive);
registry->Register(fast_is_boxed_primitive_);
}
} // namespace node
NODE_BINDING_CONTEXT_AWARE_INTERNAL(types, node::InitializeTypes)
NODE_BINDING_EXTERNAL_REFERENCE(types, node::RegisterTypesExternalReferences)