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