Line data Source code
1 : // This file is generated
2 :
3 : // Copyright (c) 2016 The Chromium Authors. All rights reserved.
4 : // Use of this source code is governed by a BSD-style license that can be
5 : // found in the LICENSE file.
6 :
7 : #include "src/inspector/protocol/Runtime.h"
8 :
9 : #include "src/inspector/protocol/Protocol.h"
10 :
11 : namespace v8_inspector {
12 : namespace protocol {
13 : namespace Runtime {
14 :
15 : // ------------- Enum values from types.
16 :
17 : const char Metainfo::domainName[] = "Runtime";
18 : const char Metainfo::commandPrefix[] = "Runtime.";
19 : const char Metainfo::version[] = "1.3";
20 :
21 : const char* RemoteObject::TypeEnum::Object = "object";
22 : const char* RemoteObject::TypeEnum::Function = "function";
23 : const char* RemoteObject::TypeEnum::Undefined = "undefined";
24 : const char* RemoteObject::TypeEnum::String = "string";
25 : const char* RemoteObject::TypeEnum::Number = "number";
26 : const char* RemoteObject::TypeEnum::Boolean = "boolean";
27 : const char* RemoteObject::TypeEnum::Symbol = "symbol";
28 : const char* RemoteObject::TypeEnum::Bigint = "bigint";
29 :
30 : const char* RemoteObject::SubtypeEnum::Array = "array";
31 : const char* RemoteObject::SubtypeEnum::Null = "null";
32 : const char* RemoteObject::SubtypeEnum::Node = "node";
33 : const char* RemoteObject::SubtypeEnum::Regexp = "regexp";
34 : const char* RemoteObject::SubtypeEnum::Date = "date";
35 : const char* RemoteObject::SubtypeEnum::Map = "map";
36 : const char* RemoteObject::SubtypeEnum::Set = "set";
37 : const char* RemoteObject::SubtypeEnum::Weakmap = "weakmap";
38 : const char* RemoteObject::SubtypeEnum::Weakset = "weakset";
39 : const char* RemoteObject::SubtypeEnum::Iterator = "iterator";
40 : const char* RemoteObject::SubtypeEnum::Generator = "generator";
41 : const char* RemoteObject::SubtypeEnum::Error = "error";
42 : const char* RemoteObject::SubtypeEnum::Proxy = "proxy";
43 : const char* RemoteObject::SubtypeEnum::Promise = "promise";
44 : const char* RemoteObject::SubtypeEnum::Typedarray = "typedarray";
45 : const char* RemoteObject::SubtypeEnum::Arraybuffer = "arraybuffer";
46 : const char* RemoteObject::SubtypeEnum::Dataview = "dataview";
47 :
48 90 : std::unique_ptr<RemoteObject> RemoteObject::fromValue(protocol::Value* value, ErrorSupport* errors)
49 : {
50 90 : if (!value || value->type() != protocol::Value::TypeObject) {
51 0 : errors->addError("object expected");
52 : return nullptr;
53 : }
54 :
55 45 : std::unique_ptr<RemoteObject> result(new RemoteObject());
56 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
57 45 : errors->push();
58 90 : protocol::Value* typeValue = object->get("type");
59 45 : errors->setName("type");
60 90 : result->m_type = ValueConversions<String>::fromValue(typeValue, errors);
61 90 : protocol::Value* subtypeValue = object->get("subtype");
62 45 : if (subtypeValue) {
63 15 : errors->setName("subtype");
64 30 : result->m_subtype = ValueConversions<String>::fromValue(subtypeValue, errors);
65 : }
66 90 : protocol::Value* classNameValue = object->get("className");
67 45 : if (classNameValue) {
68 15 : errors->setName("className");
69 30 : result->m_className = ValueConversions<String>::fromValue(classNameValue, errors);
70 : }
71 90 : protocol::Value* valueValue = object->get("value");
72 45 : if (valueValue) {
73 25 : errors->setName("value");
74 50 : result->m_value = ValueConversions<protocol::Value>::fromValue(valueValue, errors);
75 : }
76 90 : protocol::Value* unserializableValueValue = object->get("unserializableValue");
77 45 : if (unserializableValueValue) {
78 0 : errors->setName("unserializableValue");
79 0 : result->m_unserializableValue = ValueConversions<String>::fromValue(unserializableValueValue, errors);
80 : }
81 90 : protocol::Value* descriptionValue = object->get("description");
82 45 : if (descriptionValue) {
83 25 : errors->setName("description");
84 50 : result->m_description = ValueConversions<String>::fromValue(descriptionValue, errors);
85 : }
86 90 : protocol::Value* objectIdValue = object->get("objectId");
87 45 : if (objectIdValue) {
88 15 : errors->setName("objectId");
89 30 : result->m_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
90 : }
91 90 : protocol::Value* previewValue = object->get("preview");
92 45 : if (previewValue) {
93 0 : errors->setName("preview");
94 0 : result->m_preview = ValueConversions<protocol::Runtime::ObjectPreview>::fromValue(previewValue, errors);
95 : }
96 90 : protocol::Value* customPreviewValue = object->get("customPreview");
97 45 : if (customPreviewValue) {
98 0 : errors->setName("customPreview");
99 0 : result->m_customPreview = ValueConversions<protocol::Runtime::CustomPreview>::fromValue(customPreviewValue, errors);
100 : }
101 45 : errors->pop();
102 45 : if (errors->hasErrors())
103 : return nullptr;
104 : return result;
105 : }
106 :
107 3066081 : std::unique_ptr<protocol::DictionaryValue> RemoteObject::toValue() const
108 : {
109 3066081 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
110 15330405 : result->setValue("type", ValueConversions<String>::toValue(m_type));
111 3066081 : if (m_subtype.isJust())
112 299660 : result->setValue("subtype", ValueConversions<String>::toValue(m_subtype.fromJust()));
113 3066081 : if (m_className.isJust())
114 13569710 : result->setValue("className", ValueConversions<String>::toValue(m_className.fromJust()));
115 3066081 : if (m_value.isJust())
116 911620 : result->setValue("value", ValueConversions<protocol::Value>::toValue(m_value.fromJust()));
117 3066081 : if (m_unserializableValue.isJust())
118 179885 : result->setValue("unserializableValue", ValueConversions<String>::toValue(m_unserializableValue.fromJust()));
119 3066081 : if (m_description.isJust())
120 14563475 : result->setValue("description", ValueConversions<String>::toValue(m_description.fromJust()));
121 3066081 : if (m_objectId.isJust())
122 13661850 : result->setValue("objectId", ValueConversions<String>::toValue(m_objectId.fromJust()));
123 3066081 : if (m_preview.isJust())
124 2900 : result->setValue("preview", ValueConversions<protocol::Runtime::ObjectPreview>::toValue(m_preview.fromJust()));
125 3066081 : if (m_customPreview.isJust())
126 240 : result->setValue("customPreview", ValueConversions<protocol::Runtime::CustomPreview>::toValue(m_customPreview.fromJust()));
127 3066081 : return result;
128 : }
129 :
130 45 : std::unique_ptr<RemoteObject> RemoteObject::clone() const
131 : {
132 45 : ErrorSupport errors;
133 135 : return fromValue(toValue().get(), &errors);
134 : }
135 :
136 0 : std::unique_ptr<StringBuffer> RemoteObject::toJSONString() const
137 : {
138 0 : String json = toValue()->serialize();
139 0 : return StringBufferImpl::adopt(json);
140 : }
141 :
142 : // static
143 0 : std::unique_ptr<API::RemoteObject> API::RemoteObject::fromJSONString(const StringView& json)
144 : {
145 0 : ErrorSupport errors;
146 0 : std::unique_ptr<Value> value = StringUtil::parseJSON(json);
147 0 : if (!value)
148 : return nullptr;
149 0 : return protocol::Runtime::RemoteObject::fromValue(value.get(), &errors);
150 : }
151 :
152 0 : std::unique_ptr<CustomPreview> CustomPreview::fromValue(protocol::Value* value, ErrorSupport* errors)
153 : {
154 0 : if (!value || value->type() != protocol::Value::TypeObject) {
155 0 : errors->addError("object expected");
156 : return nullptr;
157 : }
158 :
159 0 : std::unique_ptr<CustomPreview> result(new CustomPreview());
160 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
161 0 : errors->push();
162 0 : protocol::Value* headerValue = object->get("header");
163 0 : errors->setName("header");
164 0 : result->m_header = ValueConversions<String>::fromValue(headerValue, errors);
165 0 : protocol::Value* bodyGetterIdValue = object->get("bodyGetterId");
166 0 : if (bodyGetterIdValue) {
167 0 : errors->setName("bodyGetterId");
168 0 : result->m_bodyGetterId = ValueConversions<String>::fromValue(bodyGetterIdValue, errors);
169 : }
170 0 : errors->pop();
171 0 : if (errors->hasErrors())
172 : return nullptr;
173 : return result;
174 : }
175 :
176 60 : std::unique_ptr<protocol::DictionaryValue> CustomPreview::toValue() const
177 : {
178 60 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
179 300 : result->setValue("header", ValueConversions<String>::toValue(m_header));
180 60 : if (m_bodyGetterId.isJust())
181 250 : result->setValue("bodyGetterId", ValueConversions<String>::toValue(m_bodyGetterId.fromJust()));
182 60 : return result;
183 : }
184 :
185 0 : std::unique_ptr<CustomPreview> CustomPreview::clone() const
186 : {
187 0 : ErrorSupport errors;
188 0 : return fromValue(toValue().get(), &errors);
189 : }
190 :
191 : const char* ObjectPreview::TypeEnum::Object = "object";
192 : const char* ObjectPreview::TypeEnum::Function = "function";
193 : const char* ObjectPreview::TypeEnum::Undefined = "undefined";
194 : const char* ObjectPreview::TypeEnum::String = "string";
195 : const char* ObjectPreview::TypeEnum::Number = "number";
196 : const char* ObjectPreview::TypeEnum::Boolean = "boolean";
197 : const char* ObjectPreview::TypeEnum::Symbol = "symbol";
198 : const char* ObjectPreview::TypeEnum::Bigint = "bigint";
199 :
200 : const char* ObjectPreview::SubtypeEnum::Array = "array";
201 : const char* ObjectPreview::SubtypeEnum::Null = "null";
202 : const char* ObjectPreview::SubtypeEnum::Node = "node";
203 : const char* ObjectPreview::SubtypeEnum::Regexp = "regexp";
204 : const char* ObjectPreview::SubtypeEnum::Date = "date";
205 : const char* ObjectPreview::SubtypeEnum::Map = "map";
206 : const char* ObjectPreview::SubtypeEnum::Set = "set";
207 : const char* ObjectPreview::SubtypeEnum::Weakmap = "weakmap";
208 : const char* ObjectPreview::SubtypeEnum::Weakset = "weakset";
209 : const char* ObjectPreview::SubtypeEnum::Iterator = "iterator";
210 : const char* ObjectPreview::SubtypeEnum::Generator = "generator";
211 : const char* ObjectPreview::SubtypeEnum::Error = "error";
212 :
213 0 : std::unique_ptr<ObjectPreview> ObjectPreview::fromValue(protocol::Value* value, ErrorSupport* errors)
214 : {
215 0 : if (!value || value->type() != protocol::Value::TypeObject) {
216 0 : errors->addError("object expected");
217 : return nullptr;
218 : }
219 :
220 0 : std::unique_ptr<ObjectPreview> result(new ObjectPreview());
221 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
222 0 : errors->push();
223 0 : protocol::Value* typeValue = object->get("type");
224 0 : errors->setName("type");
225 0 : result->m_type = ValueConversions<String>::fromValue(typeValue, errors);
226 0 : protocol::Value* subtypeValue = object->get("subtype");
227 0 : if (subtypeValue) {
228 0 : errors->setName("subtype");
229 0 : result->m_subtype = ValueConversions<String>::fromValue(subtypeValue, errors);
230 : }
231 0 : protocol::Value* descriptionValue = object->get("description");
232 0 : if (descriptionValue) {
233 0 : errors->setName("description");
234 0 : result->m_description = ValueConversions<String>::fromValue(descriptionValue, errors);
235 : }
236 0 : protocol::Value* overflowValue = object->get("overflow");
237 0 : errors->setName("overflow");
238 0 : result->m_overflow = ValueConversions<bool>::fromValue(overflowValue, errors);
239 0 : protocol::Value* propertiesValue = object->get("properties");
240 0 : errors->setName("properties");
241 0 : result->m_properties = ValueConversions<protocol::Array<protocol::Runtime::PropertyPreview>>::fromValue(propertiesValue, errors);
242 0 : protocol::Value* entriesValue = object->get("entries");
243 0 : if (entriesValue) {
244 0 : errors->setName("entries");
245 0 : result->m_entries = ValueConversions<protocol::Array<protocol::Runtime::EntryPreview>>::fromValue(entriesValue, errors);
246 : }
247 0 : errors->pop();
248 0 : if (errors->hasErrors())
249 : return nullptr;
250 : return result;
251 : }
252 :
253 11025 : std::unique_ptr<protocol::DictionaryValue> ObjectPreview::toValue() const
254 : {
255 11025 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
256 55125 : result->setValue("type", ValueConversions<String>::toValue(m_type));
257 11025 : if (m_subtype.isJust())
258 52525 : result->setValue("subtype", ValueConversions<String>::toValue(m_subtype.fromJust()));
259 11025 : if (m_description.isJust())
260 55125 : result->setValue("description", ValueConversions<String>::toValue(m_description.fromJust()));
261 55125 : result->setValue("overflow", ValueConversions<bool>::toValue(m_overflow));
262 44100 : result->setValue("properties", ValueConversions<protocol::Array<protocol::Runtime::PropertyPreview>>::toValue(m_properties.get()));
263 11025 : if (m_entries.isJust())
264 400 : result->setValue("entries", ValueConversions<protocol::Array<protocol::Runtime::EntryPreview>>::toValue(m_entries.fromJust()));
265 11025 : return result;
266 : }
267 :
268 0 : std::unique_ptr<ObjectPreview> ObjectPreview::clone() const
269 : {
270 0 : ErrorSupport errors;
271 0 : return fromValue(toValue().get(), &errors);
272 : }
273 :
274 : const char* PropertyPreview::TypeEnum::Object = "object";
275 : const char* PropertyPreview::TypeEnum::Function = "function";
276 : const char* PropertyPreview::TypeEnum::Undefined = "undefined";
277 : const char* PropertyPreview::TypeEnum::String = "string";
278 : const char* PropertyPreview::TypeEnum::Number = "number";
279 : const char* PropertyPreview::TypeEnum::Boolean = "boolean";
280 : const char* PropertyPreview::TypeEnum::Symbol = "symbol";
281 : const char* PropertyPreview::TypeEnum::Accessor = "accessor";
282 : const char* PropertyPreview::TypeEnum::Bigint = "bigint";
283 :
284 : const char* PropertyPreview::SubtypeEnum::Array = "array";
285 : const char* PropertyPreview::SubtypeEnum::Null = "null";
286 : const char* PropertyPreview::SubtypeEnum::Node = "node";
287 : const char* PropertyPreview::SubtypeEnum::Regexp = "regexp";
288 : const char* PropertyPreview::SubtypeEnum::Date = "date";
289 : const char* PropertyPreview::SubtypeEnum::Map = "map";
290 : const char* PropertyPreview::SubtypeEnum::Set = "set";
291 : const char* PropertyPreview::SubtypeEnum::Weakmap = "weakmap";
292 : const char* PropertyPreview::SubtypeEnum::Weakset = "weakset";
293 : const char* PropertyPreview::SubtypeEnum::Iterator = "iterator";
294 : const char* PropertyPreview::SubtypeEnum::Generator = "generator";
295 : const char* PropertyPreview::SubtypeEnum::Error = "error";
296 :
297 50 : std::unique_ptr<PropertyPreview> PropertyPreview::fromValue(protocol::Value* value, ErrorSupport* errors)
298 : {
299 50 : if (!value || value->type() != protocol::Value::TypeObject) {
300 0 : errors->addError("object expected");
301 : return nullptr;
302 : }
303 :
304 25 : std::unique_ptr<PropertyPreview> result(new PropertyPreview());
305 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
306 25 : errors->push();
307 50 : protocol::Value* nameValue = object->get("name");
308 25 : errors->setName("name");
309 50 : result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
310 50 : protocol::Value* typeValue = object->get("type");
311 25 : errors->setName("type");
312 50 : result->m_type = ValueConversions<String>::fromValue(typeValue, errors);
313 50 : protocol::Value* valueValue = object->get("value");
314 25 : if (valueValue) {
315 25 : errors->setName("value");
316 50 : result->m_value = ValueConversions<String>::fromValue(valueValue, errors);
317 : }
318 50 : protocol::Value* valuePreviewValue = object->get("valuePreview");
319 25 : if (valuePreviewValue) {
320 0 : errors->setName("valuePreview");
321 0 : result->m_valuePreview = ValueConversions<protocol::Runtime::ObjectPreview>::fromValue(valuePreviewValue, errors);
322 : }
323 50 : protocol::Value* subtypeValue = object->get("subtype");
324 25 : if (subtypeValue) {
325 0 : errors->setName("subtype");
326 0 : result->m_subtype = ValueConversions<String>::fromValue(subtypeValue, errors);
327 : }
328 25 : errors->pop();
329 25 : if (errors->hasErrors())
330 : return nullptr;
331 : return result;
332 : }
333 :
334 32115 : std::unique_ptr<protocol::DictionaryValue> PropertyPreview::toValue() const
335 : {
336 32115 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
337 160575 : result->setValue("name", ValueConversions<String>::toValue(m_name));
338 160575 : result->setValue("type", ValueConversions<String>::toValue(m_type));
339 32115 : if (m_value.isJust())
340 160400 : result->setValue("value", ValueConversions<String>::toValue(m_value.fromJust()));
341 32115 : if (m_valuePreview.isJust())
342 40300 : result->setValue("valuePreview", ValueConversions<protocol::Runtime::ObjectPreview>::toValue(m_valuePreview.fromJust()));
343 32115 : if (m_subtype.isJust())
344 50925 : result->setValue("subtype", ValueConversions<String>::toValue(m_subtype.fromJust()));
345 32115 : return result;
346 : }
347 :
348 25 : std::unique_ptr<PropertyPreview> PropertyPreview::clone() const
349 : {
350 25 : ErrorSupport errors;
351 75 : return fromValue(toValue().get(), &errors);
352 : }
353 :
354 0 : std::unique_ptr<EntryPreview> EntryPreview::fromValue(protocol::Value* value, ErrorSupport* errors)
355 : {
356 0 : if (!value || value->type() != protocol::Value::TypeObject) {
357 0 : errors->addError("object expected");
358 : return nullptr;
359 : }
360 :
361 0 : std::unique_ptr<EntryPreview> result(new EntryPreview());
362 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
363 0 : errors->push();
364 0 : protocol::Value* keyValue = object->get("key");
365 0 : if (keyValue) {
366 0 : errors->setName("key");
367 0 : result->m_key = ValueConversions<protocol::Runtime::ObjectPreview>::fromValue(keyValue, errors);
368 : }
369 0 : protocol::Value* valueValue = object->get("value");
370 0 : errors->setName("value");
371 0 : result->m_value = ValueConversions<protocol::Runtime::ObjectPreview>::fromValue(valueValue, errors);
372 0 : errors->pop();
373 0 : if (errors->hasErrors())
374 : return nullptr;
375 : return result;
376 : }
377 :
378 185 : std::unique_ptr<protocol::DictionaryValue> EntryPreview::toValue() const
379 : {
380 185 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
381 185 : if (m_key.isJust())
382 160 : result->setValue("key", ValueConversions<protocol::Runtime::ObjectPreview>::toValue(m_key.fromJust()));
383 740 : result->setValue("value", ValueConversions<protocol::Runtime::ObjectPreview>::toValue(m_value.get()));
384 185 : return result;
385 : }
386 :
387 0 : std::unique_ptr<EntryPreview> EntryPreview::clone() const
388 : {
389 0 : ErrorSupport errors;
390 0 : return fromValue(toValue().get(), &errors);
391 : }
392 :
393 0 : std::unique_ptr<PropertyDescriptor> PropertyDescriptor::fromValue(protocol::Value* value, ErrorSupport* errors)
394 : {
395 0 : if (!value || value->type() != protocol::Value::TypeObject) {
396 0 : errors->addError("object expected");
397 : return nullptr;
398 : }
399 :
400 0 : std::unique_ptr<PropertyDescriptor> result(new PropertyDescriptor());
401 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
402 0 : errors->push();
403 0 : protocol::Value* nameValue = object->get("name");
404 0 : errors->setName("name");
405 0 : result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
406 0 : protocol::Value* valueValue = object->get("value");
407 0 : if (valueValue) {
408 0 : errors->setName("value");
409 0 : result->m_value = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(valueValue, errors);
410 : }
411 0 : protocol::Value* writableValue = object->get("writable");
412 0 : if (writableValue) {
413 0 : errors->setName("writable");
414 0 : result->m_writable = ValueConversions<bool>::fromValue(writableValue, errors);
415 : }
416 0 : protocol::Value* getValue = object->get("get");
417 0 : if (getValue) {
418 0 : errors->setName("get");
419 0 : result->m_get = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(getValue, errors);
420 : }
421 0 : protocol::Value* setValue = object->get("set");
422 0 : if (setValue) {
423 0 : errors->setName("set");
424 0 : result->m_set = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(setValue, errors);
425 : }
426 0 : protocol::Value* configurableValue = object->get("configurable");
427 0 : errors->setName("configurable");
428 0 : result->m_configurable = ValueConversions<bool>::fromValue(configurableValue, errors);
429 0 : protocol::Value* enumerableValue = object->get("enumerable");
430 0 : errors->setName("enumerable");
431 0 : result->m_enumerable = ValueConversions<bool>::fromValue(enumerableValue, errors);
432 0 : protocol::Value* wasThrownValue = object->get("wasThrown");
433 0 : if (wasThrownValue) {
434 0 : errors->setName("wasThrown");
435 0 : result->m_wasThrown = ValueConversions<bool>::fromValue(wasThrownValue, errors);
436 : }
437 0 : protocol::Value* isOwnValue = object->get("isOwn");
438 0 : if (isOwnValue) {
439 0 : errors->setName("isOwn");
440 0 : result->m_isOwn = ValueConversions<bool>::fromValue(isOwnValue, errors);
441 : }
442 0 : protocol::Value* symbolValue = object->get("symbol");
443 0 : if (symbolValue) {
444 0 : errors->setName("symbol");
445 0 : result->m_symbol = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(symbolValue, errors);
446 : }
447 0 : errors->pop();
448 0 : if (errors->hasErrors())
449 : return nullptr;
450 : return result;
451 : }
452 :
453 2490789 : std::unique_ptr<protocol::DictionaryValue> PropertyDescriptor::toValue() const
454 : {
455 2490789 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
456 12453945 : result->setValue("name", ValueConversions<String>::toValue(m_name));
457 2490789 : if (m_value.isJust())
458 9961816 : result->setValue("value", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_value.fromJust()));
459 2490789 : if (m_writable.isJust())
460 9961816 : result->setValue("writable", ValueConversions<bool>::toValue(m_writable.fromJust()));
461 2490789 : if (m_get.isJust())
462 1340 : result->setValue("get", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_get.fromJust()));
463 2490789 : if (m_set.isJust())
464 1320 : result->setValue("set", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_set.fromJust()));
465 12453945 : result->setValue("configurable", ValueConversions<bool>::toValue(m_configurable));
466 12453945 : result->setValue("enumerable", ValueConversions<bool>::toValue(m_enumerable));
467 2490789 : if (m_wasThrown.isJust())
468 0 : result->setValue("wasThrown", ValueConversions<bool>::toValue(m_wasThrown.fromJust()));
469 2490789 : if (m_isOwn.isJust())
470 9963156 : result->setValue("isOwn", ValueConversions<bool>::toValue(m_isOwn.fromJust()));
471 2490789 : if (m_symbol.isJust())
472 73540 : result->setValue("symbol", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_symbol.fromJust()));
473 2490789 : return result;
474 : }
475 :
476 0 : std::unique_ptr<PropertyDescriptor> PropertyDescriptor::clone() const
477 : {
478 0 : ErrorSupport errors;
479 0 : return fromValue(toValue().get(), &errors);
480 : }
481 :
482 0 : std::unique_ptr<InternalPropertyDescriptor> InternalPropertyDescriptor::fromValue(protocol::Value* value, ErrorSupport* errors)
483 : {
484 0 : if (!value || value->type() != protocol::Value::TypeObject) {
485 0 : errors->addError("object expected");
486 : return nullptr;
487 : }
488 :
489 0 : std::unique_ptr<InternalPropertyDescriptor> result(new InternalPropertyDescriptor());
490 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
491 0 : errors->push();
492 0 : protocol::Value* nameValue = object->get("name");
493 0 : errors->setName("name");
494 0 : result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
495 0 : protocol::Value* valueValue = object->get("value");
496 0 : if (valueValue) {
497 0 : errors->setName("value");
498 0 : result->m_value = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(valueValue, errors);
499 : }
500 0 : errors->pop();
501 0 : if (errors->hasErrors())
502 : return nullptr;
503 : return result;
504 : }
505 :
506 1059 : std::unique_ptr<protocol::DictionaryValue> InternalPropertyDescriptor::toValue() const
507 : {
508 1059 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
509 5295 : result->setValue("name", ValueConversions<String>::toValue(m_name));
510 1059 : if (m_value.isJust())
511 4236 : result->setValue("value", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_value.fromJust()));
512 1059 : return result;
513 : }
514 :
515 0 : std::unique_ptr<InternalPropertyDescriptor> InternalPropertyDescriptor::clone() const
516 : {
517 0 : ErrorSupport errors;
518 0 : return fromValue(toValue().get(), &errors);
519 : }
520 :
521 752 : std::unique_ptr<CallArgument> CallArgument::fromValue(protocol::Value* value, ErrorSupport* errors)
522 : {
523 752 : if (!value || value->type() != protocol::Value::TypeObject) {
524 0 : errors->addError("object expected");
525 : return nullptr;
526 : }
527 :
528 376 : std::unique_ptr<CallArgument> result(new CallArgument());
529 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
530 376 : errors->push();
531 752 : protocol::Value* valueValue = object->get("value");
532 376 : if (valueValue) {
533 246 : errors->setName("value");
534 492 : result->m_value = ValueConversions<protocol::Value>::fromValue(valueValue, errors);
535 : }
536 752 : protocol::Value* unserializableValueValue = object->get("unserializableValue");
537 376 : if (unserializableValueValue) {
538 30 : errors->setName("unserializableValue");
539 60 : result->m_unserializableValue = ValueConversions<String>::fromValue(unserializableValueValue, errors);
540 : }
541 752 : protocol::Value* objectIdValue = object->get("objectId");
542 376 : if (objectIdValue) {
543 95 : errors->setName("objectId");
544 190 : result->m_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
545 : }
546 376 : errors->pop();
547 376 : if (errors->hasErrors())
548 : return nullptr;
549 : return result;
550 : }
551 :
552 0 : std::unique_ptr<protocol::DictionaryValue> CallArgument::toValue() const
553 : {
554 0 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
555 0 : if (m_value.isJust())
556 0 : result->setValue("value", ValueConversions<protocol::Value>::toValue(m_value.fromJust()));
557 0 : if (m_unserializableValue.isJust())
558 0 : result->setValue("unserializableValue", ValueConversions<String>::toValue(m_unserializableValue.fromJust()));
559 0 : if (m_objectId.isJust())
560 0 : result->setValue("objectId", ValueConversions<String>::toValue(m_objectId.fromJust()));
561 0 : return result;
562 : }
563 :
564 0 : std::unique_ptr<CallArgument> CallArgument::clone() const
565 : {
566 0 : ErrorSupport errors;
567 0 : return fromValue(toValue().get(), &errors);
568 : }
569 :
570 0 : std::unique_ptr<ExecutionContextDescription> ExecutionContextDescription::fromValue(protocol::Value* value, ErrorSupport* errors)
571 : {
572 0 : if (!value || value->type() != protocol::Value::TypeObject) {
573 0 : errors->addError("object expected");
574 : return nullptr;
575 : }
576 :
577 0 : std::unique_ptr<ExecutionContextDescription> result(new ExecutionContextDescription());
578 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
579 0 : errors->push();
580 0 : protocol::Value* idValue = object->get("id");
581 0 : errors->setName("id");
582 0 : result->m_id = ValueConversions<int>::fromValue(idValue, errors);
583 0 : protocol::Value* originValue = object->get("origin");
584 0 : errors->setName("origin");
585 0 : result->m_origin = ValueConversions<String>::fromValue(originValue, errors);
586 0 : protocol::Value* nameValue = object->get("name");
587 0 : errors->setName("name");
588 0 : result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
589 0 : protocol::Value* auxDataValue = object->get("auxData");
590 0 : if (auxDataValue) {
591 0 : errors->setName("auxData");
592 0 : result->m_auxData = ValueConversions<protocol::DictionaryValue>::fromValue(auxDataValue, errors);
593 : }
594 0 : errors->pop();
595 0 : if (errors->hasErrors())
596 : return nullptr;
597 : return result;
598 : }
599 :
600 715 : std::unique_ptr<protocol::DictionaryValue> ExecutionContextDescription::toValue() const
601 : {
602 715 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
603 3575 : result->setValue("id", ValueConversions<int>::toValue(m_id));
604 3575 : result->setValue("origin", ValueConversions<String>::toValue(m_origin));
605 3575 : result->setValue("name", ValueConversions<String>::toValue(m_name));
606 715 : if (m_auxData.isJust())
607 0 : result->setValue("auxData", ValueConversions<protocol::DictionaryValue>::toValue(m_auxData.fromJust()));
608 715 : return result;
609 : }
610 :
611 0 : std::unique_ptr<ExecutionContextDescription> ExecutionContextDescription::clone() const
612 : {
613 0 : ErrorSupport errors;
614 0 : return fromValue(toValue().get(), &errors);
615 : }
616 :
617 0 : std::unique_ptr<ExceptionDetails> ExceptionDetails::fromValue(protocol::Value* value, ErrorSupport* errors)
618 : {
619 0 : if (!value || value->type() != protocol::Value::TypeObject) {
620 0 : errors->addError("object expected");
621 : return nullptr;
622 : }
623 :
624 0 : std::unique_ptr<ExceptionDetails> result(new ExceptionDetails());
625 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
626 0 : errors->push();
627 0 : protocol::Value* exceptionIdValue = object->get("exceptionId");
628 0 : errors->setName("exceptionId");
629 0 : result->m_exceptionId = ValueConversions<int>::fromValue(exceptionIdValue, errors);
630 0 : protocol::Value* textValue = object->get("text");
631 0 : errors->setName("text");
632 0 : result->m_text = ValueConversions<String>::fromValue(textValue, errors);
633 0 : protocol::Value* lineNumberValue = object->get("lineNumber");
634 0 : errors->setName("lineNumber");
635 0 : result->m_lineNumber = ValueConversions<int>::fromValue(lineNumberValue, errors);
636 0 : protocol::Value* columnNumberValue = object->get("columnNumber");
637 0 : errors->setName("columnNumber");
638 0 : result->m_columnNumber = ValueConversions<int>::fromValue(columnNumberValue, errors);
639 0 : protocol::Value* scriptIdValue = object->get("scriptId");
640 0 : if (scriptIdValue) {
641 0 : errors->setName("scriptId");
642 0 : result->m_scriptId = ValueConversions<String>::fromValue(scriptIdValue, errors);
643 : }
644 0 : protocol::Value* urlValue = object->get("url");
645 0 : if (urlValue) {
646 0 : errors->setName("url");
647 0 : result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
648 : }
649 0 : protocol::Value* stackTraceValue = object->get("stackTrace");
650 0 : if (stackTraceValue) {
651 0 : errors->setName("stackTrace");
652 0 : result->m_stackTrace = ValueConversions<protocol::Runtime::StackTrace>::fromValue(stackTraceValue, errors);
653 : }
654 0 : protocol::Value* exceptionValue = object->get("exception");
655 0 : if (exceptionValue) {
656 0 : errors->setName("exception");
657 0 : result->m_exception = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(exceptionValue, errors);
658 : }
659 0 : protocol::Value* executionContextIdValue = object->get("executionContextId");
660 0 : if (executionContextIdValue) {
661 0 : errors->setName("executionContextId");
662 0 : result->m_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
663 : }
664 0 : errors->pop();
665 0 : if (errors->hasErrors())
666 : return nullptr;
667 : return result;
668 : }
669 :
670 1791 : std::unique_ptr<protocol::DictionaryValue> ExceptionDetails::toValue() const
671 : {
672 1791 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
673 8955 : result->setValue("exceptionId", ValueConversions<int>::toValue(m_exceptionId));
674 8955 : result->setValue("text", ValueConversions<String>::toValue(m_text));
675 8955 : result->setValue("lineNumber", ValueConversions<int>::toValue(m_lineNumber));
676 8955 : result->setValue("columnNumber", ValueConversions<int>::toValue(m_columnNumber));
677 1791 : if (m_scriptId.isJust())
678 8330 : result->setValue("scriptId", ValueConversions<String>::toValue(m_scriptId.fromJust()));
679 1791 : if (m_url.isJust())
680 100 : result->setValue("url", ValueConversions<String>::toValue(m_url.fromJust()));
681 1791 : if (m_stackTrace.isJust())
682 620 : result->setValue("stackTrace", ValueConversions<protocol::Runtime::StackTrace>::toValue(m_stackTrace.fromJust()));
683 1791 : if (m_exception.isJust())
684 7124 : result->setValue("exception", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_exception.fromJust()));
685 1791 : if (m_executionContextId.isJust())
686 700 : result->setValue("executionContextId", ValueConversions<int>::toValue(m_executionContextId.fromJust()));
687 1791 : return result;
688 : }
689 :
690 0 : std::unique_ptr<ExceptionDetails> ExceptionDetails::clone() const
691 : {
692 0 : ErrorSupport errors;
693 0 : return fromValue(toValue().get(), &errors);
694 : }
695 :
696 0 : std::unique_ptr<CallFrame> CallFrame::fromValue(protocol::Value* value, ErrorSupport* errors)
697 : {
698 0 : if (!value || value->type() != protocol::Value::TypeObject) {
699 0 : errors->addError("object expected");
700 : return nullptr;
701 : }
702 :
703 0 : std::unique_ptr<CallFrame> result(new CallFrame());
704 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
705 0 : errors->push();
706 0 : protocol::Value* functionNameValue = object->get("functionName");
707 0 : errors->setName("functionName");
708 0 : result->m_functionName = ValueConversions<String>::fromValue(functionNameValue, errors);
709 0 : protocol::Value* scriptIdValue = object->get("scriptId");
710 0 : errors->setName("scriptId");
711 0 : result->m_scriptId = ValueConversions<String>::fromValue(scriptIdValue, errors);
712 0 : protocol::Value* urlValue = object->get("url");
713 0 : errors->setName("url");
714 0 : result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
715 0 : protocol::Value* lineNumberValue = object->get("lineNumber");
716 0 : errors->setName("lineNumber");
717 0 : result->m_lineNumber = ValueConversions<int>::fromValue(lineNumberValue, errors);
718 0 : protocol::Value* columnNumberValue = object->get("columnNumber");
719 0 : errors->setName("columnNumber");
720 0 : result->m_columnNumber = ValueConversions<int>::fromValue(columnNumberValue, errors);
721 0 : errors->pop();
722 0 : if (errors->hasErrors())
723 : return nullptr;
724 : return result;
725 : }
726 :
727 63756 : std::unique_ptr<protocol::DictionaryValue> CallFrame::toValue() const
728 : {
729 63756 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
730 318780 : result->setValue("functionName", ValueConversions<String>::toValue(m_functionName));
731 318780 : result->setValue("scriptId", ValueConversions<String>::toValue(m_scriptId));
732 318780 : result->setValue("url", ValueConversions<String>::toValue(m_url));
733 318780 : result->setValue("lineNumber", ValueConversions<int>::toValue(m_lineNumber));
734 318780 : result->setValue("columnNumber", ValueConversions<int>::toValue(m_columnNumber));
735 63756 : return result;
736 : }
737 :
738 0 : std::unique_ptr<CallFrame> CallFrame::clone() const
739 : {
740 0 : ErrorSupport errors;
741 0 : return fromValue(toValue().get(), &errors);
742 : }
743 :
744 0 : std::unique_ptr<StackTrace> StackTrace::fromValue(protocol::Value* value, ErrorSupport* errors)
745 : {
746 0 : if (!value || value->type() != protocol::Value::TypeObject) {
747 0 : errors->addError("object expected");
748 : return nullptr;
749 : }
750 :
751 0 : std::unique_ptr<StackTrace> result(new StackTrace());
752 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
753 0 : errors->push();
754 0 : protocol::Value* descriptionValue = object->get("description");
755 0 : if (descriptionValue) {
756 0 : errors->setName("description");
757 0 : result->m_description = ValueConversions<String>::fromValue(descriptionValue, errors);
758 : }
759 0 : protocol::Value* callFramesValue = object->get("callFrames");
760 0 : errors->setName("callFrames");
761 0 : result->m_callFrames = ValueConversions<protocol::Array<protocol::Runtime::CallFrame>>::fromValue(callFramesValue, errors);
762 0 : protocol::Value* parentValue = object->get("parent");
763 0 : if (parentValue) {
764 0 : errors->setName("parent");
765 0 : result->m_parent = ValueConversions<protocol::Runtime::StackTrace>::fromValue(parentValue, errors);
766 : }
767 0 : protocol::Value* parentIdValue = object->get("parentId");
768 0 : if (parentIdValue) {
769 0 : errors->setName("parentId");
770 0 : result->m_parentId = ValueConversions<protocol::Runtime::StackTraceId>::fromValue(parentIdValue, errors);
771 : }
772 0 : errors->pop();
773 0 : if (errors->hasErrors())
774 : return nullptr;
775 : return result;
776 : }
777 :
778 61704 : std::unique_ptr<protocol::DictionaryValue> StackTrace::toValue() const
779 : {
780 61704 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
781 61704 : if (m_description.isJust())
782 8675 : result->setValue("description", ValueConversions<String>::toValue(m_description.fromJust()));
783 246816 : result->setValue("callFrames", ValueConversions<protocol::Array<protocol::Runtime::CallFrame>>::toValue(m_callFrames.get()));
784 61704 : if (m_parent.isJust())
785 4520 : result->setValue("parent", ValueConversions<protocol::Runtime::StackTrace>::toValue(m_parent.fromJust()));
786 61704 : if (m_parentId.isJust())
787 460 : result->setValue("parentId", ValueConversions<protocol::Runtime::StackTraceId>::toValue(m_parentId.fromJust()));
788 61704 : return result;
789 : }
790 :
791 0 : std::unique_ptr<StackTrace> StackTrace::clone() const
792 : {
793 0 : ErrorSupport errors;
794 0 : return fromValue(toValue().get(), &errors);
795 : }
796 :
797 0 : std::unique_ptr<StringBuffer> StackTrace::toJSONString() const
798 : {
799 0 : String json = toValue()->serialize();
800 0 : return StringBufferImpl::adopt(json);
801 : }
802 :
803 : // static
804 0 : std::unique_ptr<API::StackTrace> API::StackTrace::fromJSONString(const StringView& json)
805 : {
806 0 : ErrorSupport errors;
807 0 : std::unique_ptr<Value> value = StringUtil::parseJSON(json);
808 0 : if (!value)
809 : return nullptr;
810 0 : return protocol::Runtime::StackTrace::fromValue(value.get(), &errors);
811 : }
812 :
813 260 : std::unique_ptr<StackTraceId> StackTraceId::fromValue(protocol::Value* value, ErrorSupport* errors)
814 : {
815 260 : if (!value || value->type() != protocol::Value::TypeObject) {
816 0 : errors->addError("object expected");
817 : return nullptr;
818 : }
819 :
820 130 : std::unique_ptr<StackTraceId> result(new StackTraceId());
821 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
822 130 : errors->push();
823 260 : protocol::Value* idValue = object->get("id");
824 130 : errors->setName("id");
825 260 : result->m_id = ValueConversions<String>::fromValue(idValue, errors);
826 260 : protocol::Value* debuggerIdValue = object->get("debuggerId");
827 130 : if (debuggerIdValue) {
828 35 : errors->setName("debuggerId");
829 70 : result->m_debuggerId = ValueConversions<String>::fromValue(debuggerIdValue, errors);
830 : }
831 130 : errors->pop();
832 130 : if (errors->hasErrors())
833 : return nullptr;
834 : return result;
835 : }
836 :
837 235 : std::unique_ptr<protocol::DictionaryValue> StackTraceId::toValue() const
838 : {
839 235 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
840 1175 : result->setValue("id", ValueConversions<String>::toValue(m_id));
841 235 : if (m_debuggerId.isJust())
842 300 : result->setValue("debuggerId", ValueConversions<String>::toValue(m_debuggerId.fromJust()));
843 235 : return result;
844 : }
845 :
846 0 : std::unique_ptr<StackTraceId> StackTraceId::clone() const
847 : {
848 0 : ErrorSupport errors;
849 0 : return fromValue(toValue().get(), &errors);
850 : }
851 :
852 0 : std::unique_ptr<StringBuffer> StackTraceId::toJSONString() const
853 : {
854 0 : String json = toValue()->serialize();
855 0 : return StringBufferImpl::adopt(json);
856 : }
857 :
858 : // static
859 0 : std::unique_ptr<API::StackTraceId> API::StackTraceId::fromJSONString(const StringView& json)
860 : {
861 0 : ErrorSupport errors;
862 0 : std::unique_ptr<Value> value = StringUtil::parseJSON(json);
863 0 : if (!value)
864 : return nullptr;
865 0 : return protocol::Runtime::StackTraceId::fromValue(value.get(), &errors);
866 : }
867 :
868 0 : std::unique_ptr<BindingCalledNotification> BindingCalledNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
869 : {
870 0 : if (!value || value->type() != protocol::Value::TypeObject) {
871 0 : errors->addError("object expected");
872 : return nullptr;
873 : }
874 :
875 0 : std::unique_ptr<BindingCalledNotification> result(new BindingCalledNotification());
876 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
877 0 : errors->push();
878 0 : protocol::Value* nameValue = object->get("name");
879 0 : errors->setName("name");
880 0 : result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
881 0 : protocol::Value* payloadValue = object->get("payload");
882 0 : errors->setName("payload");
883 0 : result->m_payload = ValueConversions<String>::fromValue(payloadValue, errors);
884 0 : protocol::Value* executionContextIdValue = object->get("executionContextId");
885 0 : errors->setName("executionContextId");
886 0 : result->m_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
887 0 : errors->pop();
888 0 : if (errors->hasErrors())
889 : return nullptr;
890 : return result;
891 : }
892 :
893 35 : std::unique_ptr<protocol::DictionaryValue> BindingCalledNotification::toValue() const
894 : {
895 35 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
896 175 : result->setValue("name", ValueConversions<String>::toValue(m_name));
897 175 : result->setValue("payload", ValueConversions<String>::toValue(m_payload));
898 175 : result->setValue("executionContextId", ValueConversions<int>::toValue(m_executionContextId));
899 35 : return result;
900 : }
901 :
902 0 : std::unique_ptr<BindingCalledNotification> BindingCalledNotification::clone() const
903 : {
904 0 : ErrorSupport errors;
905 0 : return fromValue(toValue().get(), &errors);
906 : }
907 :
908 : const char* ConsoleAPICalledNotification::TypeEnum::Log = "log";
909 : const char* ConsoleAPICalledNotification::TypeEnum::Debug = "debug";
910 : const char* ConsoleAPICalledNotification::TypeEnum::Info = "info";
911 : const char* ConsoleAPICalledNotification::TypeEnum::Error = "error";
912 : const char* ConsoleAPICalledNotification::TypeEnum::Warning = "warning";
913 : const char* ConsoleAPICalledNotification::TypeEnum::Dir = "dir";
914 : const char* ConsoleAPICalledNotification::TypeEnum::Dirxml = "dirxml";
915 : const char* ConsoleAPICalledNotification::TypeEnum::Table = "table";
916 : const char* ConsoleAPICalledNotification::TypeEnum::Trace = "trace";
917 : const char* ConsoleAPICalledNotification::TypeEnum::Clear = "clear";
918 : const char* ConsoleAPICalledNotification::TypeEnum::StartGroup = "startGroup";
919 : const char* ConsoleAPICalledNotification::TypeEnum::StartGroupCollapsed = "startGroupCollapsed";
920 : const char* ConsoleAPICalledNotification::TypeEnum::EndGroup = "endGroup";
921 : const char* ConsoleAPICalledNotification::TypeEnum::Assert = "assert";
922 : const char* ConsoleAPICalledNotification::TypeEnum::Profile = "profile";
923 : const char* ConsoleAPICalledNotification::TypeEnum::ProfileEnd = "profileEnd";
924 : const char* ConsoleAPICalledNotification::TypeEnum::Count = "count";
925 : const char* ConsoleAPICalledNotification::TypeEnum::TimeEnd = "timeEnd";
926 :
927 0 : std::unique_ptr<ConsoleAPICalledNotification> ConsoleAPICalledNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
928 : {
929 0 : if (!value || value->type() != protocol::Value::TypeObject) {
930 0 : errors->addError("object expected");
931 : return nullptr;
932 : }
933 :
934 0 : std::unique_ptr<ConsoleAPICalledNotification> result(new ConsoleAPICalledNotification());
935 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
936 0 : errors->push();
937 0 : protocol::Value* typeValue = object->get("type");
938 0 : errors->setName("type");
939 0 : result->m_type = ValueConversions<String>::fromValue(typeValue, errors);
940 0 : protocol::Value* argsValue = object->get("args");
941 0 : errors->setName("args");
942 0 : result->m_args = ValueConversions<protocol::Array<protocol::Runtime::RemoteObject>>::fromValue(argsValue, errors);
943 0 : protocol::Value* executionContextIdValue = object->get("executionContextId");
944 0 : errors->setName("executionContextId");
945 0 : result->m_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
946 0 : protocol::Value* timestampValue = object->get("timestamp");
947 0 : errors->setName("timestamp");
948 0 : result->m_timestamp = ValueConversions<double>::fromValue(timestampValue, errors);
949 0 : protocol::Value* stackTraceValue = object->get("stackTrace");
950 0 : if (stackTraceValue) {
951 0 : errors->setName("stackTrace");
952 0 : result->m_stackTrace = ValueConversions<protocol::Runtime::StackTrace>::fromValue(stackTraceValue, errors);
953 : }
954 0 : protocol::Value* contextValue = object->get("context");
955 0 : if (contextValue) {
956 0 : errors->setName("context");
957 0 : result->m_context = ValueConversions<String>::fromValue(contextValue, errors);
958 : }
959 0 : errors->pop();
960 0 : if (errors->hasErrors())
961 : return nullptr;
962 : return result;
963 : }
964 :
965 6635 : std::unique_ptr<protocol::DictionaryValue> ConsoleAPICalledNotification::toValue() const
966 : {
967 6635 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
968 33175 : result->setValue("type", ValueConversions<String>::toValue(m_type));
969 26540 : result->setValue("args", ValueConversions<protocol::Array<protocol::Runtime::RemoteObject>>::toValue(m_args.get()));
970 33175 : result->setValue("executionContextId", ValueConversions<int>::toValue(m_executionContextId));
971 33175 : result->setValue("timestamp", ValueConversions<double>::toValue(m_timestamp));
972 6635 : if (m_stackTrace.isJust())
973 26360 : result->setValue("stackTrace", ValueConversions<protocol::Runtime::StackTrace>::toValue(m_stackTrace.fromJust()));
974 6635 : if (m_context.isJust())
975 350 : result->setValue("context", ValueConversions<String>::toValue(m_context.fromJust()));
976 6635 : return result;
977 : }
978 :
979 0 : std::unique_ptr<ConsoleAPICalledNotification> ConsoleAPICalledNotification::clone() const
980 : {
981 0 : ErrorSupport errors;
982 0 : return fromValue(toValue().get(), &errors);
983 : }
984 :
985 0 : std::unique_ptr<ExceptionRevokedNotification> ExceptionRevokedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
986 : {
987 0 : if (!value || value->type() != protocol::Value::TypeObject) {
988 0 : errors->addError("object expected");
989 : return nullptr;
990 : }
991 :
992 0 : std::unique_ptr<ExceptionRevokedNotification> result(new ExceptionRevokedNotification());
993 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
994 0 : errors->push();
995 0 : protocol::Value* reasonValue = object->get("reason");
996 0 : errors->setName("reason");
997 0 : result->m_reason = ValueConversions<String>::fromValue(reasonValue, errors);
998 0 : protocol::Value* exceptionIdValue = object->get("exceptionId");
999 0 : errors->setName("exceptionId");
1000 0 : result->m_exceptionId = ValueConversions<int>::fromValue(exceptionIdValue, errors);
1001 0 : errors->pop();
1002 0 : if (errors->hasErrors())
1003 : return nullptr;
1004 : return result;
1005 : }
1006 :
1007 70 : std::unique_ptr<protocol::DictionaryValue> ExceptionRevokedNotification::toValue() const
1008 : {
1009 70 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
1010 350 : result->setValue("reason", ValueConversions<String>::toValue(m_reason));
1011 350 : result->setValue("exceptionId", ValueConversions<int>::toValue(m_exceptionId));
1012 70 : return result;
1013 : }
1014 :
1015 0 : std::unique_ptr<ExceptionRevokedNotification> ExceptionRevokedNotification::clone() const
1016 : {
1017 0 : ErrorSupport errors;
1018 0 : return fromValue(toValue().get(), &errors);
1019 : }
1020 :
1021 0 : std::unique_ptr<ExceptionThrownNotification> ExceptionThrownNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
1022 : {
1023 0 : if (!value || value->type() != protocol::Value::TypeObject) {
1024 0 : errors->addError("object expected");
1025 : return nullptr;
1026 : }
1027 :
1028 0 : std::unique_ptr<ExceptionThrownNotification> result(new ExceptionThrownNotification());
1029 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
1030 0 : errors->push();
1031 0 : protocol::Value* timestampValue = object->get("timestamp");
1032 0 : errors->setName("timestamp");
1033 0 : result->m_timestamp = ValueConversions<double>::fromValue(timestampValue, errors);
1034 0 : protocol::Value* exceptionDetailsValue = object->get("exceptionDetails");
1035 0 : errors->setName("exceptionDetails");
1036 0 : result->m_exceptionDetails = ValueConversions<protocol::Runtime::ExceptionDetails>::fromValue(exceptionDetailsValue, errors);
1037 0 : errors->pop();
1038 0 : if (errors->hasErrors())
1039 : return nullptr;
1040 : return result;
1041 : }
1042 :
1043 175 : std::unique_ptr<protocol::DictionaryValue> ExceptionThrownNotification::toValue() const
1044 : {
1045 175 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
1046 875 : result->setValue("timestamp", ValueConversions<double>::toValue(m_timestamp));
1047 700 : result->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(m_exceptionDetails.get()));
1048 175 : return result;
1049 : }
1050 :
1051 0 : std::unique_ptr<ExceptionThrownNotification> ExceptionThrownNotification::clone() const
1052 : {
1053 0 : ErrorSupport errors;
1054 0 : return fromValue(toValue().get(), &errors);
1055 : }
1056 :
1057 0 : std::unique_ptr<ExecutionContextCreatedNotification> ExecutionContextCreatedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
1058 : {
1059 0 : if (!value || value->type() != protocol::Value::TypeObject) {
1060 0 : errors->addError("object expected");
1061 : return nullptr;
1062 : }
1063 :
1064 0 : std::unique_ptr<ExecutionContextCreatedNotification> result(new ExecutionContextCreatedNotification());
1065 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
1066 0 : errors->push();
1067 0 : protocol::Value* contextValue = object->get("context");
1068 0 : errors->setName("context");
1069 0 : result->m_context = ValueConversions<protocol::Runtime::ExecutionContextDescription>::fromValue(contextValue, errors);
1070 0 : errors->pop();
1071 0 : if (errors->hasErrors())
1072 : return nullptr;
1073 : return result;
1074 : }
1075 :
1076 715 : std::unique_ptr<protocol::DictionaryValue> ExecutionContextCreatedNotification::toValue() const
1077 : {
1078 715 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
1079 2860 : result->setValue("context", ValueConversions<protocol::Runtime::ExecutionContextDescription>::toValue(m_context.get()));
1080 715 : return result;
1081 : }
1082 :
1083 0 : std::unique_ptr<ExecutionContextCreatedNotification> ExecutionContextCreatedNotification::clone() const
1084 : {
1085 0 : ErrorSupport errors;
1086 0 : return fromValue(toValue().get(), &errors);
1087 : }
1088 :
1089 0 : std::unique_ptr<ExecutionContextDestroyedNotification> ExecutionContextDestroyedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
1090 : {
1091 0 : if (!value || value->type() != protocol::Value::TypeObject) {
1092 0 : errors->addError("object expected");
1093 : return nullptr;
1094 : }
1095 :
1096 0 : std::unique_ptr<ExecutionContextDestroyedNotification> result(new ExecutionContextDestroyedNotification());
1097 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
1098 0 : errors->push();
1099 0 : protocol::Value* executionContextIdValue = object->get("executionContextId");
1100 0 : errors->setName("executionContextId");
1101 0 : result->m_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
1102 0 : errors->pop();
1103 0 : if (errors->hasErrors())
1104 : return nullptr;
1105 : return result;
1106 : }
1107 :
1108 25 : std::unique_ptr<protocol::DictionaryValue> ExecutionContextDestroyedNotification::toValue() const
1109 : {
1110 25 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
1111 125 : result->setValue("executionContextId", ValueConversions<int>::toValue(m_executionContextId));
1112 25 : return result;
1113 : }
1114 :
1115 0 : std::unique_ptr<ExecutionContextDestroyedNotification> ExecutionContextDestroyedNotification::clone() const
1116 : {
1117 0 : ErrorSupport errors;
1118 0 : return fromValue(toValue().get(), &errors);
1119 : }
1120 :
1121 0 : std::unique_ptr<InspectRequestedNotification> InspectRequestedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
1122 : {
1123 0 : if (!value || value->type() != protocol::Value::TypeObject) {
1124 0 : errors->addError("object expected");
1125 : return nullptr;
1126 : }
1127 :
1128 0 : std::unique_ptr<InspectRequestedNotification> result(new InspectRequestedNotification());
1129 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
1130 0 : errors->push();
1131 0 : protocol::Value* objectValue = object->get("object");
1132 0 : errors->setName("object");
1133 0 : result->m_object = ValueConversions<protocol::Runtime::RemoteObject>::fromValue(objectValue, errors);
1134 0 : protocol::Value* hintsValue = object->get("hints");
1135 0 : errors->setName("hints");
1136 0 : result->m_hints = ValueConversions<protocol::DictionaryValue>::fromValue(hintsValue, errors);
1137 0 : errors->pop();
1138 0 : if (errors->hasErrors())
1139 : return nullptr;
1140 : return result;
1141 : }
1142 :
1143 80 : std::unique_ptr<protocol::DictionaryValue> InspectRequestedNotification::toValue() const
1144 : {
1145 80 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
1146 320 : result->setValue("object", ValueConversions<protocol::Runtime::RemoteObject>::toValue(m_object.get()));
1147 320 : result->setValue("hints", ValueConversions<protocol::DictionaryValue>::toValue(m_hints.get()));
1148 80 : return result;
1149 : }
1150 :
1151 0 : std::unique_ptr<InspectRequestedNotification> InspectRequestedNotification::clone() const
1152 : {
1153 0 : ErrorSupport errors;
1154 0 : return fromValue(toValue().get(), &errors);
1155 : }
1156 :
1157 : // ------------- Enum values from params.
1158 :
1159 :
1160 : namespace ConsoleAPICalled {
1161 : namespace TypeEnum {
1162 : const char* Log = "log";
1163 : const char* Debug = "debug";
1164 : const char* Info = "info";
1165 : const char* Error = "error";
1166 : const char* Warning = "warning";
1167 : const char* Dir = "dir";
1168 : const char* Dirxml = "dirxml";
1169 : const char* Table = "table";
1170 : const char* Trace = "trace";
1171 : const char* Clear = "clear";
1172 : const char* StartGroup = "startGroup";
1173 : const char* StartGroupCollapsed = "startGroupCollapsed";
1174 : const char* EndGroup = "endGroup";
1175 : const char* Assert = "assert";
1176 : const char* Profile = "profile";
1177 : const char* ProfileEnd = "profileEnd";
1178 : const char* Count = "count";
1179 : const char* TimeEnd = "timeEnd";
1180 : } // namespace TypeEnum
1181 : } // namespace ConsoleAPICalled
1182 :
1183 : // ------------- Frontend notifications.
1184 :
1185 35 : void Frontend::bindingCalled(const String& name, const String& payload, int executionContextId)
1186 : {
1187 35 : if (!m_frontendChannel)
1188 35 : return;
1189 : std::unique_ptr<BindingCalledNotification> messageData = BindingCalledNotification::create()
1190 35 : .setName(name)
1191 : .setPayload(payload)
1192 : .setExecutionContextId(executionContextId)
1193 : .build();
1194 245 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.bindingCalled", std::move(messageData)));
1195 : }
1196 :
1197 6635 : void Frontend::consoleAPICalled(const String& type, std::unique_ptr<protocol::Array<protocol::Runtime::RemoteObject>> args, int executionContextId, double timestamp, Maybe<protocol::Runtime::StackTrace> stackTrace, Maybe<String> context)
1198 : {
1199 6635 : if (!m_frontendChannel)
1200 6635 : return;
1201 : std::unique_ptr<ConsoleAPICalledNotification> messageData = ConsoleAPICalledNotification::create()
1202 6635 : .setType(type)
1203 : .setArgs(std::move(args))
1204 : .setExecutionContextId(executionContextId)
1205 : .setTimestamp(timestamp)
1206 : .build();
1207 6635 : if (stackTrace.isJust())
1208 : messageData->setStackTrace(std::move(stackTrace).takeJust());
1209 6635 : if (context.isJust())
1210 140 : messageData->setContext(std::move(context).takeJust());
1211 46445 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.consoleAPICalled", std::move(messageData)));
1212 : }
1213 :
1214 70 : void Frontend::exceptionRevoked(const String& reason, int exceptionId)
1215 : {
1216 70 : if (!m_frontendChannel)
1217 70 : return;
1218 : std::unique_ptr<ExceptionRevokedNotification> messageData = ExceptionRevokedNotification::create()
1219 70 : .setReason(reason)
1220 : .setExceptionId(exceptionId)
1221 : .build();
1222 490 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.exceptionRevoked", std::move(messageData)));
1223 : }
1224 :
1225 175 : void Frontend::exceptionThrown(double timestamp, std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails)
1226 : {
1227 175 : if (!m_frontendChannel)
1228 175 : return;
1229 : std::unique_ptr<ExceptionThrownNotification> messageData = ExceptionThrownNotification::create()
1230 175 : .setTimestamp(timestamp)
1231 : .setExceptionDetails(std::move(exceptionDetails))
1232 : .build();
1233 1225 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.exceptionThrown", std::move(messageData)));
1234 : }
1235 :
1236 715 : void Frontend::executionContextCreated(std::unique_ptr<protocol::Runtime::ExecutionContextDescription> context)
1237 : {
1238 715 : if (!m_frontendChannel)
1239 715 : return;
1240 : std::unique_ptr<ExecutionContextCreatedNotification> messageData = ExecutionContextCreatedNotification::create()
1241 : .setContext(std::move(context))
1242 : .build();
1243 5005 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.executionContextCreated", std::move(messageData)));
1244 : }
1245 :
1246 25 : void Frontend::executionContextDestroyed(int executionContextId)
1247 : {
1248 25 : if (!m_frontendChannel)
1249 25 : return;
1250 : std::unique_ptr<ExecutionContextDestroyedNotification> messageData = ExecutionContextDestroyedNotification::create()
1251 : .setExecutionContextId(executionContextId)
1252 : .build();
1253 175 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.executionContextDestroyed", std::move(messageData)));
1254 : }
1255 :
1256 40 : void Frontend::executionContextsCleared()
1257 : {
1258 40 : if (!m_frontendChannel)
1259 40 : return;
1260 280 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.executionContextsCleared"));
1261 : }
1262 :
1263 80 : void Frontend::inspectRequested(std::unique_ptr<protocol::Runtime::RemoteObject> object, std::unique_ptr<protocol::DictionaryValue> hints)
1264 : {
1265 80 : if (!m_frontendChannel)
1266 80 : return;
1267 : std::unique_ptr<InspectRequestedNotification> messageData = InspectRequestedNotification::create()
1268 80 : .setObject(std::move(object))
1269 : .setHints(std::move(hints))
1270 : .build();
1271 560 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Runtime.inspectRequested", std::move(messageData)));
1272 : }
1273 :
1274 6880 : void Frontend::flush()
1275 : {
1276 6880 : m_frontendChannel->flushProtocolNotifications();
1277 6880 : }
1278 :
1279 0 : void Frontend::sendRawNotification(const String& notification)
1280 : {
1281 0 : m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
1282 0 : }
1283 :
1284 : // --------------------- Dispatcher.
1285 :
1286 : class DispatcherImpl : public protocol::DispatcherBase {
1287 : public:
1288 3834 : DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
1289 : : DispatcherBase(frontendChannel)
1290 11502 : , m_backend(backend) {
1291 11502 : m_dispatchMap["Runtime.awaitPromise"] = &DispatcherImpl::awaitPromise;
1292 11502 : m_dispatchMap["Runtime.callFunctionOn"] = &DispatcherImpl::callFunctionOn;
1293 11502 : m_dispatchMap["Runtime.compileScript"] = &DispatcherImpl::compileScript;
1294 11502 : m_dispatchMap["Runtime.disable"] = &DispatcherImpl::disable;
1295 11502 : m_dispatchMap["Runtime.discardConsoleEntries"] = &DispatcherImpl::discardConsoleEntries;
1296 11502 : m_dispatchMap["Runtime.enable"] = &DispatcherImpl::enable;
1297 11502 : m_dispatchMap["Runtime.evaluate"] = &DispatcherImpl::evaluate;
1298 11502 : m_dispatchMap["Runtime.getIsolateId"] = &DispatcherImpl::getIsolateId;
1299 11502 : m_dispatchMap["Runtime.getHeapUsage"] = &DispatcherImpl::getHeapUsage;
1300 11502 : m_dispatchMap["Runtime.getProperties"] = &DispatcherImpl::getProperties;
1301 11502 : m_dispatchMap["Runtime.globalLexicalScopeNames"] = &DispatcherImpl::globalLexicalScopeNames;
1302 11502 : m_dispatchMap["Runtime.queryObjects"] = &DispatcherImpl::queryObjects;
1303 11502 : m_dispatchMap["Runtime.releaseObject"] = &DispatcherImpl::releaseObject;
1304 11502 : m_dispatchMap["Runtime.releaseObjectGroup"] = &DispatcherImpl::releaseObjectGroup;
1305 11502 : m_dispatchMap["Runtime.runIfWaitingForDebugger"] = &DispatcherImpl::runIfWaitingForDebugger;
1306 11502 : m_dispatchMap["Runtime.runScript"] = &DispatcherImpl::runScript;
1307 15336 : m_redirects["Runtime.setAsyncCallStackDepth"] = "Debugger.setAsyncCallStackDepth";
1308 11502 : m_dispatchMap["Runtime.setCustomObjectFormatterEnabled"] = &DispatcherImpl::setCustomObjectFormatterEnabled;
1309 11502 : m_dispatchMap["Runtime.setMaxCallStackSizeToCapture"] = &DispatcherImpl::setMaxCallStackSizeToCapture;
1310 11502 : m_dispatchMap["Runtime.terminateExecution"] = &DispatcherImpl::terminateExecution;
1311 11502 : m_dispatchMap["Runtime.addBinding"] = &DispatcherImpl::addBinding;
1312 11502 : m_dispatchMap["Runtime.removeBinding"] = &DispatcherImpl::removeBinding;
1313 3834 : }
1314 11502 : ~DispatcherImpl() override { }
1315 : bool canDispatch(const String& method) override;
1316 : void dispatch(int callId, const String& method, const String& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
1317 : std::unordered_map<String, String>& redirects() { return m_redirects; }
1318 :
1319 : protected:
1320 : using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
1321 : using DispatchMap = std::unordered_map<String, CallHandler>;
1322 : DispatchMap m_dispatchMap;
1323 : std::unordered_map<String, String> m_redirects;
1324 :
1325 : void awaitPromise(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1326 : void callFunctionOn(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1327 : void compileScript(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1328 : void disable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1329 : void discardConsoleEntries(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1330 : void enable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1331 : void evaluate(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1332 : void getIsolateId(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1333 : void getHeapUsage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1334 : void getProperties(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1335 : void globalLexicalScopeNames(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1336 : void queryObjects(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1337 : void releaseObject(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1338 : void releaseObjectGroup(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1339 : void runIfWaitingForDebugger(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1340 : void runScript(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1341 : void setCustomObjectFormatterEnabled(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1342 : void setMaxCallStackSizeToCapture(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1343 : void terminateExecution(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1344 : void addBinding(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1345 : void removeBinding(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
1346 :
1347 : Backend* m_backend;
1348 : };
1349 :
1350 79395 : bool DispatcherImpl::canDispatch(const String& method) {
1351 79395 : return m_dispatchMap.find(method) != m_dispatchMap.end();
1352 : }
1353 :
1354 79395 : void DispatcherImpl::dispatch(int callId, const String& method, const String& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
1355 : {
1356 : std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
1357 : DCHECK(it != m_dispatchMap.end());
1358 79395 : protocol::ErrorSupport errors;
1359 238185 : (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
1360 79395 : }
1361 :
1362 :
1363 70 : class AwaitPromiseCallbackImpl : public Backend::AwaitPromiseCallback, public DispatcherBase::Callback {
1364 : public:
1365 35 : AwaitPromiseCallbackImpl(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, const String& method, const String& message)
1366 70 : : DispatcherBase::Callback(std::move(backendImpl), callId, method, message) { }
1367 :
1368 30 : void sendSuccess(std::unique_ptr<protocol::Runtime::RemoteObject> result, Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails) override
1369 : {
1370 30 : std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
1371 120 : resultObject->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(result.get()));
1372 30 : if (exceptionDetails.isJust())
1373 60 : resultObject->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(exceptionDetails.fromJust()));
1374 120 : sendIfActive(std::move(resultObject), DispatchResponse::OK());
1375 30 : }
1376 :
1377 0 : void fallThrough() override
1378 : {
1379 0 : fallThroughIfActive();
1380 0 : }
1381 :
1382 5 : void sendFailure(const DispatchResponse& response) override
1383 : {
1384 : DCHECK(response.status() == DispatchResponse::kError);
1385 10 : sendIfActive(nullptr, response);
1386 5 : }
1387 : };
1388 :
1389 35 : void DispatcherImpl::awaitPromise(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1390 : {
1391 : // Prepare input parameters.
1392 105 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
1393 35 : errors->push();
1394 70 : protocol::Value* promiseObjectIdValue = object ? object->get("promiseObjectId") : nullptr;
1395 35 : errors->setName("promiseObjectId");
1396 35 : String in_promiseObjectId = ValueConversions<String>::fromValue(promiseObjectIdValue, errors);
1397 70 : protocol::Value* returnByValueValue = object ? object->get("returnByValue") : nullptr;
1398 : Maybe<bool> in_returnByValue;
1399 35 : if (returnByValueValue) {
1400 15 : errors->setName("returnByValue");
1401 15 : in_returnByValue = ValueConversions<bool>::fromValue(returnByValueValue, errors);
1402 : }
1403 70 : protocol::Value* generatePreviewValue = object ? object->get("generatePreview") : nullptr;
1404 : Maybe<bool> in_generatePreview;
1405 35 : if (generatePreviewValue) {
1406 15 : errors->setName("generatePreview");
1407 15 : in_generatePreview = ValueConversions<bool>::fromValue(generatePreviewValue, errors);
1408 : }
1409 35 : errors->pop();
1410 35 : if (errors->hasErrors()) {
1411 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
1412 0 : return;
1413 : }
1414 :
1415 35 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1416 70 : std::unique_ptr<AwaitPromiseCallbackImpl> callback(new AwaitPromiseCallbackImpl(weakPtr(), callId, method, message));
1417 105 : m_backend->awaitPromise(in_promiseObjectId, std::move(in_returnByValue), std::move(in_generatePreview), std::move(callback));
1418 : return;
1419 : }
1420 :
1421 1490 : class CallFunctionOnCallbackImpl : public Backend::CallFunctionOnCallback, public DispatcherBase::Callback {
1422 : public:
1423 745 : CallFunctionOnCallbackImpl(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, const String& method, const String& message)
1424 1490 : : DispatcherBase::Callback(std::move(backendImpl), callId, method, message) { }
1425 :
1426 740 : void sendSuccess(std::unique_ptr<protocol::Runtime::RemoteObject> result, Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails) override
1427 : {
1428 740 : std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
1429 2960 : resultObject->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(result.get()));
1430 740 : if (exceptionDetails.isJust())
1431 80 : resultObject->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(exceptionDetails.fromJust()));
1432 2960 : sendIfActive(std::move(resultObject), DispatchResponse::OK());
1433 740 : }
1434 :
1435 0 : void fallThrough() override
1436 : {
1437 0 : fallThroughIfActive();
1438 0 : }
1439 :
1440 5 : void sendFailure(const DispatchResponse& response) override
1441 : {
1442 : DCHECK(response.status() == DispatchResponse::kError);
1443 10 : sendIfActive(nullptr, response);
1444 5 : }
1445 : };
1446 :
1447 745 : void DispatcherImpl::callFunctionOn(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1448 : {
1449 : // Prepare input parameters.
1450 2235 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
1451 745 : errors->push();
1452 1490 : protocol::Value* functionDeclarationValue = object ? object->get("functionDeclaration") : nullptr;
1453 745 : errors->setName("functionDeclaration");
1454 745 : String in_functionDeclaration = ValueConversions<String>::fromValue(functionDeclarationValue, errors);
1455 1490 : protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
1456 : Maybe<String> in_objectId;
1457 745 : if (objectIdValue) {
1458 740 : errors->setName("objectId");
1459 1480 : in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
1460 : }
1461 1490 : protocol::Value* argumentsValue = object ? object->get("arguments") : nullptr;
1462 : Maybe<protocol::Array<protocol::Runtime::CallArgument>> in_arguments;
1463 745 : if (argumentsValue) {
1464 125 : errors->setName("arguments");
1465 125 : in_arguments = ValueConversions<protocol::Array<protocol::Runtime::CallArgument>>::fromValue(argumentsValue, errors);
1466 : }
1467 1490 : protocol::Value* silentValue = object ? object->get("silent") : nullptr;
1468 : Maybe<bool> in_silent;
1469 745 : if (silentValue) {
1470 0 : errors->setName("silent");
1471 0 : in_silent = ValueConversions<bool>::fromValue(silentValue, errors);
1472 : }
1473 1490 : protocol::Value* returnByValueValue = object ? object->get("returnByValue") : nullptr;
1474 : Maybe<bool> in_returnByValue;
1475 745 : if (returnByValueValue) {
1476 435 : errors->setName("returnByValue");
1477 435 : in_returnByValue = ValueConversions<bool>::fromValue(returnByValueValue, errors);
1478 : }
1479 1490 : protocol::Value* generatePreviewValue = object ? object->get("generatePreview") : nullptr;
1480 : Maybe<bool> in_generatePreview;
1481 745 : if (generatePreviewValue) {
1482 65 : errors->setName("generatePreview");
1483 65 : in_generatePreview = ValueConversions<bool>::fromValue(generatePreviewValue, errors);
1484 : }
1485 1490 : protocol::Value* userGestureValue = object ? object->get("userGesture") : nullptr;
1486 : Maybe<bool> in_userGesture;
1487 745 : if (userGestureValue) {
1488 0 : errors->setName("userGesture");
1489 0 : in_userGesture = ValueConversions<bool>::fromValue(userGestureValue, errors);
1490 : }
1491 1490 : protocol::Value* awaitPromiseValue = object ? object->get("awaitPromise") : nullptr;
1492 : Maybe<bool> in_awaitPromise;
1493 745 : if (awaitPromiseValue) {
1494 55 : errors->setName("awaitPromise");
1495 55 : in_awaitPromise = ValueConversions<bool>::fromValue(awaitPromiseValue, errors);
1496 : }
1497 1490 : protocol::Value* executionContextIdValue = object ? object->get("executionContextId") : nullptr;
1498 : Maybe<int> in_executionContextId;
1499 745 : if (executionContextIdValue) {
1500 10 : errors->setName("executionContextId");
1501 10 : in_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
1502 : }
1503 1490 : protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
1504 : Maybe<String> in_objectGroup;
1505 745 : if (objectGroupValue) {
1506 0 : errors->setName("objectGroup");
1507 0 : in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
1508 : }
1509 745 : errors->pop();
1510 745 : if (errors->hasErrors()) {
1511 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
1512 0 : return;
1513 : }
1514 :
1515 745 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1516 1490 : std::unique_ptr<CallFunctionOnCallbackImpl> callback(new CallFunctionOnCallbackImpl(weakPtr(), callId, method, message));
1517 4470 : m_backend->callFunctionOn(in_functionDeclaration, std::move(in_objectId), std::move(in_arguments), std::move(in_silent), std::move(in_returnByValue), std::move(in_generatePreview), std::move(in_userGesture), std::move(in_awaitPromise), std::move(in_executionContextId), std::move(in_objectGroup), std::move(callback));
1518 : return;
1519 : }
1520 :
1521 265 : void DispatcherImpl::compileScript(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1522 : {
1523 : // Prepare input parameters.
1524 795 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
1525 265 : errors->push();
1526 530 : protocol::Value* expressionValue = object ? object->get("expression") : nullptr;
1527 265 : errors->setName("expression");
1528 265 : String in_expression = ValueConversions<String>::fromValue(expressionValue, errors);
1529 530 : protocol::Value* sourceURLValue = object ? object->get("sourceURL") : nullptr;
1530 265 : errors->setName("sourceURL");
1531 265 : String in_sourceURL = ValueConversions<String>::fromValue(sourceURLValue, errors);
1532 530 : protocol::Value* persistScriptValue = object ? object->get("persistScript") : nullptr;
1533 265 : errors->setName("persistScript");
1534 265 : bool in_persistScript = ValueConversions<bool>::fromValue(persistScriptValue, errors);
1535 530 : protocol::Value* executionContextIdValue = object ? object->get("executionContextId") : nullptr;
1536 : Maybe<int> in_executionContextId;
1537 265 : if (executionContextIdValue) {
1538 20 : errors->setName("executionContextId");
1539 20 : in_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
1540 : }
1541 265 : errors->pop();
1542 265 : if (errors->hasErrors()) {
1543 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
1544 0 : return;
1545 : }
1546 : // Declare output parameters.
1547 : Maybe<String> out_scriptId;
1548 : Maybe<protocol::Runtime::ExceptionDetails> out_exceptionDetails;
1549 :
1550 265 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1551 530 : DispatchResponse response = m_backend->compileScript(in_expression, in_sourceURL, in_persistScript, std::move(in_executionContextId), &out_scriptId, &out_exceptionDetails);
1552 265 : if (response.status() == DispatchResponse::kFallThrough) {
1553 0 : channel()->fallThrough(callId, method, message);
1554 0 : return;
1555 : }
1556 265 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
1557 265 : if (response.status() == DispatchResponse::kSuccess) {
1558 260 : if (out_scriptId.isJust())
1559 1125 : result->setValue("scriptId", ValueConversions<String>::toValue(out_scriptId.fromJust()));
1560 260 : if (out_exceptionDetails.isJust())
1561 100 : result->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(out_exceptionDetails.fromJust()));
1562 : }
1563 265 : if (weak->get())
1564 530 : weak->get()->sendResponse(callId, response, std::move(result));
1565 : return;
1566 : }
1567 :
1568 360 : void DispatcherImpl::disable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1569 : {
1570 :
1571 360 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1572 360 : DispatchResponse response = m_backend->disable();
1573 360 : if (response.status() == DispatchResponse::kFallThrough) {
1574 0 : channel()->fallThrough(callId, method, message);
1575 0 : return;
1576 : }
1577 360 : if (weak->get())
1578 360 : weak->get()->sendResponse(callId, response);
1579 : return;
1580 : }
1581 :
1582 5 : void DispatcherImpl::discardConsoleEntries(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1583 : {
1584 :
1585 5 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1586 5 : DispatchResponse response = m_backend->discardConsoleEntries();
1587 5 : if (response.status() == DispatchResponse::kFallThrough) {
1588 0 : channel()->fallThrough(callId, method, message);
1589 0 : return;
1590 : }
1591 5 : if (weak->get())
1592 5 : weak->get()->sendResponse(callId, response);
1593 : return;
1594 : }
1595 :
1596 665 : void DispatcherImpl::enable(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1597 : {
1598 :
1599 665 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1600 665 : DispatchResponse response = m_backend->enable();
1601 665 : if (response.status() == DispatchResponse::kFallThrough) {
1602 0 : channel()->fallThrough(callId, method, message);
1603 0 : return;
1604 : }
1605 665 : if (weak->get())
1606 665 : weak->get()->sendResponse(callId, response);
1607 : return;
1608 : }
1609 :
1610 17146 : class EvaluateCallbackImpl : public Backend::EvaluateCallback, public DispatcherBase::Callback {
1611 : public:
1612 8573 : EvaluateCallbackImpl(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, const String& method, const String& message)
1613 17146 : : DispatcherBase::Callback(std::move(backendImpl), callId, method, message) { }
1614 :
1615 8478 : void sendSuccess(std::unique_ptr<protocol::Runtime::RemoteObject> result, Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails) override
1616 : {
1617 8478 : std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
1618 33912 : resultObject->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(result.get()));
1619 8478 : if (exceptionDetails.isJust())
1620 1432 : resultObject->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(exceptionDetails.fromJust()));
1621 33912 : sendIfActive(std::move(resultObject), DispatchResponse::OK());
1622 8478 : }
1623 :
1624 0 : void fallThrough() override
1625 : {
1626 0 : fallThroughIfActive();
1627 0 : }
1628 :
1629 95 : void sendFailure(const DispatchResponse& response) override
1630 : {
1631 : DCHECK(response.status() == DispatchResponse::kError);
1632 190 : sendIfActive(nullptr, response);
1633 95 : }
1634 : };
1635 :
1636 8578 : void DispatcherImpl::evaluate(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1637 : {
1638 : // Prepare input parameters.
1639 25734 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
1640 8578 : errors->push();
1641 17156 : protocol::Value* expressionValue = object ? object->get("expression") : nullptr;
1642 8578 : errors->setName("expression");
1643 8578 : String in_expression = ValueConversions<String>::fromValue(expressionValue, errors);
1644 17156 : protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
1645 : Maybe<String> in_objectGroup;
1646 8578 : if (objectGroupValue) {
1647 180 : errors->setName("objectGroup");
1648 360 : in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
1649 : }
1650 17156 : protocol::Value* includeCommandLineAPIValue = object ? object->get("includeCommandLineAPI") : nullptr;
1651 : Maybe<bool> in_includeCommandLineAPI;
1652 8578 : if (includeCommandLineAPIValue) {
1653 545 : errors->setName("includeCommandLineAPI");
1654 545 : in_includeCommandLineAPI = ValueConversions<bool>::fromValue(includeCommandLineAPIValue, errors);
1655 : }
1656 17156 : protocol::Value* silentValue = object ? object->get("silent") : nullptr;
1657 : Maybe<bool> in_silent;
1658 8578 : if (silentValue) {
1659 20 : errors->setName("silent");
1660 20 : in_silent = ValueConversions<bool>::fromValue(silentValue, errors);
1661 : }
1662 17156 : protocol::Value* contextIdValue = object ? object->get("contextId") : nullptr;
1663 : Maybe<int> in_contextId;
1664 8578 : if (contextIdValue) {
1665 5 : errors->setName("contextId");
1666 5 : in_contextId = ValueConversions<int>::fromValue(contextIdValue, errors);
1667 : }
1668 17156 : protocol::Value* returnByValueValue = object ? object->get("returnByValue") : nullptr;
1669 : Maybe<bool> in_returnByValue;
1670 8578 : if (returnByValueValue) {
1671 250 : errors->setName("returnByValue");
1672 250 : in_returnByValue = ValueConversions<bool>::fromValue(returnByValueValue, errors);
1673 : }
1674 17156 : protocol::Value* generatePreviewValue = object ? object->get("generatePreview") : nullptr;
1675 : Maybe<bool> in_generatePreview;
1676 8578 : if (generatePreviewValue) {
1677 590 : errors->setName("generatePreview");
1678 590 : in_generatePreview = ValueConversions<bool>::fromValue(generatePreviewValue, errors);
1679 : }
1680 17156 : protocol::Value* userGestureValue = object ? object->get("userGesture") : nullptr;
1681 : Maybe<bool> in_userGesture;
1682 8578 : if (userGestureValue) {
1683 0 : errors->setName("userGesture");
1684 0 : in_userGesture = ValueConversions<bool>::fromValue(userGestureValue, errors);
1685 : }
1686 17156 : protocol::Value* awaitPromiseValue = object ? object->get("awaitPromise") : nullptr;
1687 : Maybe<bool> in_awaitPromise;
1688 8578 : if (awaitPromiseValue) {
1689 685 : errors->setName("awaitPromise");
1690 685 : in_awaitPromise = ValueConversions<bool>::fromValue(awaitPromiseValue, errors);
1691 : }
1692 17156 : protocol::Value* throwOnSideEffectValue = object ? object->get("throwOnSideEffect") : nullptr;
1693 : Maybe<bool> in_throwOnSideEffect;
1694 8578 : if (throwOnSideEffectValue) {
1695 512 : errors->setName("throwOnSideEffect");
1696 512 : in_throwOnSideEffect = ValueConversions<bool>::fromValue(throwOnSideEffectValue, errors);
1697 : }
1698 17156 : protocol::Value* timeoutValue = object ? object->get("timeout") : nullptr;
1699 : Maybe<double> in_timeout;
1700 8578 : if (timeoutValue) {
1701 15 : errors->setName("timeout");
1702 15 : in_timeout = ValueConversions<double>::fromValue(timeoutValue, errors);
1703 : }
1704 8578 : errors->pop();
1705 8578 : if (errors->hasErrors()) {
1706 10 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
1707 5 : return;
1708 : }
1709 :
1710 8573 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1711 17146 : std::unique_ptr<EvaluateCallbackImpl> callback(new EvaluateCallbackImpl(weakPtr(), callId, method, message));
1712 34292 : m_backend->evaluate(in_expression, std::move(in_objectGroup), std::move(in_includeCommandLineAPI), std::move(in_silent), std::move(in_contextId), std::move(in_returnByValue), std::move(in_generatePreview), std::move(in_userGesture), std::move(in_awaitPromise), std::move(in_throwOnSideEffect), std::move(in_timeout), std::move(callback));
1713 : return;
1714 : }
1715 :
1716 5 : void DispatcherImpl::getIsolateId(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1717 : {
1718 : // Declare output parameters.
1719 5 : String out_id;
1720 :
1721 5 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1722 5 : DispatchResponse response = m_backend->getIsolateId(&out_id);
1723 5 : if (response.status() == DispatchResponse::kFallThrough) {
1724 0 : channel()->fallThrough(callId, method, message);
1725 0 : return;
1726 : }
1727 5 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
1728 5 : if (response.status() == DispatchResponse::kSuccess) {
1729 20 : result->setValue("id", ValueConversions<String>::toValue(out_id));
1730 : }
1731 5 : if (weak->get())
1732 10 : weak->get()->sendResponse(callId, response, std::move(result));
1733 : return;
1734 : }
1735 :
1736 5 : void DispatcherImpl::getHeapUsage(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1737 : {
1738 : // Declare output parameters.
1739 : double out_usedSize;
1740 : double out_totalSize;
1741 :
1742 5 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1743 5 : DispatchResponse response = m_backend->getHeapUsage(&out_usedSize, &out_totalSize);
1744 5 : if (response.status() == DispatchResponse::kFallThrough) {
1745 0 : channel()->fallThrough(callId, method, message);
1746 0 : return;
1747 : }
1748 5 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
1749 5 : if (response.status() == DispatchResponse::kSuccess) {
1750 25 : result->setValue("usedSize", ValueConversions<double>::toValue(out_usedSize));
1751 25 : result->setValue("totalSize", ValueConversions<double>::toValue(out_totalSize));
1752 : }
1753 5 : if (weak->get())
1754 10 : weak->get()->sendResponse(callId, response, std::move(result));
1755 : return;
1756 : }
1757 :
1758 68292 : void DispatcherImpl::getProperties(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1759 : {
1760 : // Prepare input parameters.
1761 204876 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
1762 68292 : errors->push();
1763 136584 : protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
1764 68292 : errors->setName("objectId");
1765 68292 : String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
1766 136584 : protocol::Value* ownPropertiesValue = object ? object->get("ownProperties") : nullptr;
1767 : Maybe<bool> in_ownProperties;
1768 68292 : if (ownPropertiesValue) {
1769 67517 : errors->setName("ownProperties");
1770 67517 : in_ownProperties = ValueConversions<bool>::fromValue(ownPropertiesValue, errors);
1771 : }
1772 136584 : protocol::Value* accessorPropertiesOnlyValue = object ? object->get("accessorPropertiesOnly") : nullptr;
1773 : Maybe<bool> in_accessorPropertiesOnly;
1774 68292 : if (accessorPropertiesOnlyValue) {
1775 5 : errors->setName("accessorPropertiesOnly");
1776 5 : in_accessorPropertiesOnly = ValueConversions<bool>::fromValue(accessorPropertiesOnlyValue, errors);
1777 : }
1778 136584 : protocol::Value* generatePreviewValue = object ? object->get("generatePreview") : nullptr;
1779 : Maybe<bool> in_generatePreview;
1780 68292 : if (generatePreviewValue) {
1781 25 : errors->setName("generatePreview");
1782 25 : in_generatePreview = ValueConversions<bool>::fromValue(generatePreviewValue, errors);
1783 : }
1784 68292 : errors->pop();
1785 68292 : if (errors->hasErrors()) {
1786 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
1787 0 : return;
1788 : }
1789 : // Declare output parameters.
1790 68292 : std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>> out_result;
1791 : Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>> out_internalProperties;
1792 : Maybe<protocol::Runtime::ExceptionDetails> out_exceptionDetails;
1793 :
1794 68292 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1795 136584 : DispatchResponse response = m_backend->getProperties(in_objectId, std::move(in_ownProperties), std::move(in_accessorPropertiesOnly), std::move(in_generatePreview), &out_result, &out_internalProperties, &out_exceptionDetails);
1796 68292 : if (response.status() == DispatchResponse::kFallThrough) {
1797 0 : channel()->fallThrough(callId, method, message);
1798 0 : return;
1799 : }
1800 68292 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
1801 68292 : if (response.status() == DispatchResponse::kSuccess) {
1802 273168 : result->setValue("result", ValueConversions<protocol::Array<protocol::Runtime::PropertyDescriptor>>::toValue(out_result.get()));
1803 68292 : if (out_internalProperties.isJust())
1804 1768 : result->setValue("internalProperties", ValueConversions<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>::toValue(out_internalProperties.fromJust()));
1805 68292 : if (out_exceptionDetails.isJust())
1806 0 : result->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(out_exceptionDetails.fromJust()));
1807 : }
1808 68292 : if (weak->get())
1809 136584 : weak->get()->sendResponse(callId, response, std::move(result));
1810 : return;
1811 : }
1812 :
1813 35 : void DispatcherImpl::globalLexicalScopeNames(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1814 : {
1815 : // Prepare input parameters.
1816 105 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
1817 35 : errors->push();
1818 70 : protocol::Value* executionContextIdValue = object ? object->get("executionContextId") : nullptr;
1819 : Maybe<int> in_executionContextId;
1820 35 : if (executionContextIdValue) {
1821 0 : errors->setName("executionContextId");
1822 0 : in_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
1823 : }
1824 35 : errors->pop();
1825 35 : if (errors->hasErrors()) {
1826 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
1827 0 : return;
1828 : }
1829 : // Declare output parameters.
1830 35 : std::unique_ptr<protocol::Array<String>> out_names;
1831 :
1832 35 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1833 70 : DispatchResponse response = m_backend->globalLexicalScopeNames(std::move(in_executionContextId), &out_names);
1834 35 : if (response.status() == DispatchResponse::kFallThrough) {
1835 0 : channel()->fallThrough(callId, method, message);
1836 0 : return;
1837 : }
1838 35 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
1839 35 : if (response.status() == DispatchResponse::kSuccess) {
1840 140 : result->setValue("names", ValueConversions<protocol::Array<String>>::toValue(out_names.get()));
1841 : }
1842 35 : if (weak->get())
1843 70 : weak->get()->sendResponse(callId, response, std::move(result));
1844 : return;
1845 : }
1846 :
1847 85 : void DispatcherImpl::queryObjects(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1848 : {
1849 : // Prepare input parameters.
1850 255 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
1851 85 : errors->push();
1852 170 : protocol::Value* prototypeObjectIdValue = object ? object->get("prototypeObjectId") : nullptr;
1853 85 : errors->setName("prototypeObjectId");
1854 85 : String in_prototypeObjectId = ValueConversions<String>::fromValue(prototypeObjectIdValue, errors);
1855 170 : protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
1856 : Maybe<String> in_objectGroup;
1857 85 : if (objectGroupValue) {
1858 20 : errors->setName("objectGroup");
1859 40 : in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
1860 : }
1861 85 : errors->pop();
1862 85 : if (errors->hasErrors()) {
1863 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
1864 0 : return;
1865 : }
1866 : // Declare output parameters.
1867 85 : std::unique_ptr<protocol::Runtime::RemoteObject> out_objects;
1868 :
1869 85 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1870 255 : DispatchResponse response = m_backend->queryObjects(in_prototypeObjectId, std::move(in_objectGroup), &out_objects);
1871 85 : if (response.status() == DispatchResponse::kFallThrough) {
1872 0 : channel()->fallThrough(callId, method, message);
1873 0 : return;
1874 : }
1875 85 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
1876 85 : if (response.status() == DispatchResponse::kSuccess) {
1877 340 : result->setValue("objects", ValueConversions<protocol::Runtime::RemoteObject>::toValue(out_objects.get()));
1878 : }
1879 85 : if (weak->get())
1880 170 : weak->get()->sendResponse(callId, response, std::move(result));
1881 : return;
1882 : }
1883 :
1884 5 : void DispatcherImpl::releaseObject(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1885 : {
1886 : // Prepare input parameters.
1887 15 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
1888 5 : errors->push();
1889 10 : protocol::Value* objectIdValue = object ? object->get("objectId") : nullptr;
1890 5 : errors->setName("objectId");
1891 5 : String in_objectId = ValueConversions<String>::fromValue(objectIdValue, errors);
1892 5 : errors->pop();
1893 5 : if (errors->hasErrors()) {
1894 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
1895 0 : return;
1896 : }
1897 :
1898 5 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1899 5 : DispatchResponse response = m_backend->releaseObject(in_objectId);
1900 5 : if (response.status() == DispatchResponse::kFallThrough) {
1901 0 : channel()->fallThrough(callId, method, message);
1902 0 : return;
1903 : }
1904 5 : if (weak->get())
1905 5 : weak->get()->sendResponse(callId, response);
1906 : return;
1907 : }
1908 :
1909 5 : void DispatcherImpl::releaseObjectGroup(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1910 : {
1911 : // Prepare input parameters.
1912 15 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
1913 5 : errors->push();
1914 10 : protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
1915 5 : errors->setName("objectGroup");
1916 5 : String in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
1917 5 : errors->pop();
1918 5 : if (errors->hasErrors()) {
1919 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
1920 0 : return;
1921 : }
1922 :
1923 5 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1924 5 : DispatchResponse response = m_backend->releaseObjectGroup(in_objectGroup);
1925 5 : if (response.status() == DispatchResponse::kFallThrough) {
1926 0 : channel()->fallThrough(callId, method, message);
1927 0 : return;
1928 : }
1929 5 : if (weak->get())
1930 5 : weak->get()->sendResponse(callId, response);
1931 : return;
1932 : }
1933 :
1934 0 : void DispatcherImpl::runIfWaitingForDebugger(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1935 : {
1936 :
1937 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
1938 0 : DispatchResponse response = m_backend->runIfWaitingForDebugger();
1939 0 : if (response.status() == DispatchResponse::kFallThrough) {
1940 0 : channel()->fallThrough(callId, method, message);
1941 0 : return;
1942 : }
1943 0 : if (weak->get())
1944 0 : weak->get()->sendResponse(callId, response);
1945 : return;
1946 : }
1947 :
1948 430 : class RunScriptCallbackImpl : public Backend::RunScriptCallback, public DispatcherBase::Callback {
1949 : public:
1950 215 : RunScriptCallbackImpl(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, const String& method, const String& message)
1951 430 : : DispatcherBase::Callback(std::move(backendImpl), callId, method, message) { }
1952 :
1953 195 : void sendSuccess(std::unique_ptr<protocol::Runtime::RemoteObject> result, Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails) override
1954 : {
1955 195 : std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
1956 780 : resultObject->setValue("result", ValueConversions<protocol::Runtime::RemoteObject>::toValue(result.get()));
1957 195 : if (exceptionDetails.isJust())
1958 40 : resultObject->setValue("exceptionDetails", ValueConversions<protocol::Runtime::ExceptionDetails>::toValue(exceptionDetails.fromJust()));
1959 780 : sendIfActive(std::move(resultObject), DispatchResponse::OK());
1960 195 : }
1961 :
1962 0 : void fallThrough() override
1963 : {
1964 0 : fallThroughIfActive();
1965 0 : }
1966 :
1967 20 : void sendFailure(const DispatchResponse& response) override
1968 : {
1969 : DCHECK(response.status() == DispatchResponse::kError);
1970 40 : sendIfActive(nullptr, response);
1971 20 : }
1972 : };
1973 :
1974 215 : void DispatcherImpl::runScript(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
1975 : {
1976 : // Prepare input parameters.
1977 645 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
1978 215 : errors->push();
1979 430 : protocol::Value* scriptIdValue = object ? object->get("scriptId") : nullptr;
1980 215 : errors->setName("scriptId");
1981 215 : String in_scriptId = ValueConversions<String>::fromValue(scriptIdValue, errors);
1982 430 : protocol::Value* executionContextIdValue = object ? object->get("executionContextId") : nullptr;
1983 : Maybe<int> in_executionContextId;
1984 215 : if (executionContextIdValue) {
1985 0 : errors->setName("executionContextId");
1986 0 : in_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
1987 : }
1988 430 : protocol::Value* objectGroupValue = object ? object->get("objectGroup") : nullptr;
1989 : Maybe<String> in_objectGroup;
1990 215 : if (objectGroupValue) {
1991 0 : errors->setName("objectGroup");
1992 0 : in_objectGroup = ValueConversions<String>::fromValue(objectGroupValue, errors);
1993 : }
1994 430 : protocol::Value* silentValue = object ? object->get("silent") : nullptr;
1995 : Maybe<bool> in_silent;
1996 215 : if (silentValue) {
1997 0 : errors->setName("silent");
1998 0 : in_silent = ValueConversions<bool>::fromValue(silentValue, errors);
1999 : }
2000 430 : protocol::Value* includeCommandLineAPIValue = object ? object->get("includeCommandLineAPI") : nullptr;
2001 : Maybe<bool> in_includeCommandLineAPI;
2002 215 : if (includeCommandLineAPIValue) {
2003 0 : errors->setName("includeCommandLineAPI");
2004 0 : in_includeCommandLineAPI = ValueConversions<bool>::fromValue(includeCommandLineAPIValue, errors);
2005 : }
2006 430 : protocol::Value* returnByValueValue = object ? object->get("returnByValue") : nullptr;
2007 : Maybe<bool> in_returnByValue;
2008 215 : if (returnByValueValue) {
2009 20 : errors->setName("returnByValue");
2010 20 : in_returnByValue = ValueConversions<bool>::fromValue(returnByValueValue, errors);
2011 : }
2012 430 : protocol::Value* generatePreviewValue = object ? object->get("generatePreview") : nullptr;
2013 : Maybe<bool> in_generatePreview;
2014 215 : if (generatePreviewValue) {
2015 5 : errors->setName("generatePreview");
2016 5 : in_generatePreview = ValueConversions<bool>::fromValue(generatePreviewValue, errors);
2017 : }
2018 430 : protocol::Value* awaitPromiseValue = object ? object->get("awaitPromise") : nullptr;
2019 : Maybe<bool> in_awaitPromise;
2020 215 : if (awaitPromiseValue) {
2021 15 : errors->setName("awaitPromise");
2022 15 : in_awaitPromise = ValueConversions<bool>::fromValue(awaitPromiseValue, errors);
2023 : }
2024 215 : errors->pop();
2025 215 : if (errors->hasErrors()) {
2026 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
2027 0 : return;
2028 : }
2029 :
2030 215 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
2031 430 : std::unique_ptr<RunScriptCallbackImpl> callback(new RunScriptCallbackImpl(weakPtr(), callId, method, message));
2032 860 : m_backend->runScript(in_scriptId, std::move(in_executionContextId), std::move(in_objectGroup), std::move(in_silent), std::move(in_includeCommandLineAPI), std::move(in_returnByValue), std::move(in_generatePreview), std::move(in_awaitPromise), std::move(callback));
2033 : return;
2034 : }
2035 :
2036 10 : void DispatcherImpl::setCustomObjectFormatterEnabled(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
2037 : {
2038 : // Prepare input parameters.
2039 30 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
2040 10 : errors->push();
2041 20 : protocol::Value* enabledValue = object ? object->get("enabled") : nullptr;
2042 10 : errors->setName("enabled");
2043 10 : bool in_enabled = ValueConversions<bool>::fromValue(enabledValue, errors);
2044 10 : errors->pop();
2045 10 : if (errors->hasErrors()) {
2046 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
2047 0 : return;
2048 : }
2049 :
2050 10 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
2051 10 : DispatchResponse response = m_backend->setCustomObjectFormatterEnabled(in_enabled);
2052 10 : if (response.status() == DispatchResponse::kFallThrough) {
2053 0 : channel()->fallThrough(callId, method, message);
2054 0 : return;
2055 : }
2056 10 : if (weak->get())
2057 10 : weak->get()->sendResponse(callId, response);
2058 : return;
2059 : }
2060 :
2061 15 : void DispatcherImpl::setMaxCallStackSizeToCapture(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
2062 : {
2063 : // Prepare input parameters.
2064 45 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
2065 15 : errors->push();
2066 30 : protocol::Value* sizeValue = object ? object->get("size") : nullptr;
2067 15 : errors->setName("size");
2068 15 : int in_size = ValueConversions<int>::fromValue(sizeValue, errors);
2069 15 : errors->pop();
2070 15 : if (errors->hasErrors()) {
2071 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
2072 0 : return;
2073 : }
2074 :
2075 15 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
2076 15 : DispatchResponse response = m_backend->setMaxCallStackSizeToCapture(in_size);
2077 15 : if (response.status() == DispatchResponse::kFallThrough) {
2078 0 : channel()->fallThrough(callId, method, message);
2079 0 : return;
2080 : }
2081 15 : if (weak->get())
2082 15 : weak->get()->sendResponse(callId, response);
2083 : return;
2084 : }
2085 :
2086 80 : class TerminateExecutionCallbackImpl : public Backend::TerminateExecutionCallback, public DispatcherBase::Callback {
2087 : public:
2088 40 : TerminateExecutionCallbackImpl(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, const String& method, const String& message)
2089 80 : : DispatcherBase::Callback(std::move(backendImpl), callId, method, message) { }
2090 :
2091 40 : void sendSuccess() override
2092 : {
2093 40 : std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
2094 160 : sendIfActive(std::move(resultObject), DispatchResponse::OK());
2095 40 : }
2096 :
2097 0 : void fallThrough() override
2098 : {
2099 0 : fallThroughIfActive();
2100 0 : }
2101 :
2102 0 : void sendFailure(const DispatchResponse& response) override
2103 : {
2104 : DCHECK(response.status() == DispatchResponse::kError);
2105 0 : sendIfActive(nullptr, response);
2106 0 : }
2107 : };
2108 :
2109 40 : void DispatcherImpl::terminateExecution(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
2110 : {
2111 :
2112 40 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
2113 80 : std::unique_ptr<TerminateExecutionCallbackImpl> callback(new TerminateExecutionCallbackImpl(weakPtr(), callId, method, message));
2114 120 : m_backend->terminateExecution(std::move(callback));
2115 40 : return;
2116 : }
2117 :
2118 25 : void DispatcherImpl::addBinding(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
2119 : {
2120 : // Prepare input parameters.
2121 75 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
2122 25 : errors->push();
2123 50 : protocol::Value* nameValue = object ? object->get("name") : nullptr;
2124 25 : errors->setName("name");
2125 25 : String in_name = ValueConversions<String>::fromValue(nameValue, errors);
2126 50 : protocol::Value* executionContextIdValue = object ? object->get("executionContextId") : nullptr;
2127 : Maybe<int> in_executionContextId;
2128 25 : if (executionContextIdValue) {
2129 0 : errors->setName("executionContextId");
2130 0 : in_executionContextId = ValueConversions<int>::fromValue(executionContextIdValue, errors);
2131 : }
2132 25 : errors->pop();
2133 25 : if (errors->hasErrors()) {
2134 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
2135 0 : return;
2136 : }
2137 :
2138 25 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
2139 50 : DispatchResponse response = m_backend->addBinding(in_name, std::move(in_executionContextId));
2140 25 : if (response.status() == DispatchResponse::kFallThrough) {
2141 0 : channel()->fallThrough(callId, method, message);
2142 0 : return;
2143 : }
2144 25 : if (weak->get())
2145 25 : weak->get()->sendResponse(callId, response);
2146 : return;
2147 : }
2148 :
2149 5 : void DispatcherImpl::removeBinding(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
2150 : {
2151 : // Prepare input parameters.
2152 15 : protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
2153 5 : errors->push();
2154 10 : protocol::Value* nameValue = object ? object->get("name") : nullptr;
2155 5 : errors->setName("name");
2156 5 : String in_name = ValueConversions<String>::fromValue(nameValue, errors);
2157 5 : errors->pop();
2158 5 : if (errors->hasErrors()) {
2159 0 : reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
2160 0 : return;
2161 : }
2162 :
2163 5 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
2164 5 : DispatchResponse response = m_backend->removeBinding(in_name);
2165 5 : if (response.status() == DispatchResponse::kFallThrough) {
2166 0 : channel()->fallThrough(callId, method, message);
2167 0 : return;
2168 : }
2169 5 : if (weak->get())
2170 5 : weak->get()->sendResponse(callId, response);
2171 : return;
2172 : }
2173 :
2174 : // static
2175 3834 : void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
2176 : {
2177 3834 : std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
2178 3834 : uber->setupRedirects(dispatcher->redirects());
2179 11502 : uber->registerBackend("Runtime", std::move(dispatcher));
2180 3834 : }
2181 :
2182 : } // Runtime
2183 : } // namespace v8_inspector
2184 : } // namespace protocol
|