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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/PropertyBag.cpp
diff --git a/Source/bindings/core/v8/PropertyBag.cpp b/Source/bindings/core/v8/PropertyBag.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..33b18a88135181b92f894b4564db5eddba74a323
--- /dev/null
+++ b/Source/bindings/core/v8/PropertyBag.cpp
@@ -0,0 +1,87 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "bindings/core/v8/PropertyBag.h"
+
+#include "bindings/core/v8/ArrayValue.h"
+#include "bindings/core/v8/V8TextTrack.h"
+#include "bindings/core/v8/V8Window.h"
+
+namespace blink {
+
+bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, ArrayValue& value) const
+{
+ if (!v8Value->IsArray())
+ return false;
+ value = ArrayValue(v8::Handle<v8::Array>::Cast(v8Value), m_isolate);
+ return true;
+}
+
+bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, RefPtrWillBeMember<LocalDOMWindow>& value) const
+{
+ value = toDOMWindow(v8Value, m_isolate);
+ return !!value;
+}
+
+bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, MessagePortArray& value) const
+{
+ value = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort>(v8Value, key, m_isolate, &m_exceptionState);
+ return !m_exceptionState.hadException();
+}
+
+bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, HashSet<AtomicString>& value) const
+{
+ // FIXME: Support array-like objects
+ if (!v8Value->IsArray())
+ return false;
+
+ v8::Handle<v8::Array> v8Array = v8::Handle<v8::Array>::Cast(v8Value);
+ for (size_t i = 0; i < v8Array->Length(); ++i) {
+ v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Integer::New(m_isolate, i));
+ TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, false);
+ value.add(stringValue);
+ }
+
+ return true;
+}
+
+bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, RefPtrWillBeMember<TrackBase>& value) const
+{
+ TrackBase* source = 0;
+ if (v8Value->IsObject()) {
+ v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(v8Value);
+
+ // FIXME: this will need to be changed so it can also return an AudioTrack or a VideoTrack once
+ // we add them.
+ v8::Handle<v8::Object> track = V8TextTrack::findInstanceInPrototypeChain(wrapper, m_isolate);
+ if (!track.IsEmpty())
+ source = V8TextTrack::toImpl(track);
+ }
+ value = source;
+ return !!source;
+}
+
+bool PropertyBag::getInternal(const String& key, v8::Handle<v8::Value>& v8Value, RefPtrWillBeMember<EventTarget>& value) const
+{
+ value = nullptr;
+ // We need to handle a LocalDOMWindow specially, because a LocalDOMWindow wrapper
+ // exists on a prototype chain of v8Value.
+ if (v8Value->IsObject()) {
+ v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(v8Value);
+ v8::Handle<v8::Object> window = V8Window::findInstanceInPrototypeChain(wrapper, m_isolate);
+ if (!window.IsEmpty()) {
+ value = toWrapperTypeInfo(window)->toEventTarget(window);
+ return true;
+ }
+ }
+
+ if (V8DOMWrapper::isDOMWrapper(v8Value)) {
+ v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(v8Value);
+ value = toWrapperTypeInfo(wrapper)->toEventTarget(wrapper);
+ }
+ return !!value;
+}
+
+} // namespace blink
« 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