Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V0CustomElementConstructorBuilder.cpp

Issue 2817533003: Replace ASSERT, RELEASE_ASSERT, and ASSERT_NOT_REACHED in bindings (Closed)
Patch Set: fixed dcheck build error Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "platform/wtf/Assertions.h" 52 #include "platform/wtf/Assertions.h"
53 53
54 namespace blink { 54 namespace blink {
55 55
56 static void ConstructCustomElement(const v8::FunctionCallbackInfo<v8::Value>&); 56 static void ConstructCustomElement(const v8::FunctionCallbackInfo<v8::Value>&);
57 57
58 V0CustomElementConstructorBuilder::V0CustomElementConstructorBuilder( 58 V0CustomElementConstructorBuilder::V0CustomElementConstructorBuilder(
59 ScriptState* script_state, 59 ScriptState* script_state,
60 const ElementRegistrationOptions& options) 60 const ElementRegistrationOptions& options)
61 : script_state_(script_state), options_(options) { 61 : script_state_(script_state), options_(options) {
62 ASSERT(script_state_->GetContext() == 62 DCHECK(script_state_->GetContext() ==
63 script_state_->GetIsolate()->GetCurrentContext()); 63 script_state_->GetIsolate()->GetCurrentContext());
64 } 64 }
65 65
66 bool V0CustomElementConstructorBuilder::IsFeatureAllowed() const { 66 bool V0CustomElementConstructorBuilder::IsFeatureAllowed() const {
67 return script_state_->World().IsMainWorld(); 67 return script_state_->World().IsMainWorld();
68 } 68 }
69 69
70 bool V0CustomElementConstructorBuilder::ValidateOptions( 70 bool V0CustomElementConstructorBuilder::ValidateOptions(
71 const AtomicString& type, 71 const AtomicString& type,
72 QualifiedName& tag_name, 72 QualifiedName& tag_name,
73 ExceptionState& exception_state) { 73 ExceptionState& exception_state) {
74 ASSERT(prototype_.IsEmpty()); 74 DCHECK(prototype_.IsEmpty());
75 75
76 v8::TryCatch try_catch(script_state_->GetIsolate()); 76 v8::TryCatch try_catch(script_state_->GetIsolate());
77 77
78 if (!script_state_->PerContextData()) { 78 if (!script_state_->PerContextData()) {
79 // FIXME: This should generate an InvalidContext exception at a later point. 79 // FIXME: This should generate an InvalidContext exception at a later point.
80 V0CustomElementException::ThrowException( 80 V0CustomElementException::ThrowException(
81 V0CustomElementException::kContextDestroyedCheckingPrototype, type, 81 V0CustomElementException::kContextDestroyedCheckingPrototype, type,
82 exception_state); 82 exception_state);
83 try_catch.ReThrow(); 83 try_catch.ReThrow();
84 return false; 84 return false;
85 } 85 }
86 86
87 if (options_.hasPrototype()) { 87 if (options_.hasPrototype()) {
88 ASSERT(options_.prototype().IsObject()); 88 DCHECK(options_.prototype().IsObject());
89 prototype_ = options_.prototype().V8Value().As<v8::Object>(); 89 prototype_ = options_.prototype().V8Value().As<v8::Object>();
90 } else { 90 } else {
91 prototype_ = v8::Object::New(script_state_->GetIsolate()); 91 prototype_ = v8::Object::New(script_state_->GetIsolate());
92 v8::Local<v8::Object> base_prototype = 92 v8::Local<v8::Object> base_prototype =
93 script_state_->PerContextData()->PrototypeForType( 93 script_state_->PerContextData()->PrototypeForType(
94 &V8HTMLElement::wrapperTypeInfo); 94 &V8HTMLElement::wrapperTypeInfo);
95 if (!base_prototype.IsEmpty()) { 95 if (!base_prototype.IsEmpty()) {
96 if (!V8CallBoolean(prototype_->SetPrototype(script_state_->GetContext(), 96 if (!V8CallBoolean(prototype_->SetPrototype(script_state_->GetContext(),
97 base_prototype))) 97 base_prototype)))
98 return false; 98 return false;
99 } 99 }
100 } 100 }
101 101
102 AtomicString namespace_uri = HTMLNames::xhtmlNamespaceURI; 102 AtomicString namespace_uri = HTMLNames::xhtmlNamespaceURI;
103 if (HasValidPrototypeChainFor(&V8SVGElement::wrapperTypeInfo)) 103 if (HasValidPrototypeChainFor(&V8SVGElement::wrapperTypeInfo))
104 namespace_uri = SVGNames::svgNamespaceURI; 104 namespace_uri = SVGNames::svgNamespaceURI;
105 105
106 ASSERT(!try_catch.HasCaught()); 106 DCHECK(!try_catch.HasCaught());
107 107
108 AtomicString local_name; 108 AtomicString local_name;
109 109
110 if (options_.hasExtends()) { 110 if (options_.hasExtends()) {
111 local_name = AtomicString(options_.extends().DeprecatedLower()); 111 local_name = AtomicString(options_.extends().DeprecatedLower());
112 112
113 if (!Document::IsValidName(local_name)) { 113 if (!Document::IsValidName(local_name)) {
114 V0CustomElementException::ThrowException( 114 V0CustomElementException::ThrowException(
115 V0CustomElementException::kExtendsIsInvalidName, type, 115 V0CustomElementException::kExtendsIsInvalidName, type,
116 exception_state); 116 exception_state);
(...skipping 11 matching lines...) Expand all
128 if (namespace_uri == SVGNames::svgNamespaceURI) { 128 if (namespace_uri == SVGNames::svgNamespaceURI) {
129 V0CustomElementException::ThrowException( 129 V0CustomElementException::ThrowException(
130 V0CustomElementException::kExtendsIsInvalidName, type, 130 V0CustomElementException::kExtendsIsInvalidName, type,
131 exception_state); 131 exception_state);
132 try_catch.ReThrow(); 132 try_catch.ReThrow();
133 return false; 133 return false;
134 } 134 }
135 local_name = type; 135 local_name = type;
136 } 136 }
137 137
138 ASSERT(!try_catch.HasCaught()); 138 DCHECK(!try_catch.HasCaught());
139 tag_name = QualifiedName(g_null_atom, local_name, namespace_uri); 139 tag_name = QualifiedName(g_null_atom, local_name, namespace_uri);
140 return true; 140 return true;
141 } 141 }
142 142
143 V0CustomElementLifecycleCallbacks* 143 V0CustomElementLifecycleCallbacks*
144 V0CustomElementConstructorBuilder::CreateCallbacks() { 144 V0CustomElementConstructorBuilder::CreateCallbacks() {
145 ASSERT(!prototype_.IsEmpty()); 145 DCHECK(!prototype_.IsEmpty());
146 146
147 v8::TryCatch exception_catcher(script_state_->GetIsolate()); 147 v8::TryCatch exception_catcher(script_state_->GetIsolate());
148 exception_catcher.SetVerbose(true); 148 exception_catcher.SetVerbose(true);
149 149
150 v8::MaybeLocal<v8::Function> created = RetrieveCallback("createdCallback"); 150 v8::MaybeLocal<v8::Function> created = RetrieveCallback("createdCallback");
151 v8::MaybeLocal<v8::Function> attached = RetrieveCallback("attachedCallback"); 151 v8::MaybeLocal<v8::Function> attached = RetrieveCallback("attachedCallback");
152 v8::MaybeLocal<v8::Function> detached = RetrieveCallback("detachedCallback"); 152 v8::MaybeLocal<v8::Function> detached = RetrieveCallback("detachedCallback");
153 v8::MaybeLocal<v8::Function> attribute_changed = 153 v8::MaybeLocal<v8::Function> attribute_changed =
154 RetrieveCallback("attributeChangedCallback"); 154 RetrieveCallback("attributeChangedCallback");
155 155
(...skipping 12 matching lines...) Expand all
168 .ToLocal(&value) || 168 .ToLocal(&value) ||
169 !value->IsFunction()) 169 !value->IsFunction())
170 return v8::MaybeLocal<v8::Function>(); 170 return v8::MaybeLocal<v8::Function>();
171 return v8::MaybeLocal<v8::Function>(value.As<v8::Function>()); 171 return v8::MaybeLocal<v8::Function>(value.As<v8::Function>());
172 } 172 }
173 173
174 bool V0CustomElementConstructorBuilder::CreateConstructor( 174 bool V0CustomElementConstructorBuilder::CreateConstructor(
175 Document* document, 175 Document* document,
176 V0CustomElementDefinition* definition, 176 V0CustomElementDefinition* definition,
177 ExceptionState& exception_state) { 177 ExceptionState& exception_state) {
178 ASSERT(!prototype_.IsEmpty()); 178 DCHECK(!prototype_.IsEmpty());
179 ASSERT(constructor_.IsEmpty()); 179 DCHECK(constructor_.IsEmpty());
180 ASSERT(document); 180 DCHECK(document);
181 181
182 v8::Isolate* isolate = script_state_->GetIsolate(); 182 v8::Isolate* isolate = script_state_->GetIsolate();
183 v8::Local<v8::Context> context = script_state_->GetContext(); 183 v8::Local<v8::Context> context = script_state_->GetContext();
184 184
185 if (!PrototypeIsValid(definition->Descriptor().GetType(), exception_state)) 185 if (!PrototypeIsValid(definition->Descriptor().GetType(), exception_state))
186 return false; 186 return false;
187 187
188 const V0CustomElementDescriptor& descriptor = definition->Descriptor(); 188 const V0CustomElementDescriptor& descriptor = definition->Descriptor();
189 189
190 v8::Local<v8::String> v8_tag_name = V8String(isolate, descriptor.LocalName()); 190 v8::Local<v8::String> v8_tag_name = V8String(isolate, descriptor.LocalName());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 V0CustomElementException::ThrowException( 273 V0CustomElementException::ThrowException(
274 V0CustomElementException::kConstructorPropertyNotConfigurable, type, 274 V0CustomElementException::kConstructorPropertyNotConfigurable, type,
275 exception_state); 275 exception_state);
276 return false; 276 return false;
277 } 277 }
278 278
279 return true; 279 return true;
280 } 280 }
281 281
282 bool V0CustomElementConstructorBuilder::DidRegisterDefinition() const { 282 bool V0CustomElementConstructorBuilder::DidRegisterDefinition() const {
283 ASSERT(!constructor_.IsEmpty()); 283 DCHECK(!constructor_.IsEmpty());
284 284
285 return callbacks_->SetBinding( 285 return callbacks_->SetBinding(
286 V0CustomElementBinding::Create(script_state_->GetIsolate(), prototype_)); 286 V0CustomElementBinding::Create(script_state_->GetIsolate(), prototype_));
287 } 287 }
288 288
289 ScriptValue V0CustomElementConstructorBuilder::BindingsReturnValue() const { 289 ScriptValue V0CustomElementConstructorBuilder::BindingsReturnValue() const {
290 return ScriptValue(script_state_.Get(), constructor_); 290 return ScriptValue(script_state_.Get(), constructor_);
291 } 291 }
292 292
293 bool V0CustomElementConstructorBuilder::HasValidPrototypeChainFor( 293 bool V0CustomElementConstructorBuilder::HasValidPrototypeChainFor(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 namespace_uri, tag_name, 346 namespace_uri, tag_name,
347 StringOrDictionary::fromString(maybe_type->IsNull() ? g_null_atom : type), 347 StringOrDictionary::fromString(maybe_type->IsNull() ? g_null_atom : type),
348 exception_state); 348 exception_state);
349 if (element) { 349 if (element) {
350 UseCounter::Count(document, UseCounter::kV0CustomElementsConstruct); 350 UseCounter::Count(document, UseCounter::kV0CustomElementsConstruct);
351 } 351 }
352 V8SetReturnValueFast(info, element, document); 352 V8SetReturnValueFast(info, element, document);
353 } 353 }
354 354
355 } // namespace blink 355 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698