@contrast/agent 4.4.1 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/VERSION +1 -1
- package/bin/linux/contrast-service +0 -0
- package/bin/mac/contrast-service +0 -0
- package/bin/windows/contrast-service.exe +0 -0
- package/lib/assess/hapi/route-coverage.js +3 -3
- package/lib/assess/membrane/index.js +2 -8
- package/lib/assess/membrane/source-membrane.js +3 -4
- package/lib/assess/models/base-event.js +2 -2
- package/lib/assess/models/call-context.js +0 -3
- package/lib/assess/policy/propagators.json +20 -0
- package/lib/assess/policy/signatures.json +103 -0
- package/lib/assess/propagators/path/common.js +165 -36
- package/lib/assess/propagators/path/join.js +5 -1
- package/lib/assess/propagators/path/normalize.js +5 -1
- package/lib/assess/propagators/path/resolve.js +11 -2
- package/lib/assess/response-scanning/autocomplete-missing.js +0 -2
- package/lib/assess/response-scanning/parameter-pollution.js +0 -2
- package/lib/core/arch-components/dynamodb.js +1 -2
- package/lib/core/arch-components/dynamodbv3.js +44 -0
- package/lib/core/arch-components/index.js +1 -0
- package/lib/core/async-storage/hooks/bluebird.js +20 -0
- package/lib/core/config/options.js +3 -2
- package/lib/core/express/utils.js +1 -1
- package/lib/core/logger/debug-logger.js +15 -17
- package/lib/core/stacktrace.js +3 -4
- package/lib/feature-set.js +2 -1
- package/lib/hooks/encoding.js +1 -1
- package/lib/hooks/frameworks/base.js +8 -2
- package/lib/hooks/frameworks/http.js +23 -16
- package/lib/hooks/frameworks/http2.js +73 -0
- package/lib/hooks/frameworks/index.js +8 -3
- package/lib/hooks/http.js +112 -128
- package/lib/hooks/patcher.js +10 -12
- package/lib/hooks/require.js +16 -22
- package/lib/instrumentation.js +0 -3
- package/lib/protect/analysis/aho-corasick.js +13 -30
- package/lib/protect/rules/cmd-injection-command-backdoors/backdoor-detector.js +3 -3
- package/lib/protect/rules/signatures/reflected-xss/helpers/function-call.js +1 -1
- package/lib/protect/rules/xss/helpers/function-call.js +1 -1
- package/lib/util/clean-stack.js +1 -1
- package/lib/util/clean-string/brackets.js +3 -3
- package/lib/util/clean-string/concatenations.js +1 -1
- package/lib/util/clean-string/util.js +1 -2
- package/lib/util/ip-analyzer.js +1 -1
- package/lib/util/some.js +27 -0
- package/lib/util/xml-analyzer/external-entity-finder.js +1 -1
- package/package.json +14 -15
- package/lib/hooks/frameworks/https.js +0 -42
- package/node_modules/bindings/LICENSE.md +0 -22
- package/node_modules/bindings/README.md +0 -98
- package/node_modules/bindings/bindings.js +0 -221
- package/node_modules/bindings/package.json +0 -32
- package/node_modules/file-uri-to-path/.npmignore +0 -1
- package/node_modules/file-uri-to-path/.travis.yml +0 -30
- package/node_modules/file-uri-to-path/History.md +0 -21
- package/node_modules/file-uri-to-path/LICENSE +0 -20
- package/node_modules/file-uri-to-path/README.md +0 -74
- package/node_modules/file-uri-to-path/index.d.ts +0 -2
- package/node_modules/file-uri-to-path/index.js +0 -66
- package/node_modules/file-uri-to-path/package.json +0 -36
- package/node_modules/file-uri-to-path/test/test.js +0 -24
- package/node_modules/file-uri-to-path/test/tests.json +0 -13
- package/node_modules/glossy/LICENSE +0 -19
- package/node_modules/glossy/README.md +0 -129
- package/node_modules/glossy/index.js +0 -12
- package/node_modules/glossy/lib/glossy/parse.js +0 -520
- package/node_modules/glossy/lib/glossy/produce.js +0 -459
- package/node_modules/glossy/package.json +0 -47
- package/node_modules/glossy/test/decide.js +0 -7
- package/node_modules/glossy/test/decode_pri.js +0 -24
- package/node_modules/glossy/test/parse_3164.js +0 -104
- package/node_modules/glossy/test/parse_5424.js +0 -106
- package/node_modules/glossy/test/parse_5848.js +0 -40
- package/node_modules/glossy/test/parse_8601.js +0 -14
- package/node_modules/glossy/test/parse_rfc3339.js +0 -9
- package/node_modules/glossy/test/produce.js +0 -162
- package/node_modules/glossy/test/runner.js +0 -40
- package/node_modules/glossy/test/structure_data.js +0 -24
- package/node_modules/nan/CHANGELOG.md +0 -537
- package/node_modules/nan/LICENSE.md +0 -13
- package/node_modules/nan/README.md +0 -455
- package/node_modules/nan/doc/asyncworker.md +0 -146
- package/node_modules/nan/doc/buffers.md +0 -54
- package/node_modules/nan/doc/callback.md +0 -76
- package/node_modules/nan/doc/converters.md +0 -41
- package/node_modules/nan/doc/errors.md +0 -226
- package/node_modules/nan/doc/json.md +0 -62
- package/node_modules/nan/doc/maybe_types.md +0 -583
- package/node_modules/nan/doc/methods.md +0 -664
- package/node_modules/nan/doc/new.md +0 -147
- package/node_modules/nan/doc/node_misc.md +0 -123
- package/node_modules/nan/doc/object_wrappers.md +0 -263
- package/node_modules/nan/doc/persistent.md +0 -296
- package/node_modules/nan/doc/scopes.md +0 -73
- package/node_modules/nan/doc/script.md +0 -38
- package/node_modules/nan/doc/string_bytes.md +0 -62
- package/node_modules/nan/doc/v8_internals.md +0 -199
- package/node_modules/nan/doc/v8_misc.md +0 -85
- package/node_modules/nan/include_dirs.js +0 -1
- package/node_modules/nan/nan.h +0 -2898
- package/node_modules/nan/nan_callbacks.h +0 -88
- package/node_modules/nan/nan_callbacks_12_inl.h +0 -514
- package/node_modules/nan/nan_callbacks_pre_12_inl.h +0 -520
- package/node_modules/nan/nan_converters.h +0 -72
- package/node_modules/nan/nan_converters_43_inl.h +0 -68
- package/node_modules/nan/nan_converters_pre_43_inl.h +0 -42
- package/node_modules/nan/nan_define_own_property_helper.h +0 -29
- package/node_modules/nan/nan_implementation_12_inl.h +0 -430
- package/node_modules/nan/nan_implementation_pre_12_inl.h +0 -263
- package/node_modules/nan/nan_json.h +0 -166
- package/node_modules/nan/nan_maybe_43_inl.h +0 -356
- package/node_modules/nan/nan_maybe_pre_43_inl.h +0 -268
- package/node_modules/nan/nan_new.h +0 -340
- package/node_modules/nan/nan_object_wrap.h +0 -156
- package/node_modules/nan/nan_persistent_12_inl.h +0 -132
- package/node_modules/nan/nan_persistent_pre_12_inl.h +0 -242
- package/node_modules/nan/nan_private.h +0 -73
- package/node_modules/nan/nan_string_bytes.h +0 -305
- package/node_modules/nan/nan_typedarray_contents.h +0 -96
- package/node_modules/nan/nan_weak.h +0 -437
- package/node_modules/nan/package.json +0 -41
- package/node_modules/nan/tools/1to2.js +0 -412
- package/node_modules/nan/tools/README.md +0 -14
- package/node_modules/nan/tools/package.json +0 -19
- package/node_modules/unix-dgram/LICENSE +0 -13
- package/node_modules/unix-dgram/README.md +0 -107
- package/node_modules/unix-dgram/binding.gyp +0 -20
- package/node_modules/unix-dgram/build/Makefile +0 -324
- package/node_modules/unix-dgram/build/Release/.deps/Release/obj.target/unix_dgram/src/unix_dgram.o.d +0 -58
- package/node_modules/unix-dgram/build/Release/.deps/Release/obj.target/unix_dgram.node.d +0 -1
- package/node_modules/unix-dgram/build/Release/.deps/Release/unix_dgram.node.d +0 -1
- package/node_modules/unix-dgram/build/Release/obj.target/unix_dgram/src/unix_dgram.o +0 -0
- package/node_modules/unix-dgram/build/Release/obj.target/unix_dgram.node +0 -0
- package/node_modules/unix-dgram/build/Release/unix_dgram.node +0 -0
- package/node_modules/unix-dgram/build/binding.Makefile +0 -6
- package/node_modules/unix-dgram/build/config.gypi +0 -213
- package/node_modules/unix-dgram/build/unix_dgram.target.mk +0 -159
- package/node_modules/unix-dgram/lib/unix_dgram.js +0 -168
- package/node_modules/unix-dgram/package.json +0 -36
- package/node_modules/unix-dgram/src/unix_dgram.cc +0 -404
- package/node_modules/unix-dgram/src/win_dummy.cc +0 -7
- package/node_modules/unix-dgram/test/test-connect-callback.js +0 -68
- package/node_modules/unix-dgram/test/test-connect.js +0 -53
- package/node_modules/unix-dgram/test/test-dgram-unix.js +0 -58
- package/node_modules/unix-dgram/test/test-send-error.js +0 -26
- package/node_modules/winston-syslog/.eslintrc +0 -7
- package/node_modules/winston-syslog/.travis.yml +0 -14
- package/node_modules/winston-syslog/CHANGELOG.md +0 -9
- package/node_modules/winston-syslog/LICENSE +0 -20
- package/node_modules/winston-syslog/README.md +0 -135
- package/node_modules/winston-syslog/lib/utils.js +0 -26
- package/node_modules/winston-syslog/lib/winston-syslog.js +0 -385
- package/node_modules/winston-syslog/package.json +0 -56
- package/node_modules/winston-syslog/test/format-test.js +0 -122
- package/node_modules/winston-syslog/test/syslog-test.js +0 -95
- package/node_modules/winston-syslog/test/unix-connect-test.js +0 -133
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
/*********************************************************************
|
|
2
|
-
* NAN - Native Abstractions for Node.js
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2018 NAN contributors
|
|
5
|
-
*
|
|
6
|
-
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
|
|
7
|
-
********************************************************************/
|
|
8
|
-
|
|
9
|
-
#ifndef NAN_IMPLEMENTATION_PRE_12_INL_H_
|
|
10
|
-
#define NAN_IMPLEMENTATION_PRE_12_INL_H_
|
|
11
|
-
|
|
12
|
-
//==============================================================================
|
|
13
|
-
// node v0.10 implementation
|
|
14
|
-
//==============================================================================
|
|
15
|
-
|
|
16
|
-
namespace imp {
|
|
17
|
-
|
|
18
|
-
//=== Array ====================================================================
|
|
19
|
-
|
|
20
|
-
Factory<v8::Array>::return_t
|
|
21
|
-
Factory<v8::Array>::New() {
|
|
22
|
-
return v8::Array::New();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
Factory<v8::Array>::return_t
|
|
26
|
-
Factory<v8::Array>::New(int length) {
|
|
27
|
-
return v8::Array::New(length);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
//=== Boolean ==================================================================
|
|
31
|
-
|
|
32
|
-
Factory<v8::Boolean>::return_t
|
|
33
|
-
Factory<v8::Boolean>::New(bool value) {
|
|
34
|
-
return v8::Boolean::New(value)->ToBoolean();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
//=== Boolean Object ===========================================================
|
|
38
|
-
|
|
39
|
-
Factory<v8::BooleanObject>::return_t
|
|
40
|
-
Factory<v8::BooleanObject>::New(bool value) {
|
|
41
|
-
return v8::BooleanObject::New(value).As<v8::BooleanObject>();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
//=== Context ==================================================================
|
|
45
|
-
|
|
46
|
-
Factory<v8::Context>::return_t
|
|
47
|
-
Factory<v8::Context>::New( v8::ExtensionConfiguration* extensions
|
|
48
|
-
, v8::Local<v8::ObjectTemplate> tmpl
|
|
49
|
-
, v8::Local<v8::Value> obj) {
|
|
50
|
-
v8::Persistent<v8::Context> ctx = v8::Context::New(extensions, tmpl, obj);
|
|
51
|
-
v8::Local<v8::Context> lctx = v8::Local<v8::Context>::New(ctx);
|
|
52
|
-
ctx.Dispose();
|
|
53
|
-
return lctx;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
//=== Date =====================================================================
|
|
57
|
-
|
|
58
|
-
Factory<v8::Date>::return_t
|
|
59
|
-
Factory<v8::Date>::New(double value) {
|
|
60
|
-
return v8::Date::New(value).As<v8::Date>();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
//=== External =================================================================
|
|
64
|
-
|
|
65
|
-
Factory<v8::External>::return_t
|
|
66
|
-
Factory<v8::External>::New(void * value) {
|
|
67
|
-
return v8::External::New(value);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
//=== Function =================================================================
|
|
71
|
-
|
|
72
|
-
Factory<v8::Function>::return_t
|
|
73
|
-
Factory<v8::Function>::New( FunctionCallback callback
|
|
74
|
-
, v8::Local<v8::Value> data) {
|
|
75
|
-
v8::HandleScope scope;
|
|
76
|
-
|
|
77
|
-
return scope.Close(Factory<v8::FunctionTemplate>::New(
|
|
78
|
-
callback, data, v8::Local<v8::Signature>())
|
|
79
|
-
->GetFunction());
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
//=== FunctionTemplate =========================================================
|
|
84
|
-
|
|
85
|
-
Factory<v8::FunctionTemplate>::return_t
|
|
86
|
-
Factory<v8::FunctionTemplate>::New( FunctionCallback callback
|
|
87
|
-
, v8::Local<v8::Value> data
|
|
88
|
-
, v8::Local<v8::Signature> signature) {
|
|
89
|
-
if (callback) {
|
|
90
|
-
v8::HandleScope scope;
|
|
91
|
-
|
|
92
|
-
v8::Local<v8::ObjectTemplate> tpl = v8::ObjectTemplate::New();
|
|
93
|
-
tpl->SetInternalFieldCount(imp::kFunctionFieldCount);
|
|
94
|
-
v8::Local<v8::Object> obj = tpl->NewInstance();
|
|
95
|
-
|
|
96
|
-
obj->SetInternalField(
|
|
97
|
-
imp::kFunctionIndex
|
|
98
|
-
, v8::External::New(reinterpret_cast<void *>(callback)));
|
|
99
|
-
|
|
100
|
-
v8::Local<v8::Value> val = v8::Local<v8::Value>::New(data);
|
|
101
|
-
|
|
102
|
-
if (!val.IsEmpty()) {
|
|
103
|
-
obj->SetInternalField(imp::kDataIndex, val);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Note(agnat): Emulate length argument here. Unfortunately, I couldn't find
|
|
107
|
-
// a way. Have at it though...
|
|
108
|
-
return scope.Close(
|
|
109
|
-
v8::FunctionTemplate::New(imp::FunctionCallbackWrapper
|
|
110
|
-
, obj
|
|
111
|
-
, signature));
|
|
112
|
-
} else {
|
|
113
|
-
return v8::FunctionTemplate::New(0, data, signature);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
//=== Number ===================================================================
|
|
118
|
-
|
|
119
|
-
Factory<v8::Number>::return_t
|
|
120
|
-
Factory<v8::Number>::New(double value) {
|
|
121
|
-
return v8::Number::New(value);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
//=== Number Object ============================================================
|
|
125
|
-
|
|
126
|
-
Factory<v8::NumberObject>::return_t
|
|
127
|
-
Factory<v8::NumberObject>::New(double value) {
|
|
128
|
-
return v8::NumberObject::New(value).As<v8::NumberObject>();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
//=== Integer, Int32 and Uint32 ================================================
|
|
132
|
-
|
|
133
|
-
template <typename T>
|
|
134
|
-
typename IntegerFactory<T>::return_t
|
|
135
|
-
IntegerFactory<T>::New(int32_t value) {
|
|
136
|
-
return To<T>(T::New(value));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
template <typename T>
|
|
140
|
-
typename IntegerFactory<T>::return_t
|
|
141
|
-
IntegerFactory<T>::New(uint32_t value) {
|
|
142
|
-
return To<T>(T::NewFromUnsigned(value));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
Factory<v8::Uint32>::return_t
|
|
146
|
-
Factory<v8::Uint32>::New(int32_t value) {
|
|
147
|
-
return To<v8::Uint32>(v8::Uint32::NewFromUnsigned(value));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
Factory<v8::Uint32>::return_t
|
|
151
|
-
Factory<v8::Uint32>::New(uint32_t value) {
|
|
152
|
-
return To<v8::Uint32>(v8::Uint32::NewFromUnsigned(value));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//=== Object ===================================================================
|
|
157
|
-
|
|
158
|
-
Factory<v8::Object>::return_t
|
|
159
|
-
Factory<v8::Object>::New() {
|
|
160
|
-
return v8::Object::New();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
//=== Object Template ==========================================================
|
|
164
|
-
|
|
165
|
-
Factory<v8::ObjectTemplate>::return_t
|
|
166
|
-
Factory<v8::ObjectTemplate>::New() {
|
|
167
|
-
return v8::ObjectTemplate::New();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
//=== RegExp ===================================================================
|
|
171
|
-
|
|
172
|
-
Factory<v8::RegExp>::return_t
|
|
173
|
-
Factory<v8::RegExp>::New(
|
|
174
|
-
v8::Local<v8::String> pattern
|
|
175
|
-
, v8::RegExp::Flags flags) {
|
|
176
|
-
return v8::RegExp::New(pattern, flags);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
//=== Script ===================================================================
|
|
180
|
-
|
|
181
|
-
Factory<v8::Script>::return_t
|
|
182
|
-
Factory<v8::Script>::New( v8::Local<v8::String> source) {
|
|
183
|
-
return v8::Script::New(source);
|
|
184
|
-
}
|
|
185
|
-
Factory<v8::Script>::return_t
|
|
186
|
-
Factory<v8::Script>::New( v8::Local<v8::String> source
|
|
187
|
-
, v8::ScriptOrigin const& origin) {
|
|
188
|
-
return v8::Script::New(source, const_cast<v8::ScriptOrigin*>(&origin));
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
//=== Signature ================================================================
|
|
192
|
-
|
|
193
|
-
Factory<v8::Signature>::return_t
|
|
194
|
-
Factory<v8::Signature>::New(Factory<v8::Signature>::FTH receiver) {
|
|
195
|
-
return v8::Signature::New(receiver);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
//=== String ===================================================================
|
|
199
|
-
|
|
200
|
-
Factory<v8::String>::return_t
|
|
201
|
-
Factory<v8::String>::New() {
|
|
202
|
-
return v8::String::Empty();
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
Factory<v8::String>::return_t
|
|
206
|
-
Factory<v8::String>::New(const char * value, int length) {
|
|
207
|
-
return v8::String::New(value, length);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
Factory<v8::String>::return_t
|
|
211
|
-
Factory<v8::String>::New(
|
|
212
|
-
std::string const& value) /* NOLINT(build/include_what_you_use) */ {
|
|
213
|
-
assert(value.size() <= INT_MAX && "string too long");
|
|
214
|
-
return v8::String::New(value.data(), static_cast<int>(value.size()));
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
Factory<v8::String>::return_t
|
|
218
|
-
Factory<v8::String>::New(const uint16_t * value, int length) {
|
|
219
|
-
return v8::String::New(value, length);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
Factory<v8::String>::return_t
|
|
223
|
-
Factory<v8::String>::New(v8::String::ExternalStringResource * value) {
|
|
224
|
-
return v8::String::NewExternal(value);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
Factory<v8::String>::return_t
|
|
228
|
-
Factory<v8::String>::New(v8::String::ExternalAsciiStringResource * value) {
|
|
229
|
-
return v8::String::NewExternal(value);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
//=== String Object ============================================================
|
|
233
|
-
|
|
234
|
-
Factory<v8::StringObject>::return_t
|
|
235
|
-
Factory<v8::StringObject>::New(v8::Local<v8::String> value) {
|
|
236
|
-
return v8::StringObject::New(value).As<v8::StringObject>();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
} // end of namespace imp
|
|
240
|
-
|
|
241
|
-
//=== Presistents and Handles ==================================================
|
|
242
|
-
|
|
243
|
-
template <typename T>
|
|
244
|
-
inline v8::Local<T> New(v8::Handle<T> h) {
|
|
245
|
-
return v8::Local<T>::New(h);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
template <typename T>
|
|
249
|
-
inline v8::Local<T> New(v8::Persistent<T> const& p) {
|
|
250
|
-
return v8::Local<T>::New(p);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
template <typename T, typename M>
|
|
254
|
-
inline v8::Local<T> New(Persistent<T, M> const& p) {
|
|
255
|
-
return v8::Local<T>::New(p.persistent);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
template <typename T>
|
|
259
|
-
inline v8::Local<T> New(Global<T> const& p) {
|
|
260
|
-
return v8::Local<T>::New(p.persistent);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
#endif // NAN_IMPLEMENTATION_PRE_12_INL_H_
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/*********************************************************************
|
|
2
|
-
* NAN - Native Abstractions for Node.js
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2018 NAN contributors
|
|
5
|
-
*
|
|
6
|
-
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
|
|
7
|
-
********************************************************************/
|
|
8
|
-
|
|
9
|
-
#ifndef NAN_JSON_H_
|
|
10
|
-
#define NAN_JSON_H_
|
|
11
|
-
|
|
12
|
-
#if NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION
|
|
13
|
-
#define NAN_JSON_H_NEED_PARSE 1
|
|
14
|
-
#else
|
|
15
|
-
#define NAN_JSON_H_NEED_PARSE 0
|
|
16
|
-
#endif // NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION
|
|
17
|
-
|
|
18
|
-
#if NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION
|
|
19
|
-
#define NAN_JSON_H_NEED_STRINGIFY 0
|
|
20
|
-
#else
|
|
21
|
-
#define NAN_JSON_H_NEED_STRINGIFY 1
|
|
22
|
-
#endif // NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION
|
|
23
|
-
|
|
24
|
-
class JSON {
|
|
25
|
-
public:
|
|
26
|
-
JSON() {
|
|
27
|
-
#if NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY
|
|
28
|
-
Nan::HandleScope scope;
|
|
29
|
-
|
|
30
|
-
Nan::MaybeLocal<v8::Value> maybe_global_json = Nan::Get(
|
|
31
|
-
Nan::GetCurrentContext()->Global(),
|
|
32
|
-
Nan::New("JSON").ToLocalChecked()
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
assert(!maybe_global_json.IsEmpty() && "global JSON is empty");
|
|
36
|
-
v8::Local<v8::Value> val_global_json = maybe_global_json.ToLocalChecked();
|
|
37
|
-
|
|
38
|
-
assert(val_global_json->IsObject() && "global JSON is not an object");
|
|
39
|
-
Nan::MaybeLocal<v8::Object> maybe_obj_global_json =
|
|
40
|
-
Nan::To<v8::Object>(val_global_json);
|
|
41
|
-
|
|
42
|
-
assert(!maybe_obj_global_json.IsEmpty() && "global JSON object is empty");
|
|
43
|
-
v8::Local<v8::Object> global_json = maybe_obj_global_json.ToLocalChecked();
|
|
44
|
-
|
|
45
|
-
#if NAN_JSON_H_NEED_PARSE
|
|
46
|
-
Nan::MaybeLocal<v8::Value> maybe_parse_method = Nan::Get(
|
|
47
|
-
global_json, Nan::New("parse").ToLocalChecked()
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
assert(!maybe_parse_method.IsEmpty() && "JSON.parse is empty");
|
|
51
|
-
v8::Local<v8::Value> parse_method = maybe_parse_method.ToLocalChecked();
|
|
52
|
-
|
|
53
|
-
assert(parse_method->IsFunction() && "JSON.parse is not a function");
|
|
54
|
-
parse_cb_.Reset(parse_method.As<v8::Function>());
|
|
55
|
-
#endif // NAN_JSON_H_NEED_PARSE
|
|
56
|
-
|
|
57
|
-
#if NAN_JSON_H_NEED_STRINGIFY
|
|
58
|
-
Nan::MaybeLocal<v8::Value> maybe_stringify_method = Nan::Get(
|
|
59
|
-
global_json, Nan::New("stringify").ToLocalChecked()
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
assert(!maybe_stringify_method.IsEmpty() && "JSON.stringify is empty");
|
|
63
|
-
v8::Local<v8::Value> stringify_method =
|
|
64
|
-
maybe_stringify_method.ToLocalChecked();
|
|
65
|
-
|
|
66
|
-
assert(
|
|
67
|
-
stringify_method->IsFunction() && "JSON.stringify is not a function"
|
|
68
|
-
);
|
|
69
|
-
stringify_cb_.Reset(stringify_method.As<v8::Function>());
|
|
70
|
-
#endif // NAN_JSON_H_NEED_STRINGIFY
|
|
71
|
-
#endif // NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
inline
|
|
75
|
-
Nan::MaybeLocal<v8::Value> Parse(v8::Local<v8::String> json_string) {
|
|
76
|
-
Nan::EscapableHandleScope scope;
|
|
77
|
-
#if NAN_JSON_H_NEED_PARSE
|
|
78
|
-
return scope.Escape(parse(json_string));
|
|
79
|
-
#else
|
|
80
|
-
Nan::MaybeLocal<v8::Value> result;
|
|
81
|
-
#if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION && \
|
|
82
|
-
NODE_MODULE_VERSION <= IOJS_2_0_MODULE_VERSION
|
|
83
|
-
result = v8::JSON::Parse(json_string);
|
|
84
|
-
#else
|
|
85
|
-
#if NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION
|
|
86
|
-
v8::Local<v8::Context> context_or_isolate = Nan::GetCurrentContext();
|
|
87
|
-
#else
|
|
88
|
-
v8::Isolate* context_or_isolate = v8::Isolate::GetCurrent();
|
|
89
|
-
#endif // NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION
|
|
90
|
-
result = v8::JSON::Parse(context_or_isolate, json_string);
|
|
91
|
-
#endif // NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION &&
|
|
92
|
-
// NODE_MODULE_VERSION <= IOJS_2_0_MODULE_VERSION
|
|
93
|
-
if (result.IsEmpty()) return v8::Local<v8::Value>();
|
|
94
|
-
return scope.Escape(result.ToLocalChecked());
|
|
95
|
-
#endif // NAN_JSON_H_NEED_PARSE
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
inline
|
|
99
|
-
Nan::MaybeLocal<v8::String> Stringify(v8::Local<v8::Object> json_object) {
|
|
100
|
-
Nan::EscapableHandleScope scope;
|
|
101
|
-
Nan::MaybeLocal<v8::String> result =
|
|
102
|
-
#if NAN_JSON_H_NEED_STRINGIFY
|
|
103
|
-
Nan::To<v8::String>(stringify(json_object));
|
|
104
|
-
#else
|
|
105
|
-
v8::JSON::Stringify(Nan::GetCurrentContext(), json_object);
|
|
106
|
-
#endif // NAN_JSON_H_NEED_STRINGIFY
|
|
107
|
-
if (result.IsEmpty()) return v8::Local<v8::String>();
|
|
108
|
-
return scope.Escape(result.ToLocalChecked());
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
inline
|
|
112
|
-
Nan::MaybeLocal<v8::String> Stringify(v8::Local<v8::Object> json_object,
|
|
113
|
-
v8::Local<v8::String> gap) {
|
|
114
|
-
Nan::EscapableHandleScope scope;
|
|
115
|
-
Nan::MaybeLocal<v8::String> result =
|
|
116
|
-
#if NAN_JSON_H_NEED_STRINGIFY
|
|
117
|
-
Nan::To<v8::String>(stringify(json_object, gap));
|
|
118
|
-
#else
|
|
119
|
-
v8::JSON::Stringify(Nan::GetCurrentContext(), json_object, gap);
|
|
120
|
-
#endif // NAN_JSON_H_NEED_STRINGIFY
|
|
121
|
-
if (result.IsEmpty()) return v8::Local<v8::String>();
|
|
122
|
-
return scope.Escape(result.ToLocalChecked());
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private:
|
|
126
|
-
NAN_DISALLOW_ASSIGN_COPY_MOVE(JSON)
|
|
127
|
-
#if NAN_JSON_H_NEED_PARSE
|
|
128
|
-
Nan::Callback parse_cb_;
|
|
129
|
-
#endif // NAN_JSON_H_NEED_PARSE
|
|
130
|
-
#if NAN_JSON_H_NEED_STRINGIFY
|
|
131
|
-
Nan::Callback stringify_cb_;
|
|
132
|
-
#endif // NAN_JSON_H_NEED_STRINGIFY
|
|
133
|
-
|
|
134
|
-
#if NAN_JSON_H_NEED_PARSE
|
|
135
|
-
inline v8::Local<v8::Value> parse(v8::Local<v8::Value> arg) {
|
|
136
|
-
assert(!parse_cb_.IsEmpty() && "parse_cb_ is empty");
|
|
137
|
-
AsyncResource resource("nan:JSON.parse");
|
|
138
|
-
return parse_cb_.Call(1, &arg, &resource).FromMaybe(v8::Local<v8::Value>());
|
|
139
|
-
}
|
|
140
|
-
#endif // NAN_JSON_H_NEED_PARSE
|
|
141
|
-
|
|
142
|
-
#if NAN_JSON_H_NEED_STRINGIFY
|
|
143
|
-
inline v8::Local<v8::Value> stringify(v8::Local<v8::Value> arg) {
|
|
144
|
-
assert(!stringify_cb_.IsEmpty() && "stringify_cb_ is empty");
|
|
145
|
-
AsyncResource resource("nan:JSON.stringify");
|
|
146
|
-
return stringify_cb_.Call(1, &arg, &resource)
|
|
147
|
-
.FromMaybe(v8::Local<v8::Value>());
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
inline v8::Local<v8::Value> stringify(v8::Local<v8::Value> arg,
|
|
151
|
-
v8::Local<v8::String> gap) {
|
|
152
|
-
assert(!stringify_cb_.IsEmpty() && "stringify_cb_ is empty");
|
|
153
|
-
|
|
154
|
-
v8::Local<v8::Value> argv[] = {
|
|
155
|
-
arg,
|
|
156
|
-
Nan::Null(),
|
|
157
|
-
gap
|
|
158
|
-
};
|
|
159
|
-
AsyncResource resource("nan:JSON.stringify");
|
|
160
|
-
return stringify_cb_.Call(3, argv, &resource)
|
|
161
|
-
.FromMaybe(v8::Local<v8::Value>());
|
|
162
|
-
}
|
|
163
|
-
#endif // NAN_JSON_H_NEED_STRINGIFY
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
#endif // NAN_JSON_H_
|