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