forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspector_object_utils.cc
More file actions
102 lines (94 loc) · 3.36 KB
/
Copy pathinspector_object_utils.cc
File metadata and controls
102 lines (94 loc) · 3.36 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
#include "inspector_object_utils.h"
#include "inspector/protocol_helper.h"
#include "util-inl.h"
using v8::Boolean;
using v8::Context;
using v8::EscapableHandleScope;
using v8::HandleScope;
using v8::Int32;
using v8::Isolate;
using v8::Just;
using v8::Local;
using v8::Maybe;
using v8::MaybeLocal;
using v8::Nothing;
using v8::Number;
using v8::Object;
using v8::String;
using v8::Value;
namespace node {
namespace inspector {
// Get a protocol string property from the object.
Maybe<protocol::String> ObjectGetProtocolString(Local<Context> context,
Local<Object> object,
Local<String> property) {
HandleScope handle_scope(Isolate::GetCurrent());
Local<Value> value;
if (!object->Get(context, property).ToLocal(&value) || !value->IsString()) {
return Nothing<protocol::String>();
}
Local<String> str = value.As<String>();
return Just(ToProtocolString(Isolate::GetCurrent(), str));
}
// Get a protocol string property from the object.
Maybe<protocol::String> ObjectGetProtocolString(Local<Context> context,
Local<Object> object,
const char* property) {
HandleScope handle_scope(Isolate::GetCurrent());
return ObjectGetProtocolString(
context, object, OneByteString(Isolate::GetCurrent(), property));
}
// Get a protocol double property from the object.
Maybe<double> ObjectGetDouble(Local<Context> context,
Local<Object> object,
const char* property) {
HandleScope handle_scope(Isolate::GetCurrent());
Local<Value> value;
if (!object->Get(context, OneByteString(Isolate::GetCurrent(), property))
.ToLocal(&value) ||
!value->IsNumber()) {
return Nothing<double>();
}
return Just(value.As<Number>()->Value());
}
// Get a protocol int property from the object.
Maybe<int> ObjectGetInt(Local<Context> context,
Local<Object> object,
const char* property) {
HandleScope handle_scope(Isolate::GetCurrent());
Local<Value> value;
if (!object->Get(context, OneByteString(Isolate::GetCurrent(), property))
.ToLocal(&value) ||
!value->IsInt32()) {
return Nothing<int>();
}
return Just(value.As<Int32>()->Value());
}
// Get a protocol bool property from the object.
Maybe<bool> ObjectGetBool(Local<Context> context,
Local<Object> object,
const char* property) {
HandleScope handle_scope(Isolate::GetCurrent());
Local<Value> value;
if (!object->Get(context, OneByteString(Isolate::GetCurrent(), property))
.ToLocal(&value) ||
!value->IsBoolean()) {
return Nothing<bool>();
}
return Just(value.As<Boolean>()->Value());
}
// Get an object property from the object.
MaybeLocal<Object> ObjectGetObject(Local<Context> context,
Local<Object> object,
const char* property) {
EscapableHandleScope handle_scope(Isolate::GetCurrent());
Local<Value> value;
if (!object->Get(context, OneByteString(Isolate::GetCurrent(), property))
.ToLocal(&value) ||
!value->IsObject()) {
return {};
}
return handle_scope.Escape(value.As<Object>());
}
} // namespace inspector
} // namespace node