Index: third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dce6d077706d9e72b38cc47b98d00be5eac86b53 |
--- /dev/null |
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.cpp |
@@ -0,0 +1,97 @@ |
+// 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/ScriptCustomElementDefinitionBuilder.h" |
+ |
+#include "bindings/core/v8/DOMWrapperWorld.h" |
+#include "bindings/core/v8/ExceptionState.h" |
+#include "bindings/core/v8/ScriptCustomElementDefinition.h" |
+#include "bindings/core/v8/ScriptState.h" |
+#include "bindings/core/v8/ScriptValue.h" |
+#include "bindings/core/v8/V8Binding.h" |
+#include "bindings/core/v8/V8BindingMacros.h" |
+#include "core/dom/ExceptionCode.h" |
+ |
+namespace blink { |
+ |
+ScriptCustomElementDefinitionBuilder::ScriptCustomElementDefinitionBuilder( |
+ ScriptState* scriptState, |
+ CustomElementsRegistry* registry, |
+ const ScriptValue& constructor, |
+ ExceptionState& exceptionState) |
+ : m_scriptState(scriptState) |
+ , m_registry(registry) |
+ , m_constructorValue(constructor.v8Value()) |
+ , m_exceptionState(exceptionState) |
+{ |
+} |
+ |
+void ScriptCustomElementDefinitionBuilder::checkConstructorIntrinsics() |
+{ |
+ DCHECK(m_scriptState->world().isMainWorld()); |
+ |
+ if (!m_constructorValue->IsFunction()) { |
+ // Not even a function. |
+ m_exceptionState.throwTypeError( |
+ "constructor argument is not a constructor"); |
+ return; |
+ } |
+ m_constructor = m_constructorValue.As<v8::Object>(); |
+ if (!m_constructor->IsConstructor()) { |
+ m_exceptionState.throwTypeError( |
+ "constructor argument is not a constructor"); |
+ return; |
+ } |
+} |
+ |
+void ScriptCustomElementDefinitionBuilder::checkConstructorNotRegistered() |
+{ |
+ if (ScriptCustomElementDefinition::forConstructor( |
+ m_scriptState, |
+ m_registry, |
+ m_constructor)) { |
+ |
+ // Constructor is already registered. |
+ m_exceptionState.throwDOMException( |
+ NotSupportedError, |
+ "this constructor has already been used with this registry"); |
+ } |
+} |
+ |
+bool ScriptCustomElementDefinitionBuilder::checkPrototype() |
+{ |
+ v8::Isolate* isolate = m_scriptState->isolate(); |
+ v8::Local<v8::Context> context = m_scriptState->context(); |
+ 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.
|
+ v8::Local<v8::String> prototypeString = |
+ v8AtomicString(isolate, "prototype"); |
+ v8::Local<v8::Value> prototypeValue; |
+ if (!v8Call( |
+ m_constructor->Get(context, prototypeString), prototypeValue)) { |
+ DCHECK(tryCatch.HasCaught()); |
+ tryCatch.ReThrow(); |
+ return false; |
+ } |
+ if (!prototypeValue->IsObject()) { |
+ DCHECK(!tryCatch.HasCaught()); |
+ m_exceptionState.throwTypeError( |
+ "constructor prototype is not an object"); |
+ return false; |
+ } |
+ m_prototype = prototypeValue.As<v8::Object>(); |
+ 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
|
+} |
+ |
+CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build( |
+ const CustomElementDescriptor& descriptor) |
+{ |
+ return ScriptCustomElementDefinition::create( |
+ m_scriptState, |
+ m_registry, |
+ descriptor, |
+ m_constructor, |
+ m_prototype); |
+} |
+ |
+} // namespace blink |