Index: third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLDocumentCustom.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLDocumentCustom.cpp b/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLDocumentCustom.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9c673aaa33a427d498bb2a0219a830afebedf20f |
--- /dev/null |
+++ b/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLDocumentCustom.cpp |
@@ -0,0 +1,70 @@ |
+// Copyright 2016 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 "bindings/core/v8/V8HTMLDocument.h" |
+ |
+#include "bindings/core/v8/ToV8.h" |
+#include "bindings/core/v8/V8Binding.h" |
+#include "core/html/DocumentNameCollection.h" |
+#include "core/html/HTMLDocument.h" |
+#include "core/html/HTMLIFrameElement.h" |
+ |
+namespace blink { |
+ |
+namespace { |
+ |
+v8::Local<v8::Value> getNamedProperty(v8::Isolate* isolate, HTMLDocument* htmlDocument, const AtomicString& key, v8::Local<v8::Object> creationContext) |
+{ |
+ if (!htmlDocument->hasNamedItem(key) && !htmlDocument->hasExtraNamedItem(key)) |
+ return v8Undefined(); |
+ DocumentNameCollection* items = htmlDocument->documentNamedItems(key); |
+ if (items->isEmpty()) |
+ return v8Undefined(); |
+ |
+ // https://html.spec.whatwg.org/multipage/dom.html#dom-document-namedItem-which |
+ if (items->hasExactlyOneItem()) { |
+ HTMLElement* element = items->item(0); |
+ DCHECK(element); |
+ if (isHTMLIFrameElement(*element)) { |
+ Frame* frame = toHTMLIFrameElement(*element).contentFrame(); |
+ if (frame) |
+ return toV8(frame->domWindow(), creationContext, isolate); |
+ } |
+ return toV8(element, creationContext, isolate); |
+ } |
+ return toV8(items, creationContext, isolate); |
+} |
+ |
+void propertyGetterCustom(const AtomicString& name, v8::PropertyCallbackInfo<v8::Value> const& info) |
+{ |
+ HTMLDocument* htmlDocument = V8HTMLDocument::toImpl(info.Holder()); |
+ DCHECK(htmlDocument); |
+ |
+ v8::Local<v8::Value> result = getNamedProperty(info.GetIsolate(), htmlDocument, name, info.Holder()); |
+ if (!result.IsEmpty()) { |
+ v8SetReturnValue(info, result); |
+ return; |
+ } |
+} |
+ |
+} // namespace |
+ |
+void V8HTMLDocument::indexedPropertyGetterCustom(unsigned index, v8::PropertyCallbackInfo<v8::Value> const& info) |
+{ |
+ propertyGetterCustom(AtomicString::number(index), info); |
+} |
+ |
+void V8HTMLDocument::namedPropertyGetterCustom(v8::Local<v8::Name> name, v8::PropertyCallbackInfo<v8::Value> const& info) |
+{ |
+ AtomicString atomicName(toCoreAtomicString(name.As<v8::String>())); |
haraken
2016/05/23 21:50:17
I guess you need to check 'if(name->IsString())' b
haraken
2016/05/23 21:50:17
I want to defer the AtomicString's instantiation a
Yuki
2016/05/24 03:06:19
I've already landed the following CL.
https://code
peria
2016/05/24 07:00:12
Postponed the instantiation of AtomicString.
In ca
|
+ // HTMLDocument has a special case for a [Unforgeable] attribute "location" in a |
+ // [OverrideBuiltin] interface. This is a workaround for the case. |
haraken
2016/05/23 21:50:16
Slightly better:
[Unforgeable] attributes in an [
peria
2016/05/24 07:00:12
Done.
|
+ // See http://heycam.github.io/webidl/#dfn-named-property-visibility for the details. |
+ if (atomicName == "location") |
+ return; |
+ |
+ propertyGetterCustom(atomicName, info); |
+} |
+ |
+} // namespace blink |