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

Side by Side Diff: Source/bindings/core/v8/PropertyBag.h

Issue 508073002: IDL: Add PropertyBag class (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 PropertyBag_h
6 #define PropertyBag_h
7
8 #include "bindings/core/v8/V8Binding.h"
9 #include "wtf/Noncopyable.h"
10 #include <v8.h>
11
12 namespace blink {
13
14 template <typename T> struct PropertyBagTraits;
15
16 // PropertyBag is used by IDL dictionary implementations to retrieve native
17 // values from a V8 object. It is similar to Dictionary(Helper), but its get()
18 // method returns false when the V8 object doesn't have the given key.
19 // FIXME: Eliminate duplication between Dictionary(Helper) and PropertyBag.
20 // When we have enough IDL dictionary support, we should be able to remove
21 // Dictionary(Helper).
22 class PropertyBag {
23 WTF_MAKE_NONCOPYABLE(PropertyBag);
24 public:
25 PropertyBag(v8::Isolate* isolate, const v8::Handle<v8::Object>& object)
26 : m_isolate(isolate)
27 , m_object(object)
28 {
29 ASSERT(!m_object.IsEmpty());
30 }
31
32 template <typename T>
33 bool get(const String& key, T& value)
34 {
35 v8::Handle<v8::String> v8Key = v8String(m_isolate, key);
36 v8::Local<v8::Value> v8Value = m_object->Get(v8Key);
37 if (v8Value.IsEmpty() || isUndefinedOrNull(v8Value)) {
haraken 2014/08/29 05:44:05 Just to confirm: I understand you want to return f
38 return false;
39 }
40 return getInternal(v8Value, value);
41 }
42
43 private:
44 bool getInternal(v8::Handle<v8::Value>& v8Value, String& value);
haraken 2014/08/29 05:44:04 Drop |v8Value| and |value|.
45 bool getInternal(v8::Handle<v8::Value>& v8Value, int& value);
46 bool getInternal(v8::Handle<v8::Value>& v8Value, bool& value);
47 bool getInternal(v8::Handle<v8::Value>& v8Value, double& value);
48
49 template <template <typename> class PointerType, typename T>
50 bool getInternal(v8::Handle<v8::Value>& v8Value, PointerType<T>& value)
51 {
52 value = PropertyBagTraits<T>::type::toNativeWithTypeCheck(m_isolate, v8V alue);
53 return value;
54 }
55
56 template <typename T>
57 bool getInternal(v8::Handle<v8::Value>& v8Value, Vector<T>& value)
58 {
59 if (!v8Value->IsArray())
60 return false;
61 // FIXME: Check types of each value
62 value = toNativeArray<T>(v8Value, 0, m_isolate);
63 return true;
64 }
65
66 v8::Isolate* m_isolate;
67 v8::Handle<v8::Object> m_object;
68 };
69
70 } // namespace blink
71
72 #endif // PropertyBag_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698