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

Side by Side Diff: Source/bindings/v8/CustomElementConstructorBuilder.cpp

Issue 17707002: Implement Custom Elements inserted and removed callbacks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 return false; 134 return false;
135 } 135 }
136 136
137 PassRefPtr<CustomElementCallback> CustomElementConstructorBuilder::createCallbac k(Document* document) 137 PassRefPtr<CustomElementCallback> CustomElementConstructorBuilder::createCallbac k(Document* document)
138 { 138 {
139 ASSERT(!m_prototype.IsEmpty()); 139 ASSERT(!m_prototype.IsEmpty());
140 140
141 RefPtr<Document> protect(document); 141 RefPtr<Document> protect(document);
142 142
143 v8::Handle<v8::Function> ready = retrieveCallback("readyCallback");
144 v8::Handle<v8::Function> inserted = retrieveCallback("insertedCallback");
145 v8::Handle<v8::Function> removed = retrieveCallback("removedCallback");
146
147 return V8CustomElementCallback::create(document, m_prototype, ready, inserte d, removed);
148 }
149
150 v8::Handle<v8::Function> CustomElementConstructorBuilder::retrieveCallback(const char* name) const
151 {
143 v8::TryCatch exceptionCatcher; 152 v8::TryCatch exceptionCatcher;
144 exceptionCatcher.SetVerbose(true); 153 exceptionCatcher.SetVerbose(true);
145 154
146 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 155 v8::Isolate* isolate = v8::Isolate::GetCurrent();
147 v8::Handle<v8::Value> readyValue = m_prototype->Get(v8String("readyCallback" , isolate)); 156 v8::Handle<v8::Value> value = m_prototype->Get(v8String(name, isolate));
abarth-chromium 2013/06/25 21:13:56 Would you be willing to add a test that hooks each
157 if (value.IsEmpty() || !value->IsFunction())
158 return v8::Handle<v8::Function>();
148 159
149 v8::Handle<v8::Function> readyFunction; 160 return v8::Handle<v8::Function>::Cast(value);
150 if (!readyValue.IsEmpty() && readyValue->IsFunction())
151 readyFunction = v8::Handle<v8::Function>::Cast(readyValue);
152
153 return V8CustomElementCallback::create(document, m_prototype, readyFunction) ;
154 } 161 }
155 162
156 bool CustomElementConstructorBuilder::createConstructor(Document* document, Cust omElementDefinition* definition) 163 bool CustomElementConstructorBuilder::createConstructor(Document* document, Cust omElementDefinition* definition)
157 { 164 {
158 ASSERT(!m_prototype.IsEmpty()); 165 ASSERT(!m_prototype.IsEmpty());
159 ASSERT(m_constructor.IsEmpty()); 166 ASSERT(m_constructor.IsEmpty());
160 ASSERT(document); 167 ASSERT(document);
161 168
162 v8::Isolate* isolate = m_context->GetIsolate(); 169 v8::Isolate* isolate = m_context->GetIsolate();
163 170
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 return; 277 return;
271 } 278 }
272 279
273 Document* document = V8Document::toNative(v8::Handle<v8::Object>::Cast(args. Callee()->GetHiddenValue(V8HiddenPropertyName::document()))); 280 Document* document = V8Document::toNative(v8::Handle<v8::Object>::Cast(args. Callee()->GetHiddenValue(V8HiddenPropertyName::document())));
274 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, namespaceURI, args. Callee()->GetHiddenValue(V8HiddenPropertyName::namespaceURI())); 281 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, namespaceURI, args. Callee()->GetHiddenValue(V8HiddenPropertyName::namespaceURI()));
275 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, name, args.Callee() ->GetHiddenValue(V8HiddenPropertyName::name())); 282 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, name, args.Callee() ->GetHiddenValue(V8HiddenPropertyName::name()));
276 v8::Handle<v8::Value> maybeType = args.Callee()->GetHiddenValue(V8HiddenProp ertyName::type()); 283 v8::Handle<v8::Value> maybeType = args.Callee()->GetHiddenValue(V8HiddenProp ertyName::type());
277 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, maybeType); 284 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, maybeType);
278 285
279 ExceptionCode ec = 0; 286 ExceptionCode ec = 0;
280 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope;
281 RefPtr<Element> element = document->createElementNS(namespaceURI, name, mayb eType->IsNull() ? nullAtom : type, ec); 287 RefPtr<Element> element = document->createElementNS(namespaceURI, name, mayb eType->IsNull() ? nullAtom : type, ec);
282 if (ec) { 288 if (ec) {
283 setDOMException(ec, isolate); 289 setDOMException(ec, isolate);
284 return; 290 return;
285 } 291 }
292 CustomElementCallbackDispatcher::instance().dispatchReadyCallback(element.ge t());
286 v8SetReturnValue(args, toV8Fast(element.release(), args, document)); 293 v8SetReturnValue(args, toV8Fast(element.release(), args, document));
287 } 294 }
288 295
289 } // namespace WebCore 296 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698