|
1 | 1 | #include "env-inl.h" |
2 | 2 | #include "node.h" |
| 3 | +#include "node_debug.h" |
3 | 4 | #include "node_external_reference.h" |
4 | 5 |
|
| 6 | +using v8::CFunction; |
5 | 7 | using v8::Context; |
6 | 8 | using v8::FunctionCallbackInfo; |
7 | 9 | using v8::Local; |
@@ -11,47 +13,59 @@ using v8::Value; |
11 | 13 | namespace node { |
12 | 14 | namespace { |
13 | 15 |
|
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 | | - } |
| 16 | +#define VALUE_METHOD_MAP(V) \ |
| 17 | + V(External) \ |
| 18 | + V(Date) \ |
| 19 | + V(ArgumentsObject) \ |
| 20 | + V(BigIntObject) \ |
| 21 | + V(BooleanObject) \ |
| 22 | + V(NumberObject) \ |
| 23 | + V(StringObject) \ |
| 24 | + V(SymbolObject) \ |
| 25 | + V(NativeError) \ |
| 26 | + V(RegExp) \ |
| 27 | + V(AsyncFunction) \ |
| 28 | + V(GeneratorFunction) \ |
| 29 | + V(GeneratorObject) \ |
| 30 | + V(Promise) \ |
| 31 | + V(Map) \ |
| 32 | + V(Set) \ |
| 33 | + V(MapIterator) \ |
| 34 | + V(SetIterator) \ |
| 35 | + V(WeakMap) \ |
| 36 | + V(WeakSet) \ |
| 37 | + V(ArrayBuffer) \ |
| 38 | + V(DataView) \ |
| 39 | + V(SharedArrayBuffer) \ |
| 40 | + V(Proxy) \ |
| 41 | + V(ModuleNamespaceObject) |
46 | 42 |
|
47 | | - VALUE_METHOD_MAP(V) |
| 43 | +#define V(type) \ |
| 44 | + static void Is##type(const FunctionCallbackInfo<Value>& args) { \ |
| 45 | + args.GetReturnValue().Set(args[0]->Is##type()); \ |
| 46 | + } \ |
| 47 | + static bool Is##type##FastApi(Local<Value> unused, Local<Value> value) { \ |
| 48 | + TRACK_V8_FAST_API_CALL("types.is" #type); \ |
| 49 | + return value->Is##type(); \ |
| 50 | + } \ |
| 51 | + static CFunction fast_is_##type##_ = CFunction::Make(Is##type##FastApi); |
| 52 | + |
| 53 | +VALUE_METHOD_MAP(V) |
48 | 54 | #undef V |
49 | 55 |
|
50 | 56 | static void IsAnyArrayBuffer(const FunctionCallbackInfo<Value>& args) { |
51 | 57 | args.GetReturnValue().Set( |
52 | 58 | args[0]->IsArrayBuffer() || args[0]->IsSharedArrayBuffer()); |
53 | 59 | } |
54 | 60 |
|
| 61 | +static bool IsAnyArrayBufferFastApi(Local<Value> unused, Local<Value> value) { |
| 62 | + TRACK_V8_FAST_API_CALL("types.isAnyArrayBuffer"); |
| 63 | + return value->IsArrayBuffer() || value->IsSharedArrayBuffer(); |
| 64 | +} |
| 65 | + |
| 66 | +static CFunction fast_is_any_array_buffer_ = |
| 67 | + CFunction::Make(IsAnyArrayBufferFastApi); |
| 68 | + |
55 | 69 | static void IsBoxedPrimitive(const FunctionCallbackInfo<Value>& args) { |
56 | 70 | args.GetReturnValue().Set( |
57 | 71 | args[0]->IsNumberObject() || |
@@ -61,27 +75,56 @@ static void IsBoxedPrimitive(const FunctionCallbackInfo<Value>& args) { |
61 | 75 | args[0]->IsSymbolObject()); |
62 | 76 | } |
63 | 77 |
|
| 78 | +static bool IsBoxedPrimitiveFastApi(Local<Value> unused, Local<Value> value) { |
| 79 | + TRACK_V8_FAST_API_CALL("types.isBoxedPrimitive"); |
| 80 | + return value->IsNumberObject() || value->IsStringObject() || |
| 81 | + value->IsBooleanObject() || value->IsBigIntObject() || |
| 82 | + value->IsSymbolObject(); |
| 83 | +} |
| 84 | + |
| 85 | +static CFunction fast_is_boxed_primitive_ = |
| 86 | + CFunction::Make(IsBoxedPrimitiveFastApi); |
| 87 | + |
64 | 88 | void InitializeTypes(Local<Object> target, |
65 | 89 | Local<Value> unused, |
66 | 90 | Local<Context> context, |
67 | 91 | void* priv) { |
68 | | -#define V(type) SetMethodNoSideEffect(context, target, "is" #type, Is##type); |
| 92 | +#define V(type) \ |
| 93 | + SetFastMethodNoSideEffect( \ |
| 94 | + context, target, "is" #type, Is##type, &fast_is_##type##_); |
| 95 | + |
69 | 96 | VALUE_METHOD_MAP(V) |
70 | 97 | #undef V |
71 | 98 |
|
72 | | - SetMethodNoSideEffect(context, target, "isAnyArrayBuffer", IsAnyArrayBuffer); |
73 | | - SetMethodNoSideEffect(context, target, "isBoxedPrimitive", IsBoxedPrimitive); |
| 99 | + SetFastMethodNoSideEffect(context, |
| 100 | + target, |
| 101 | + "isAnyArrayBuffer", |
| 102 | + IsAnyArrayBuffer, |
| 103 | + &fast_is_any_array_buffer_); |
| 104 | + SetFastMethodNoSideEffect(context, |
| 105 | + target, |
| 106 | + "isBoxedPrimitive", |
| 107 | + IsBoxedPrimitive, |
| 108 | + &fast_is_boxed_primitive_); |
74 | 109 | } |
75 | 110 |
|
76 | 111 | } // anonymous namespace |
77 | 112 |
|
78 | 113 | void RegisterTypesExternalReferences(ExternalReferenceRegistry* registry) { |
79 | | -#define V(type) registry->Register(Is##type); |
| 114 | +#define V(type) \ |
| 115 | + registry->Register(Is##type); \ |
| 116 | + registry->Register(Is##type##FastApi); \ |
| 117 | + registry->Register(fast_is_##type##_.GetTypeInfo()); |
| 118 | + |
80 | 119 | VALUE_METHOD_MAP(V) |
81 | 120 | #undef V |
82 | 121 |
|
83 | 122 | registry->Register(IsAnyArrayBuffer); |
| 123 | + registry->Register(IsAnyArrayBufferFastApi); |
| 124 | + registry->Register(fast_is_any_array_buffer_.GetTypeInfo()); |
84 | 125 | registry->Register(IsBoxedPrimitive); |
| 126 | + registry->Register(IsBoxedPrimitiveFastApi); |
| 127 | + registry->Register(fast_is_boxed_primitive_.GetTypeInfo()); |
85 | 128 | } |
86 | 129 | } // namespace node |
87 | 130 |
|
|