1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer
12  *    in the documentation and/or other materials provided with the
13  *    distribution.
14  * 3. Neither the name of Google Inc. nor the names of its contributors
15  *    may be used to endorse or promote products derived from this
16  *    software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "third_party/blink/renderer/core/html/custom/v0_custom_element_exception.h"
32 
33 #include "third_party/blink/renderer/platform/bindings/exception_state.h"
34 
35 namespace blink {
36 
Preamble(const AtomicString & type)37 String V0CustomElementException::Preamble(const AtomicString& type) {
38   return "Registration failed for type '" + type + "'. ";
39 }
40 
ThrowException(Reason reason,const AtomicString & type,ExceptionState & exception_state)41 void V0CustomElementException::ThrowException(Reason reason,
42                                               const AtomicString& type,
43                                               ExceptionState& exception_state) {
44   switch (reason) {
45     case kCannotRegisterFromExtension:
46       exception_state.ThrowDOMException(
47           DOMExceptionCode::kNotSupportedError,
48           Preamble(type) + "Elements cannot be registered from extensions.");
49       return;
50 
51     case kConstructorPropertyNotConfigurable:
52       exception_state.ThrowDOMException(
53           DOMExceptionCode::kNotSupportedError,
54           Preamble(type) +
55               "Prototype constructor property is not configurable.");
56       return;
57 
58     case kContextDestroyedCheckingPrototype:
59       exception_state.ThrowDOMException(
60           DOMExceptionCode::kInvalidStateError,
61           Preamble(type) + "The context is no longer valid.");
62       return;
63 
64     case kContextDestroyedCreatingCallbacks:
65       exception_state.ThrowDOMException(
66           DOMExceptionCode::kInvalidStateError,
67           Preamble(type) + "The context is no longer valid.");
68       return;
69 
70     case kContextDestroyedRegisteringDefinition:
71       exception_state.ThrowDOMException(
72           DOMExceptionCode::kInvalidStateError,
73           Preamble(type) + "The context is no longer valid.");
74       return;
75 
76     case kExtendsIsInvalidName:
77       exception_state.ThrowDOMException(
78           DOMExceptionCode::kNotSupportedError,
79           Preamble(type) +
80               "The tag name specified in 'extends' is not a valid tag name.");
81       return;
82 
83     case kExtendsIsCustomElementName:
84       exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError,
85                                         Preamble(type) +
86                                             "The tag name specified in "
87                                             "'extends' is a custom element "
88                                             "name. Use inheritance instead.");
89       return;
90 
91     case kInvalidName:
92       exception_state.ThrowDOMException(
93           DOMExceptionCode::kSyntaxError,
94           Preamble(type) + "The type name is invalid.");
95       return;
96 
97     case kPrototypeInUse:
98       exception_state.ThrowDOMException(
99           DOMExceptionCode::kNotSupportedError,
100           Preamble(type) +
101               "The prototype is already in-use as "
102               "an interface prototype object.");
103       return;
104 
105     case kTypeAlreadyRegistered:
106       exception_state.ThrowDOMException(
107           DOMExceptionCode::kNotSupportedError,
108           Preamble(type) + "A type with that name is already registered.");
109       return;
110   }
111 
112   NOTREACHED();
113 }
114 
115 }  // namespace blink
116