Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLElementCustom.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLElementCustom.cpp b/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLElementCustom.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1a037534dffe12fbcd242e8a945ca950e0d89eb9 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLElementCustom.cpp |
| @@ -0,0 +1,74 @@ |
| +// 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/V8HTMLElement.h" |
| + |
| +#include "bindings/core/v8/DOMWrapperWorld.h" |
| +#include "bindings/core/v8/ExceptionState.h" |
| +#include "bindings/core/v8/V8Binding.h" |
| +#include "bindings/core/v8/V8BindingMacros.h" |
| +#include "bindings/core/v8/V8DOMWrapper.h" |
| +#include "bindings/core/v8/V8ThrowException.h" |
| +#include "core/dom/Document.h" |
| +#include "core/dom/custom/CustomElementDefinition.h" |
| +#include "core/dom/custom/CustomElementsRegistry.h" |
| +#include "core/frame/LocalDOMWindow.h" |
| +#include "platform/RuntimeEnabledFeatures.h" |
| + |
| +namespace blink { |
| + |
| +void V8HTMLElement::constructorCustom( |
| + const v8::FunctionCallbackInfo<v8::Value>& info) |
| +{ |
| + DCHECK(info.IsConstructCall()); |
| + |
| + v8::Isolate* isolate = info.GetIsolate(); |
| + ScriptState* scriptState = ScriptState::current(isolate); |
| + |
| + if (!RuntimeEnabledFeatures::customElementsV1Enabled() |
| + || !scriptState->world().isMainWorld()) { |
| + V8ThrowException::throwTypeError(info.GetIsolate(), "Illegal constructor"); |
| + return; |
| + } |
| + |
| + LocalDOMWindow* window = scriptState->domWindow(); |
| + CustomElementDefinition* def = |
| + window->customElements(scriptState)->definitionForConstructor( |
| + scriptState, |
| + info.NewTarget()); |
| + if (!def) { |
| + V8ThrowException::throwTypeError(isolate, "Illegal constructor"); |
| + return; |
| + } |
| + |
| + // TODO(dominicc): Implement cases where the definition's |
| + // construction stack is not empty when parser-creation is |
| + // implemented. |
| + |
| + ExceptionState exceptionState( |
| + ExceptionState::ConstructionContext, |
| + "HTMLElement", |
| + info.Holder(), |
| + isolate); |
| + Element* element = window->document()->createElement( |
| + def->localName(), |
| + AtomicString(), |
| + exceptionState); |
| + if (exceptionState.throwIfNeeded()) |
| + return; |
| + const WrapperTypeInfo* wrapperType = element->wrapperTypeInfo(); |
| + v8::Local<v8::Object> wrapper = V8DOMWrapper::associateObjectWithWrapper( |
| + isolate, |
| + element, |
| + wrapperType, |
| + info.This()); |
| + |
| + if (!v8CallBoolean(wrapper->SetPrototype( |
| + scriptState->context(), |
| + def->prototype(scriptState)))) { |
| + return; |
|
yosin_UTC9
2016/05/12 07:54:22
Do you forget |V8ThrowException| here?
dominicc (has gone to gerrit)
2016/05/12 08:00:40
I'm not sure when that would fail, actually, becau
bashi
2016/05/12 08:19:13
I'm not sure if this would fail but there will be
|
| + } |
| +} |
| + |
| +} // namespace blink |