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/ScriptCustomElementDefinitionBuilder.h" | |
6 | |
7 #include "bindings/core/v8/DOMWrapperWorld.h" | |
8 #include "bindings/core/v8/ExceptionState.h" | |
9 #include "bindings/core/v8/ScriptCustomElementDefinition.h" | |
10 #include "bindings/core/v8/ScriptState.h" | |
11 #include "bindings/core/v8/ScriptValue.h" | |
12 #include "bindings/core/v8/V8Binding.h" | |
13 #include "bindings/core/v8/V8BindingMacros.h" | |
14 #include "core/dom/ExceptionCode.h" | |
15 | |
16 namespace blink { | |
17 | |
18 ScriptCustomElementDefinitionBuilder::ScriptCustomElementDefinitionBuilder( | |
19 ScriptState* scriptState, | |
20 CustomElementsRegistry* registry, | |
21 const ScriptValue& constructor, | |
22 ExceptionState& exceptionState) | |
23 : m_scriptState(scriptState) | |
24 , m_registry(registry) | |
25 , m_constructorValue(constructor.v8Value()) | |
26 , m_exceptionState(exceptionState) | |
27 { | |
28 } | |
29 | |
30 void ScriptCustomElementDefinitionBuilder::checkConstructorIntrinsics() | |
31 { | |
32 DCHECK(m_scriptState->world().isMainWorld()); | |
33 | |
34 if (!m_constructorValue->IsFunction()) { | |
35 // Not even a function. | |
36 m_exceptionState.throwTypeError( | |
37 "constructor argument is not a constructor"); | |
38 return; | |
39 } | |
40 m_constructor = m_constructorValue.As<v8::Object>(); | |
41 if (!m_constructor->IsConstructor()) { | |
42 m_exceptionState.throwTypeError( | |
43 "constructor argument is not a constructor"); | |
44 return; | |
45 } | |
46 } | |
47 | |
48 void ScriptCustomElementDefinitionBuilder::checkConstructorNotRegistered() | |
49 { | |
50 if (ScriptCustomElementDefinition::forConstructor( | |
51 m_scriptState, | |
52 m_registry, | |
53 m_constructor)) { | |
54 | |
55 // Constructor is already registered. | |
56 m_exceptionState.throwDOMException( | |
57 NotSupportedError, | |
58 "this constructor has already been used with this registry"); | |
59 } | |
60 } | |
61 | |
62 bool ScriptCustomElementDefinitionBuilder::checkPrototype() | |
63 { | |
64 v8::Isolate* isolate = m_scriptState->isolate(); | |
65 v8::Local<v8::Context> context = m_scriptState->context(); | |
66 v8::TryCatch tryCatch(isolate); | |
haraken
2016/05/26 08:33:46
I think you can remove TryCatch. Checking the retu
dominicc (has gone to gerrit)
2016/05/27 04:54:17
Done.
| |
67 v8::Local<v8::String> prototypeString = | |
68 v8AtomicString(isolate, "prototype"); | |
69 v8::Local<v8::Value> prototypeValue; | |
70 if (!v8Call( | |
71 m_constructor->Get(context, prototypeString), prototypeValue)) { | |
72 DCHECK(tryCatch.HasCaught()); | |
73 tryCatch.ReThrow(); | |
74 return false; | |
75 } | |
76 if (!prototypeValue->IsObject()) { | |
77 DCHECK(!tryCatch.HasCaught()); | |
78 m_exceptionState.throwTypeError( | |
79 "constructor prototype is not an object"); | |
80 return false; | |
81 } | |
82 m_prototype = prototypeValue.As<v8::Object>(); | |
83 return m_scriptState->contextIsValid(); | |
haraken
2016/05/26 08:33:46
What is this checking?
dominicc (has gone to gerrit)
2016/05/27 04:54:17
Retrieving the prototype can run script and detach
| |
84 } | |
85 | |
86 CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build( | |
87 const CustomElementDescriptor& descriptor) | |
88 { | |
89 return ScriptCustomElementDefinition::create( | |
90 m_scriptState, | |
91 m_registry, | |
92 descriptor, | |
93 m_constructor, | |
94 m_prototype); | |
95 } | |
96 | |
97 } // namespace blink | |
OLD | NEW |