OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "bindings/core/v8/V8HTMLElement.h" | |
6 | |
7 #include "bindings/core/v8/DOMWrapperWorld.h" | |
8 #include "bindings/core/v8/ExceptionState.h" | |
9 #include "bindings/core/v8/V8Binding.h" | |
10 #include "bindings/core/v8/V8ThrowException.h" | |
11 #include "core/dom/Document.h" | |
12 #include "core/dom/custom/CustomElementDefinition.h" | |
13 #include "core/dom/custom/CustomElementsRegistry.h" | |
14 #include "core/frame/LocalDOMWindow.h" | |
15 #include "platform/RuntimeEnabledFeatures.h" | |
16 | |
17 namespace blink { | |
18 | |
19 void V8HTMLElement::constructorCustom( | |
20 const v8::FunctionCallbackInfo<v8::Value>& info) | |
21 { | |
22 DCHECK(info.IsConstructCall()); | |
23 v8::Isolate* isolate = info.GetIsolate(); | |
24 | |
25 if (!RuntimeEnabledFeatures::customElementsV1Enabled() | |
26 || !DOMWrapperWorld::current(isolate).isMainWorld()) { | |
27 V8ThrowException::throwIllegalConstructorTypeError(isolate); | |
28 return; | |
29 } | |
30 | |
31 Document* document = toDocument(currentExecutionContext(isolate)); | |
32 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
33 CustomElementDefinition* def = | |
34 document->domWindow()->customElements()->definitionForConstructor( | |
35 context, | |
36 info.NewTarget()); | |
37 if (!def) { | |
38 V8ThrowException::throwIllegalConstructorTypeError(isolate); | |
39 return; | |
40 } | |
41 | |
42 // TODO(dominicc): Implement cases where the definition's | |
43 // construction stack is not empty when parser-creation is | |
44 // implemented. | |
45 ExceptionState exceptionState( | |
46 ExceptionState::ConstructionContext, | |
47 "HTMLElement", | |
48 info.Holder(), | |
49 isolate); | |
50 Element* element = document->createElement( | |
51 def->localName(), | |
52 AtomicString(), | |
53 exceptionState); | |
54 if (exceptionState.throwIfNeeded()) | |
55 return; | |
56 v8::Local<v8::Object> wrapper = element->wrap(isolate, info.Holder()); | |
Yuki
2016/05/11 01:59:02
Please prefer using toV8() rather than wrap() meth
| |
57 info.GetReturnValue().Set(wrapper); | |
haraken
2016/05/10 09:04:22
Can we use v8SetReturnValue(info, wrapper)?
I'm a
yosin_UTC9
2016/05/10 13:10:59
I think we don't need to set return value for cons
dominicc (has gone to gerrit)
2016/05/11 02:31:49
Hmm, I actually did start with the HTMLElement con
dominicc (has gone to gerrit)
2016/05/11 02:31:49
We do in this case because we are returning a diff
yosin_UTC9
2016/05/11 03:49:55
AFIK, return value of constructor isn't used. I tr
| |
58 if (wrapper.IsEmpty()) | |
59 return; | |
60 | |
61 v8::Maybe<bool> couldSetPrototype = | |
62 wrapper->SetPrototype(context, def->prototype(isolate)); | |
yosin_UTC9
2016/05/10 13:10:59
Can we use new.target.constructor.prototype? If so
dominicc (has gone to gerrit)
2016/05/11 02:31:49
I was wondering about this too; I filed https://gi
yosin_UTC9
2016/05/11 03:49:55
Can we change spec to pass tagName to super? If so
| |
63 if (couldSetPrototype.IsNothing()) | |
64 return; | |
65 if (!couldSetPrototype.FromJust()) { | |
haraken
2016/05/10 09:04:22
V8BindingMacros.h provides macros to avoid develop
| |
66 // TODO(dominicc): Find out when SetPrototype can fail and write a | |
67 // test for this. | |
haraken
2016/05/10 09:04:22
You can use v8CallOrCrash. (In practice, it will n
| |
68 return; | |
69 } | |
70 } | |
71 | |
72 } // namespace blink | |
OLD | NEW |