Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/Dictionary.h

Issue 2509713002: binding: Makes Dictionary throw an exception (constructor). (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 class ExecutionContext; 42 class ExecutionContext;
43 43
44 // Dictionary class provides ways to retrieve property values as C++ objects 44 // Dictionary class provides ways to retrieve property values as C++ objects
45 // from a V8 object. Instances of this class must not outlive V8's handle scope 45 // from a V8 object. Instances of this class must not outlive V8's handle scope
46 // because they hold a V8 value without putting it on persistent handles. 46 // because they hold a V8 value without putting it on persistent handles.
47 class CORE_EXPORT Dictionary final { 47 class CORE_EXPORT Dictionary final {
48 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 48 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
49 49
50 public: 50 public:
51 Dictionary() : m_isolate(nullptr) {} 51 Dictionary() : m_isolate(nullptr) {}
52 Dictionary(v8::Isolate* isolate, const v8::Local<v8::Value>& options) 52 Dictionary(v8::Isolate*, v8::Local<v8::Value> dictObj, ExceptionState&);
53 : m_options(options), m_isolate(isolate) { 53
54 DCHECK(m_isolate); 54 Dictionary& operator=(const Dictionary&) = default;
55
56 bool isObject() const { return !m_dictObj.IsEmpty(); }
57 bool isUndefinedOrNull() const { return blink::isUndefinedOrNull(m_value); }
58
59 bool get(const StringView& key, Dictionary&) const;
60 bool get(const StringView& key, v8::Local<v8::Value>& value) const {
61 return getInternal(v8String(m_isolate, key), value);
55 } 62 }
56 Dictionary(const v8::Local<v8::Value>& options,
57 v8::Isolate* isolate,
58 ExceptionState&) // DEPRECATED
59 : Dictionary(isolate, options) {}
60 63
61 Dictionary& operator=(const Dictionary&); 64 v8::Local<v8::Value> v8Value() const { return m_value; }
62
63 bool isObject() const;
64 bool isUndefinedOrNull() const;
65
66 bool get(const StringView&, Dictionary&) const;
67 bool get(const StringView&, v8::Local<v8::Value>&) const;
68
69 v8::Local<v8::Value> v8Value() const { return m_options; }
70 65
71 bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const; 66 bool getOwnPropertiesAsStringHashMap(HashMap<String, String>&) const;
72 bool getPropertyNames(Vector<String>&) const; 67 bool getPropertyNames(Vector<String>&) const;
73 68
74 bool hasProperty(const StringView&) const; 69 bool hasProperty(const StringView&) const;
75 70
76 v8::Isolate* isolate() const { return m_isolate; } 71 v8::Isolate* isolate() const { return m_isolate; }
77 v8::Local<v8::Context> v8Context() const { 72 v8::Local<v8::Context> v8Context() const {
78 ASSERT(m_isolate); 73 ASSERT(m_isolate);
79 return m_isolate->GetCurrentContext(); 74 return m_isolate->GetCurrentContext();
80 } 75 }
81 76
82 DictionaryIterator getIterator(ExecutionContext*) const; 77 DictionaryIterator getIterator(ExecutionContext*) const;
83 78
84 private: 79 private:
85 bool getInternal(const v8::Local<v8::Value>& key, 80 bool getInternal(const v8::Local<v8::Value>& key,
86 v8::Local<v8::Value>& result) const; 81 v8::Local<v8::Value>& result) const;
87 bool toObject(v8::Local<v8::Object>&) const;
88 82
89 v8::Local<v8::Value> m_options;
90 v8::Isolate* m_isolate; 83 v8::Isolate* m_isolate;
84 // Undefined, Null, or Object is allowed as type of dictionary.
85 v8::Local<v8::Value> m_value; // empty, undefined, null, or an Object
86 // In order to avoid converting a v8::Value to a v8::Object everytime, keep
87 // the converted object.
88 v8::Local<v8::Object> m_dictObj; // an Object (same as m_value) or empty
haraken 2016/11/16 17:28:57 Do we need m_dictObj? You're storing m_dictObj to
Yuki 2016/11/17 07:38:53 We need to distinguish undefined / null / an Objec
Yuki 2016/11/18 13:37:53 Done.
91 }; 89 };
92 90
93 template <> 91 template <>
94 struct NativeValueTraits<Dictionary> { 92 struct NativeValueTraits<Dictionary> {
95 static inline Dictionary nativeValue(v8::Isolate* isolate, 93 static Dictionary nativeValue(v8::Isolate* isolate,
96 v8::Local<v8::Value> value, 94 v8::Local<v8::Value> value,
97 ExceptionState&) { 95 ExceptionState& exceptionState) {
98 return Dictionary(isolate, value); 96 return Dictionary(isolate, value, exceptionState);
99 } 97 }
100 }; 98 };
101 99
102 // DictionaryHelper is a collection of static methods for getting or 100 // DictionaryHelper is a collection of static methods for getting or
103 // converting a value from Dictionary. 101 // converting a value from Dictionary.
104 struct DictionaryHelper { 102 struct DictionaryHelper {
105 STATIC_ONLY(DictionaryHelper); 103 STATIC_ONLY(DictionaryHelper);
106 template <typename T> 104 template <typename T>
107 static bool get(const Dictionary&, const StringView& key, T& value); 105 static bool get(const Dictionary&, const StringView& key, T& value);
108 template <typename T> 106 template <typename T>
(...skipping 19 matching lines...) Expand all
128 static bool get(const Dictionary&, 126 static bool get(const Dictionary&,
129 const StringView& key, 127 const StringView& key,
130 PointerType<T>& value); 128 PointerType<T>& value);
131 template <typename T> 129 template <typename T>
132 static bool get(const Dictionary&, const StringView& key, Nullable<T>& value); 130 static bool get(const Dictionary&, const StringView& key, Nullable<T>& value);
133 }; 131 };
134 132
135 } // namespace blink 133 } // namespace blink
136 134
137 #endif // Dictionary_h 135 #endif // Dictionary_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698