| 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..340f686449c128bd6ed14c5beaa275d7c42e3fb6
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLElementCustom.cpp
|
| @@ -0,0 +1,72 @@
|
| +// 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/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)
|
| +{
|
| + ASSERT(info.IsConstructCall());
|
| + v8::Isolate* isolate = info.GetIsolate();
|
| +
|
| + if (!RuntimeEnabledFeatures::customElementsV1Enabled()
|
| + || !DOMWrapperWorld::current(isolate).isMainWorld()) {
|
| + V8ThrowException::throwIllegalConstructorTypeError(isolate);
|
| + return;
|
| + }
|
| +
|
| + Document* document = toDocument(currentExecutionContext(isolate));
|
| + v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
| + CustomElementDefinition* def =
|
| + document->domWindow()->customElements()->definitionForConstructor(
|
| + context,
|
| + info.NewTarget());
|
| + if (!def) {
|
| + V8ThrowException::throwIllegalConstructorTypeError(isolate);
|
| + 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 = document->createElement(
|
| + def->localName(),
|
| + AtomicString(),
|
| + exceptionState);
|
| + if (exceptionState.throwIfNeeded())
|
| + return;
|
| + v8::Local<v8::Object> wrapper = element->wrap(isolate, info.Holder());
|
| + info.GetReturnValue().Set(wrapper);
|
| + if (wrapper.IsEmpty())
|
| + return;
|
| +
|
| + v8::Maybe<bool> couldSetPrototype =
|
| + wrapper->SetPrototype(context, def->prototype(isolate));
|
| + if (couldSetPrototype.IsNothing())
|
| + return;
|
| + if (!couldSetPrototype.FromJust()) {
|
| + // TODO(dominicc): Find out when SetPrototype can fail and write a
|
| + // test for this.
|
| + return;
|
| + }
|
| +}
|
| +
|
| +} // namespace blink
|
|
|