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

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

Issue 534133002: [WIP] bindings: Introduce PropertyBag (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
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
« no previous file with comments | « Source/bindings/core/v8/PropertyBag.h ('k') | Source/bindings/core/v8/PropertyBagTraits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "config.h"
6 #include "bindings/core/v8/PropertyBag.h"
7
8 #include "bindings/core/v8/ArrayValue.h"
9 #include "bindings/core/v8/V8TextTrack.h"
10 #include "bindings/core/v8/V8Window.h"
11
12 namespace blink {
13
14 bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, ArrayValue& value) const
15 {
16 if (!v8Value->IsArray())
17 return false;
18 value = ArrayValue(v8::Handle<v8::Array>::Cast(v8Value), m_isolate);
19 return true;
20 }
21
22 bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, RefPtrWillBeMember<LocalDOMWindow>& value) const
23 {
24 value = toDOMWindow(v8Value, m_isolate);
25 return !!value;
26 }
27
28 bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, MessagePortArray& value) const
29 {
30 value = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort>(v8Value, key, m_isolate, &m_exceptionState);
31 return !m_exceptionState.hadException();
32 }
33
34 bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, HashSet<AtomicString>& value) const
35 {
36 // FIXME: Support array-like objects
37 if (!v8Value->IsArray())
38 return false;
39
40 v8::Handle<v8::Array> v8Array = v8::Handle<v8::Array>::Cast(v8Value);
41 for (size_t i = 0; i < v8Array->Length(); ++i) {
42 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Integer::New(m_isol ate, i));
43 TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, false);
44 value.add(stringValue);
45 }
46
47 return true;
48 }
49
50 bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, RefPtrWillBeMember<TrackBase>& value) const
51 {
52 TrackBase* source = 0;
53 if (v8Value->IsObject()) {
54 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(v8Value);
55
56 // FIXME: this will need to be changed so it can also return an AudioTra ck or a VideoTrack once
57 // we add them.
58 v8::Handle<v8::Object> track = V8TextTrack::findInstanceInPrototypeChain (wrapper, m_isolate);
59 if (!track.IsEmpty())
60 source = V8TextTrack::toImpl(track);
61 }
62 value = source;
63 return !!source;
64 }
65
66 bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, RefPtrWillBeMember<EventTarget>& value) const
67 {
68 value = nullptr;
69 // We need to handle a LocalDOMWindow specially, because a LocalDOMWindow wr apper
70 // exists on a prototype chain of v8Value.
71 if (v8Value->IsObject()) {
72 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(v8Value);
73 v8::Handle<v8::Object> window = V8Window::findInstanceInPrototypeChain(w rapper, m_isolate);
74 if (!window.IsEmpty()) {
75 value = toWrapperTypeInfo(window)->toEventTarget(window);
76 return true;
77 }
78 }
79
80 if (V8DOMWrapper::isDOMWrapper(v8Value)) {
81 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(v8Value);
82 value = toWrapperTypeInfo(wrapper)->toEventTarget(wrapper);
83 }
84 return !!value;
85 }
86
87 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/PropertyBag.h ('k') | Source/bindings/core/v8/PropertyBagTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698