Line data Source code
1 : // Copyright 2016 The Chromium Authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef v8_inspector_protocol_Collections_h
6 : #define v8_inspector_protocol_Collections_h
7 :
8 : #include "src/inspector/protocol/Forward.h"
9 : #include <cstddef>
10 :
11 : #if defined(__APPLE__) && !defined(_LIBCPP_VERSION)
12 : #include <map>
13 : #include <set>
14 :
15 : namespace v8_inspector {
16 : namespace protocol {
17 :
18 : template <class Key, class T> using HashMap = std::map<Key, T>;
19 : template <class Key> using HashSet = std::set<Key>;
20 :
21 : } // namespace v8_inspector
22 : } // namespace protocol
23 :
24 : #else
25 : #include <unordered_map>
26 : #include <unordered_set>
27 :
28 : namespace v8_inspector {
29 : namespace protocol {
30 :
31 : template <class Key, class T> using HashMap = std::unordered_map<Key, T>;
32 : template <class Key> using HashSet = std::unordered_set<Key>;
33 :
34 : } // namespace v8_inspector
35 : } // namespace protocol
36 :
37 : #endif // defined(__APPLE__) && !defined(_LIBCPP_VERSION)
38 :
39 : #endif // !defined(v8_inspector_protocol_Collections_h)
40 :
41 :
42 : // Copyright 2016 The Chromium Authors. All rights reserved.
43 : // Use of this source code is governed by a BSD-style license that can be
44 : // found in the LICENSE file.
45 :
46 : #ifndef v8_inspector_protocol_ErrorSupport_h
47 : #define v8_inspector_protocol_ErrorSupport_h
48 :
49 : //#include "Forward.h"
50 :
51 : namespace v8_inspector {
52 : namespace protocol {
53 :
54 : class ErrorSupport {
55 : public:
56 : ErrorSupport();
57 : ~ErrorSupport();
58 :
59 : void push();
60 : void setName(const String&);
61 : void pop();
62 : void addError(const String&);
63 : bool hasErrors();
64 : String errors();
65 :
66 : private:
67 : std::vector<String> m_path;
68 : std::vector<String> m_errors;
69 : };
70 :
71 : } // namespace v8_inspector
72 : } // namespace protocol
73 :
74 : #endif // !defined(v8_inspector_protocol_ErrorSupport_h)
75 :
76 :
77 : // Copyright 2016 The Chromium Authors. All rights reserved.
78 : // Use of this source code is governed by a BSD-style license that can be
79 : // found in the LICENSE file.
80 :
81 : #ifndef v8_inspector_protocol_Values_h
82 : #define v8_inspector_protocol_Values_h
83 :
84 : //#include "Allocator.h"
85 : //#include "Collections.h"
86 : //#include "Forward.h"
87 :
88 : namespace v8_inspector {
89 : namespace protocol {
90 :
91 : class ListValue;
92 : class DictionaryValue;
93 : class Value;
94 :
95 : class Value : public Serializable {
96 : PROTOCOL_DISALLOW_COPY(Value);
97 : public:
98 96417074 : virtual ~Value() override { }
99 :
100 : static std::unique_ptr<Value> null()
101 : {
102 10944 : return std::unique_ptr<Value>(new Value());
103 : }
104 :
105 : enum ValueType {
106 : TypeNull = 0,
107 : TypeBoolean,
108 : TypeInteger,
109 : TypeDouble,
110 : TypeString,
111 : TypeObject,
112 : TypeArray,
113 : TypeSerialized
114 : };
115 :
116 : ValueType type() const { return m_type; }
117 :
118 : bool isNull() const { return m_type == TypeNull; }
119 :
120 : virtual bool asBoolean(bool* output) const;
121 : virtual bool asDouble(double* output) const;
122 : virtual bool asInteger(int* output) const;
123 : virtual bool asString(String* output) const;
124 : virtual bool asSerialized(String* output) const;
125 :
126 : virtual void writeJSON(StringBuilder* output) const;
127 : virtual std::unique_ptr<Value> clone() const;
128 : String serialize() override;
129 :
130 : protected:
131 10944 : Value() : m_type(TypeNull) { }
132 96395186 : explicit Value(ValueType type) : m_type(type) { }
133 :
134 : private:
135 : friend class DictionaryValue;
136 : friend class ListValue;
137 :
138 : ValueType m_type;
139 : };
140 :
141 64591338 : class FundamentalValue : public Value {
142 : public:
143 28094440 : static std::unique_ptr<FundamentalValue> create(bool value)
144 : {
145 56188880 : return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
146 : }
147 :
148 4113927 : static std::unique_ptr<FundamentalValue> create(int value)
149 : {
150 8227854 : return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
151 : }
152 :
153 87302 : static std::unique_ptr<FundamentalValue> create(double value)
154 : {
155 174604 : return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
156 : }
157 :
158 : bool asBoolean(bool* output) const override;
159 : bool asDouble(double* output) const override;
160 : bool asInteger(int* output) const override;
161 : void writeJSON(StringBuilder* output) const override;
162 : std::unique_ptr<Value> clone() const override;
163 :
164 : private:
165 28094440 : explicit FundamentalValue(bool value) : Value(TypeBoolean), m_boolValue(value) { }
166 4113927 : explicit FundamentalValue(int value) : Value(TypeInteger), m_integerValue(value) { }
167 87302 : explicit FundamentalValue(double value) : Value(TypeDouble), m_doubleValue(value) { }
168 :
169 : union {
170 : bool m_boolValue;
171 : double m_doubleValue;
172 : int m_integerValue;
173 : };
174 : };
175 :
176 86624246 : class StringValue : public Value {
177 : public:
178 43312123 : static std::unique_ptr<StringValue> create(const String& value)
179 : {
180 86624246 : return std::unique_ptr<StringValue>(new StringValue(value));
181 : }
182 :
183 : static std::unique_ptr<StringValue> create(const char* value)
184 : {
185 : return std::unique_ptr<StringValue>(new StringValue(value));
186 : }
187 :
188 : bool asString(String* output) const override;
189 : void writeJSON(StringBuilder* output) const override;
190 : std::unique_ptr<Value> clone() const override;
191 :
192 : private:
193 43312123 : explicit StringValue(const String& value) : Value(TypeString), m_stringValue(value) { }
194 : explicit StringValue(const char* value) : Value(TypeString), m_stringValue(value) { }
195 :
196 : String m_stringValue;
197 : };
198 :
199 816050 : class SerializedValue : public Value {
200 : public:
201 408025 : static std::unique_ptr<SerializedValue> create(const String& value)
202 : {
203 816050 : return std::unique_ptr<SerializedValue>(new SerializedValue(value));
204 : }
205 :
206 : bool asSerialized(String* output) const override;
207 : void writeJSON(StringBuilder* output) const override;
208 : std::unique_ptr<Value> clone() const override;
209 :
210 : private:
211 408025 : explicit SerializedValue(const String& value) : Value(TypeSerialized), m_serializedValue(value) { }
212 :
213 : String m_serializedValue;
214 : };
215 :
216 : class DictionaryValue : public Value {
217 : public:
218 : using Entry = std::pair<String, Value*>;
219 19499495 : static std::unique_ptr<DictionaryValue> create()
220 : {
221 38998990 : return std::unique_ptr<DictionaryValue>(new DictionaryValue());
222 : }
223 :
224 9513218 : static DictionaryValue* cast(Value* value)
225 : {
226 19103821 : if (!value || value->type() != TypeObject)
227 : return nullptr;
228 : return static_cast<DictionaryValue*>(value);
229 : }
230 :
231 : static std::unique_ptr<DictionaryValue> cast(std::unique_ptr<Value> value)
232 : {
233 : return std::unique_ptr<DictionaryValue>(DictionaryValue::cast(value.release()));
234 : }
235 :
236 : void writeJSON(StringBuilder* output) const override;
237 : std::unique_ptr<Value> clone() const override;
238 :
239 : size_t size() const { return m_data.size(); }
240 :
241 : void setBoolean(const String& name, bool);
242 : void setInteger(const String& name, int);
243 : void setDouble(const String& name, double);
244 : void setString(const String& name, const String&);
245 : void setValue(const String& name, std::unique_ptr<Value>);
246 : void setObject(const String& name, std::unique_ptr<DictionaryValue>);
247 : void setArray(const String& name, std::unique_ptr<ListValue>);
248 :
249 : bool getBoolean(const String& name, bool* output) const;
250 : bool getInteger(const String& name, int* output) const;
251 : bool getDouble(const String& name, double* output) const;
252 : bool getString(const String& name, String* output) const;
253 :
254 : DictionaryValue* getObject(const String& name) const;
255 : ListValue* getArray(const String& name) const;
256 : Value* get(const String& name) const;
257 : Entry at(size_t index) const;
258 :
259 : bool booleanProperty(const String& name, bool defaultValue) const;
260 : int integerProperty(const String& name, int defaultValue) const;
261 : double doubleProperty(const String& name, double defaultValue) const;
262 : void remove(const String& name);
263 :
264 : ~DictionaryValue() override;
265 :
266 : private:
267 : DictionaryValue();
268 : template<typename T>
269 86329236 : void set(const String& key, std::unique_ptr<T>& value)
270 : {
271 : DCHECK(value);
272 : bool isNew = m_data.find(key) == m_data.end();
273 : m_data[key] = std::move(value);
274 86329236 : if (isNew)
275 86315727 : m_order.push_back(key);
276 86329236 : }
277 :
278 : using Dictionary = protocol::HashMap<String, std::unique_ptr<Value>>;
279 : Dictionary m_data;
280 : std::vector<String> m_order;
281 : };
282 :
283 : class ListValue : public Value {
284 : public:
285 879874 : static std::unique_ptr<ListValue> create()
286 : {
287 1759748 : return std::unique_ptr<ListValue>(new ListValue());
288 : }
289 :
290 375488 : static ListValue* cast(Value* value)
291 : {
292 750976 : if (!value || value->type() != TypeArray)
293 : return nullptr;
294 : return static_cast<ListValue*>(value);
295 : }
296 :
297 : static std::unique_ptr<ListValue> cast(std::unique_ptr<Value> value)
298 : {
299 : return std::unique_ptr<ListValue>(ListValue::cast(value.release()));
300 : }
301 :
302 : ~ListValue() override;
303 :
304 : void writeJSON(StringBuilder* output) const override;
305 : std::unique_ptr<Value> clone() const override;
306 :
307 : void pushValue(std::unique_ptr<Value>);
308 :
309 : Value* at(size_t index);
310 4532797 : size_t size() const { return m_data.size(); }
311 :
312 : private:
313 : ListValue();
314 : std::vector<std::unique_ptr<Value>> m_data;
315 : };
316 :
317 : } // namespace v8_inspector
318 : } // namespace protocol
319 :
320 : #endif // v8_inspector_protocol_Values_h
321 :
322 :
323 : // Copyright 2016 The Chromium Authors. All rights reserved.
324 : // Use of this source code is governed by a BSD-style license that can be
325 : // found in the LICENSE file.
326 :
327 : #ifndef v8_inspector_protocol_Object_h
328 : #define v8_inspector_protocol_Object_h
329 :
330 : //#include "ErrorSupport.h"
331 : //#include "Forward.h"
332 : //#include "Values.h"
333 :
334 : namespace v8_inspector {
335 : namespace protocol {
336 :
337 : class Object {
338 : public:
339 : static std::unique_ptr<Object> fromValue(protocol::Value*, ErrorSupport*);
340 : ~Object();
341 :
342 : std::unique_ptr<protocol::DictionaryValue> toValue() const;
343 : std::unique_ptr<Object> clone() const;
344 : private:
345 : explicit Object(std::unique_ptr<protocol::DictionaryValue>);
346 : std::unique_ptr<protocol::DictionaryValue> m_object;
347 : };
348 :
349 : } // namespace v8_inspector
350 : } // namespace protocol
351 :
352 : #endif // !defined(v8_inspector_protocol_Object_h)
353 :
354 :
355 : // Copyright 2016 The Chromium Authors. All rights reserved.
356 : // Use of this source code is governed by a BSD-style license that can be
357 : // found in the LICENSE file.
358 :
359 : #ifndef v8_inspector_protocol_ValueConversions_h
360 : #define v8_inspector_protocol_ValueConversions_h
361 :
362 : //#include "ErrorSupport.h"
363 : //#include "Forward.h"
364 : //#include "Values.h"
365 :
366 : namespace v8_inspector {
367 : namespace protocol {
368 :
369 : template<typename T>
370 : struct ValueConversions {
371 594 : static std::unique_ptr<T> fromValue(protocol::Value* value, ErrorSupport* errors)
372 : {
373 9188106 : return T::fromValue(value, errors);
374 : }
375 :
376 2568 : static std::unique_ptr<protocol::Value> toValue(T* value)
377 : {
378 10820540 : return value->toValue();
379 : }
380 :
381 : static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<T>& value)
382 : {
383 8422836 : return value->toValue();
384 : }
385 : };
386 :
387 : template<>
388 : struct ValueConversions<bool> {
389 13988980 : static bool fromValue(protocol::Value* value, ErrorSupport* errors)
390 : {
391 13988980 : bool result = false;
392 13988980 : bool success = value ? value->asBoolean(&result) : false;
393 13988980 : if (!success)
394 0 : errors->addError("boolean value expected");
395 13988980 : return result;
396 : }
397 :
398 : static std::unique_ptr<protocol::Value> toValue(bool value)
399 : {
400 27953536 : return FundamentalValue::create(value);
401 : }
402 : };
403 :
404 : template<>
405 : struct ValueConversions<int> {
406 1289794 : static int fromValue(protocol::Value* value, ErrorSupport* errors)
407 : {
408 1289794 : int result = 0;
409 1289794 : bool success = value ? value->asInteger(&result) : false;
410 1289794 : if (!success)
411 0 : errors->addError("integer value expected");
412 1289794 : return result;
413 : }
414 :
415 : static std::unique_ptr<protocol::Value> toValue(int value)
416 : {
417 3196190 : return FundamentalValue::create(value);
418 : }
419 : };
420 :
421 : template<>
422 : struct ValueConversions<double> {
423 0 : static double fromValue(protocol::Value* value, ErrorSupport* errors)
424 : {
425 0 : double result = 0;
426 0 : bool success = value ? value->asDouble(&result) : false;
427 0 : if (!success)
428 0 : errors->addError("double value expected");
429 0 : return result;
430 : }
431 :
432 : static std::unique_ptr<protocol::Value> toValue(double value)
433 : {
434 14920 : return FundamentalValue::create(value);
435 : }
436 : };
437 :
438 : template<>
439 : struct ValueConversions<String> {
440 21196197 : static String fromValue(protocol::Value* value, ErrorSupport* errors)
441 : {
442 : String result;
443 21196197 : bool success = value ? value->asString(&result) : false;
444 21196197 : if (!success)
445 76 : errors->addError("string value expected");
446 21196197 : return result;
447 : }
448 :
449 : static std::unique_ptr<protocol::Value> toValue(const String& value)
450 : {
451 42854448 : return StringValue::create(value);
452 : }
453 : };
454 :
455 : template<>
456 : struct ValueConversions<Value> {
457 318437 : static std::unique_ptr<Value> fromValue(protocol::Value* value, ErrorSupport* errors)
458 : {
459 : bool success = !!value;
460 318437 : if (!success) {
461 0 : errors->addError("value expected");
462 : return nullptr;
463 : }
464 318437 : return value->clone();
465 : }
466 :
467 : static std::unique_ptr<protocol::Value> toValue(Value* value)
468 : {
469 318291 : return value->clone();
470 : }
471 :
472 : static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<Value>& value)
473 : {
474 : return value->clone();
475 : }
476 : };
477 :
478 : template<>
479 : struct ValueConversions<DictionaryValue> {
480 0 : static std::unique_ptr<DictionaryValue> fromValue(protocol::Value* value, ErrorSupport* errors)
481 : {
482 0 : bool success = value && value->type() == protocol::Value::TypeObject;
483 0 : if (!success)
484 0 : errors->addError("object expected");
485 0 : return DictionaryValue::cast(value->clone());
486 : }
487 :
488 : static std::unique_ptr<protocol::Value> toValue(DictionaryValue* value)
489 : {
490 2746 : return value->clone();
491 : }
492 :
493 : static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<DictionaryValue>& value)
494 : {
495 : return value->clone();
496 : }
497 : };
498 :
499 : template<>
500 : struct ValueConversions<ListValue> {
501 : static std::unique_ptr<ListValue> fromValue(protocol::Value* value, ErrorSupport* errors)
502 : {
503 : bool success = value && value->type() == protocol::Value::TypeArray;
504 : if (!success)
505 : errors->addError("list expected");
506 : return ListValue::cast(value->clone());
507 : }
508 :
509 : static std::unique_ptr<protocol::Value> toValue(ListValue* value)
510 : {
511 : return value->clone();
512 : }
513 :
514 : static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<ListValue>& value)
515 : {
516 : return value->clone();
517 : }
518 : };
519 :
520 : } // namespace v8_inspector
521 : } // namespace protocol
522 :
523 : #endif // !defined(v8_inspector_protocol_ValueConversions_h)
524 :
525 :
526 : // Copyright 2016 The Chromium Authors. All rights reserved.
527 : // Use of this source code is governed by a BSD-style license that can be
528 : // found in the LICENSE file.
529 :
530 : #ifndef v8_inspector_protocol_Maybe_h
531 : #define v8_inspector_protocol_Maybe_h
532 :
533 : //#include "Forward.h"
534 :
535 : namespace v8_inspector {
536 : namespace protocol {
537 :
538 : template<typename T>
539 : class Maybe {
540 : public:
541 : Maybe() : m_value() { }
542 : Maybe(std::unique_ptr<T> value) : m_value(std::move(value)) { }
543 : Maybe(Maybe&& other) : m_value(std::move(other.m_value)) { }
544 : void operator=(std::unique_ptr<T> value) { m_value = std::move(value); }
545 : T* fromJust() const { DCHECK(m_value); return m_value.get(); }
546 : T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defaultValue; }
547 : bool isJust() const { return !!m_value; }
548 : std::unique_ptr<T> takeJust() { DCHECK(m_value); return std::move(m_value); }
549 : private:
550 : std::unique_ptr<T> m_value;
551 : };
552 :
553 : template<typename T>
554 : class MaybeBase {
555 : public:
556 29356988 : MaybeBase() : m_isJust(false) { }
557 183246 : MaybeBase(T value) : m_isJust(true), m_value(value) { }
558 170746 : MaybeBase(MaybeBase&& other) : m_isJust(other.m_isJust), m_value(std::move(other.m_value)) { }
559 19717898 : void operator=(T value) { m_value = value; m_isJust = true; }
560 : T fromJust() const { DCHECK(m_isJust); return m_value; }
561 548705 : T fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defaultValue; }
562 : bool isJust() const { return m_isJust; }
563 : T takeJust() { DCHECK(m_isJust); return m_value; }
564 :
565 : protected:
566 : bool m_isJust;
567 : T m_value;
568 : };
569 :
570 : template<>
571 : class Maybe<bool> : public MaybeBase<bool> {
572 : public:
573 : Maybe() { }
574 : Maybe(bool value) : MaybeBase(value) { }
575 : Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
576 : using MaybeBase::operator=;
577 : };
578 :
579 : template<>
580 : class Maybe<int> : public MaybeBase<int> {
581 : public:
582 : Maybe() { }
583 : Maybe(int value) : MaybeBase(value) { }
584 : Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
585 : using MaybeBase::operator=;
586 : };
587 :
588 : template<>
589 : class Maybe<double> : public MaybeBase<double> {
590 : public:
591 : Maybe() { }
592 : Maybe(double value) : MaybeBase(value) { }
593 : Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
594 : using MaybeBase::operator=;
595 : };
596 :
597 : template<>
598 : class Maybe<String> : public MaybeBase<String> {
599 : public:
600 : Maybe() { }
601 73452 : Maybe(const String& value) : MaybeBase(value) { }
602 : Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
603 : using MaybeBase::operator=;
604 : };
605 :
606 : } // namespace v8_inspector
607 : } // namespace protocol
608 :
609 : #endif // !defined(v8_inspector_protocol_Maybe_h)
610 :
611 :
612 : // Copyright 2016 The Chromium Authors. All rights reserved.
613 : // Use of this source code is governed by a BSD-style license that can be
614 : // found in the LICENSE file.
615 :
616 : #ifndef v8_inspector_protocol_Array_h
617 : #define v8_inspector_protocol_Array_h
618 :
619 : //#include "ErrorSupport.h"
620 : //#include "Forward.h"
621 : //#include "ValueConversions.h"
622 : //#include "Values.h"
623 :
624 : namespace v8_inspector {
625 : namespace protocol {
626 :
627 : template<typename T>
628 532445 : class Array {
629 : public:
630 : static std::unique_ptr<Array<T>> create()
631 : {
632 157013 : return std::unique_ptr<Array<T>>(new Array<T>());
633 : }
634 :
635 375432 : static std::unique_ptr<Array<T>> fromValue(protocol::Value* value, ErrorSupport* errors)
636 : {
637 : protocol::ListValue* array = ListValue::cast(value);
638 375432 : if (!array) {
639 0 : errors->addError("array expected");
640 : return nullptr;
641 : }
642 375432 : std::unique_ptr<Array<T>> result(new Array<T>());
643 375432 : errors->push();
644 9065368 : for (size_t i = 0; i < array->size(); ++i) {
645 8314504 : errors->setName(StringUtil::fromInteger(i));
646 4157252 : std::unique_ptr<T> item = ValueConversions<T>::fromValue(array->at(i), errors);
647 4157252 : result->m_vector.push_back(std::move(item));
648 : }
649 375432 : errors->pop();
650 375432 : if (errors->hasErrors())
651 : return nullptr;
652 : return result;
653 : }
654 :
655 : void addItem(std::unique_ptr<T> value)
656 : {
657 54322 : m_vector.push_back(std::move(value));
658 : }
659 :
660 : size_t length()
661 : {
662 183734 : return m_vector.size();
663 : }
664 :
665 : T* get(size_t index)
666 : {
667 191374 : return m_vector[index].get();
668 : }
669 :
670 426513 : std::unique_ptr<protocol::ListValue> toValue()
671 : {
672 426513 : std::unique_ptr<protocol::ListValue> result = ListValue::create();
673 5064444 : for (auto& item : m_vector)
674 8422836 : result->pushValue(ValueConversions<T>::toValue(item));
675 426513 : return result;
676 : }
677 :
678 : private:
679 : std::vector<std::unique_ptr<T>> m_vector;
680 : };
681 :
682 : template<typename T>
683 77116 : class ArrayBase {
684 : public:
685 : static std::unique_ptr<Array<T>> create()
686 : {
687 77183 : return std::unique_ptr<Array<T>>(new Array<T>());
688 : }
689 :
690 56 : static std::unique_ptr<Array<T>> fromValue(protocol::Value* value, ErrorSupport* errors)
691 : {
692 : protocol::ListValue* array = ListValue::cast(value);
693 56 : if (!array) {
694 0 : errors->addError("array expected");
695 : return nullptr;
696 : }
697 56 : errors->push();
698 56 : std::unique_ptr<Array<T>> result(new Array<T>());
699 226 : for (size_t i = 0; i < array->size(); ++i) {
700 114 : errors->setName(StringUtil::fromInteger(i));
701 57 : T item = ValueConversions<T>::fromValue(array->at(i), errors);
702 57 : result->m_vector.push_back(item);
703 : }
704 56 : errors->pop();
705 56 : if (errors->hasErrors())
706 : return nullptr;
707 : return result;
708 : }
709 :
710 : void addItem(const T& value)
711 : {
712 3088 : m_vector.push_back(value);
713 : }
714 :
715 : size_t length()
716 : {
717 113 : return m_vector.size();
718 : }
719 :
720 : T get(size_t index)
721 : {
722 : return m_vector[index];
723 : }
724 :
725 77183 : std::unique_ptr<protocol::ListValue> toValue()
726 : {
727 77183 : std::unique_ptr<protocol::ListValue> result = ListValue::create();
728 157454 : for (auto& item : m_vector)
729 6457 : result->pushValue(ValueConversions<T>::toValue(item));
730 77183 : return result;
731 : }
732 :
733 : private:
734 : std::vector<T> m_vector;
735 : };
736 :
737 : template<> class Array<String> : public ArrayBase<String> {};
738 : template<> class Array<int> : public ArrayBase<int> {};
739 : template<> class Array<double> : public ArrayBase<double> {};
740 : template<> class Array<bool> : public ArrayBase<bool> {};
741 :
742 : } // namespace v8_inspector
743 : } // namespace protocol
744 :
745 : #endif // !defined(v8_inspector_protocol_Array_h)
746 :
747 :
748 : // Copyright 2016 The Chromium Authors. All rights reserved.
749 : // Use of this source code is governed by a BSD-style license that can be
750 : // found in the LICENSE file.
751 :
752 : #ifndef v8_inspector_protocol_DispatcherBase_h
753 : #define v8_inspector_protocol_DispatcherBase_h
754 :
755 : //#include "Collections.h"
756 : //#include "ErrorSupport.h"
757 : //#include "Forward.h"
758 : //#include "Values.h"
759 :
760 : namespace v8_inspector {
761 : namespace protocol {
762 :
763 : class WeakPtr;
764 :
765 1160202 : class DispatchResponse {
766 : public:
767 : enum Status {
768 : kSuccess = 0,
769 : kError = 1,
770 : kFallThrough = 2,
771 : kAsync = 3
772 : };
773 :
774 : enum ErrorCode {
775 : kParseError = -32700,
776 : kInvalidRequest = -32600,
777 : kMethodNotFound = -32601,
778 : kInvalidParams = -32602,
779 : kInternalError = -32603,
780 : kServerError = -32000,
781 : };
782 :
783 : Status status() const { return m_status; }
784 : const String& errorMessage() const { return m_errorMessage; }
785 : ErrorCode errorCode() const { return m_errorCode; }
786 : bool isSuccess() const { return m_status == kSuccess; }
787 :
788 : static DispatchResponse OK();
789 : static DispatchResponse Error(const String&);
790 : static DispatchResponse InternalError();
791 : static DispatchResponse InvalidParams(const String&);
792 : static DispatchResponse FallThrough();
793 :
794 : private:
795 : Status m_status;
796 : String m_errorMessage;
797 : ErrorCode m_errorCode;
798 : };
799 :
800 : class DispatcherBase {
801 : PROTOCOL_DISALLOW_COPY(DispatcherBase);
802 : public:
803 : static const char kInvalidParamsString[];
804 : class WeakPtr {
805 : public:
806 : explicit WeakPtr(DispatcherBase*);
807 : ~WeakPtr();
808 344901 : DispatcherBase* get() { return m_dispatcher; }
809 12 : void dispose() { m_dispatcher = nullptr; }
810 :
811 : private:
812 : DispatcherBase* m_dispatcher;
813 : };
814 :
815 9898 : class Callback {
816 : public:
817 : Callback(std::unique_ptr<WeakPtr> backendImpl, int callId, int callbackId);
818 : virtual ~Callback();
819 : void dispose();
820 :
821 : protected:
822 : void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const DispatchResponse& response);
823 : void fallThroughIfActive();
824 :
825 : private:
826 : std::unique_ptr<WeakPtr> m_backendImpl;
827 : int m_callId;
828 : int m_callbackId;
829 : };
830 :
831 : explicit DispatcherBase(FrontendChannel*);
832 : virtual ~DispatcherBase();
833 :
834 : static bool getCommandName(const String& message, String* result);
835 :
836 : virtual DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) = 0;
837 :
838 : void sendResponse(int callId, const DispatchResponse&, std::unique_ptr<protocol::DictionaryValue> result);
839 : void sendResponse(int callId, const DispatchResponse&);
840 :
841 : void reportProtocolError(int callId, DispatchResponse::ErrorCode, const String& errorMessage, ErrorSupport* errors);
842 : void clearFrontend();
843 :
844 : std::unique_ptr<WeakPtr> weakPtr();
845 :
846 : int nextCallbackId();
847 : void markFallThrough(int callbackId);
848 : bool lastCallbackFallThrough() { return m_lastCallbackFallThrough; }
849 :
850 : private:
851 : FrontendChannel* m_frontendChannel;
852 : protocol::HashSet<WeakPtr*> m_weakPtrs;
853 : int m_lastCallbackId;
854 : bool m_lastCallbackFallThrough;
855 : };
856 :
857 9146 : class UberDispatcher {
858 : PROTOCOL_DISALLOW_COPY(UberDispatcher);
859 : public:
860 : explicit UberDispatcher(FrontendChannel*);
861 : void registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase>);
862 : DispatchResponse::Status dispatch(std::unique_ptr<Value> message);
863 : FrontendChannel* channel() { return m_frontendChannel; }
864 : bool fallThroughForNotFound() { return m_fallThroughForNotFound; }
865 : void setFallThroughForNotFound(bool);
866 : virtual ~UberDispatcher();
867 :
868 : private:
869 : FrontendChannel* m_frontendChannel;
870 : bool m_fallThroughForNotFound;
871 : protocol::HashMap<String, std::unique_ptr<protocol::DispatcherBase>> m_dispatchers;
872 : };
873 :
874 : class InternalResponse : public Serializable {
875 : PROTOCOL_DISALLOW_COPY(InternalResponse);
876 : public:
877 : static std::unique_ptr<InternalResponse> createResponse(int callId, std::unique_ptr<Serializable> params);
878 : static std::unique_ptr<InternalResponse> createNotification(const String& notification, std::unique_ptr<Serializable> params = nullptr);
879 :
880 : String serialize() override;
881 :
882 1224075 : ~InternalResponse() override {}
883 :
884 : private:
885 : InternalResponse(int callId, const String& notification, std::unique_ptr<Serializable> params);
886 :
887 : int m_callId;
888 : String m_notification;
889 : std::unique_ptr<Serializable> m_params;
890 : };
891 :
892 : class InternalRawNotification : public Serializable {
893 : public:
894 0 : static std::unique_ptr<InternalRawNotification> create(const String& notification)
895 : {
896 0 : return std::unique_ptr<InternalRawNotification>(new InternalRawNotification(notification));
897 : }
898 0 : ~InternalRawNotification() override {}
899 :
900 0 : String serialize() override
901 : {
902 0 : return m_notification;
903 : }
904 :
905 : private:
906 : explicit InternalRawNotification(const String& notification)
907 0 : : m_notification(notification)
908 : {
909 : }
910 :
911 : String m_notification;
912 : };
913 :
914 : } // namespace v8_inspector
915 : } // namespace protocol
916 :
917 : #endif // !defined(v8_inspector_protocol_DispatcherBase_h)
918 :
919 :
920 : // Copyright 2016 The Chromium Authors. All rights reserved.
921 : // Use of this source code is governed by a BSD-style license that can be
922 : // found in the LICENSE file.
923 :
924 : #ifndef v8_inspector_protocol_Parser_h
925 : #define v8_inspector_protocol_Parser_h
926 :
927 : //#include "Forward.h"
928 : //#include "Values.h"
929 :
930 : namespace v8_inspector {
931 : namespace protocol {
932 :
933 : std::unique_ptr<Value> parseJSONCharacters(const uint8_t*, unsigned);
934 : std::unique_ptr<Value> parseJSONCharacters(const uint16_t*, unsigned);
935 :
936 : } // namespace v8_inspector
937 : } // namespace protocol
938 :
939 : #endif // !defined(v8_inspector_protocol_Parser_h)
|