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