| 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..d8b5ad9e1741a200298b9a31d9db476d341f4d64
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLElementCustom.cpp
|
| @@ -0,0 +1,92 @@
|
| +// 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());
|
| +
|
| + if (!RuntimeEnabledFeatures::customElementsV1Enabled()
|
| + || !DOMWrapperWorld::current(info.GetIsolate()).isMainWorld()) {
|
| + V8ThrowException::throwIllegalConstructorTypeError(info.GetIsolate());
|
| + return;
|
| + }
|
| + // FIXME(dominicc): Update this to match the specification when
|
| + // https://github.com/whatwg/html/issues/1154 is closed (if the
|
| + // behavior matches Image constructor, then just remove this
|
| + // FIXME.)
|
| +
|
| + Document* document =
|
| + toDocument(currentExecutionContext(info.GetIsolate()));
|
| + v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
|
| + CustomElementDefinition* def =
|
| + document->domWindow()->customElements()->definitionForConstructor(
|
| + context,
|
| + info.NewTarget());
|
| + if (!def) {
|
| + V8ThrowException::throwIllegalConstructorTypeError(info.GetIsolate());
|
| + return;
|
| + }
|
| +
|
| + // TODO(dominicc): Implement cases where the definition's
|
| + // construction stack is not empty.
|
| + ExceptionState exceptionState(
|
| + ExceptionState::ConstructionContext,
|
| + "HTMLElement",
|
| + info.Holder(),
|
| + info.GetIsolate());
|
| + Element* element = document->createElement(
|
| + def->localName(),
|
| + AtomicString(),
|
| + exceptionState);
|
| + if (exceptionState.throwIfNeeded())
|
| + return;
|
| + // TODO(dominicc): The constructor invoked this way should
|
| + // allocate a wrapper; so use associateWithWrapper instead of
|
| + // allocating a new wrapper.
|
| + v8::Local<v8::Object> wrapper =
|
| + element->wrap(info.GetIsolate(), info.Holder());
|
| + info.GetReturnValue().Set(wrapper);
|
| + if (wrapper.IsEmpty())
|
| + return;
|
| +
|
| + v8::Maybe<bool> couldSetPrototype =
|
| + wrapper->SetPrototype(context, def->prototype().v8Value());
|
| + if (couldSetPrototype.IsNothing())
|
| + return;
|
| + if (!couldSetPrototype.FromJust()) {
|
| + // TODO(dominicc): Does this happen in practice?
|
| + return;
|
| + }
|
| +
|
| + // TODO(dominicc): This will be leaky, because the parser can be
|
| + // invoked any time. Write a test to ensure window shutdown does
|
| + // not leak.
|
| +
|
| + // TODO(dominicc): Retrieve the window and CustomElementRegistry.
|
| + // TODO(dominicc): Use a v8::NativeWeakMap to store the ID of the object.
|
| + // - We can't use a hidden field, because the constructor could be any
|
| + // ES6 constructor--we don't know ahead of time.
|
| + // - We can't use a symbol because the object could be frozen.
|
| +
|
| + // TODO(dominicc): Add a test w/ calling the constructor cross-document.
|
| + // TODO(dominicc): Add a test that Custom Elements can not be registered
|
| + // from non-main worlds.
|
| +}
|
| +
|
| +} // namespace blink
|
|
|