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