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

Side by Side Diff: Source/bindings/dart/DartCustomElementWrapper.cpp

Issue 27183006: Setting native pointer of custom elements before running constructor. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Created 7 years, 2 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
« no previous file with comments | « no previous file | Source/bindings/dart/DartDOMData.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 Dart_WeakPersistentHandle oldInstance = DartDOMWrapper::lookupWrapper( 106 Dart_WeakPersistentHandle oldInstance = DartDOMWrapper::lookupWrapper(
107 domData, DartHTMLElement::isNode, reinterpret_cast<HTMLElement*>(element )); 107 domData, DartHTMLElement::isNode, reinterpret_cast<HTMLElement*>(element ));
108 if (oldInstance) { 108 if (oldInstance) {
109 DartDOMWrapper::disassociateWrapper<DartHTMLElement>( 109 DartDOMWrapper::disassociateWrapper<DartHTMLElement>(
110 domData, 110 domData,
111 reinterpret_cast<HTMLElement*>(element), 111 reinterpret_cast<HTMLElement*>(element),
112 Dart_HandleFromWeakPersistent(oldInstance)); 112 Dart_HandleFromWeakPersistent(oldInstance));
113 } 113 }
114 114
115 domData->pushUpgradingCustomElement(element); 115 Dart_Handle newInstance = Dart_Allocate(customType);
116 ASSERT(!Dart_IsError(newInstance));
116 117
117 Dart_Handle newInstance = Dart_New(customType, Dart_NewStringFromCString("cr eated"), 0, 0); 118 Dart_Handle result = Dart_SetNativeInstanceField(newInstance, 0, reinterpret _cast<intptr_t>(element));
118 if (Dart_IsError(newInstance)) { 119 UNUSED_PARAM(result);
119 domData->popUpgradingCustomElement(); 120 ASSERT(!Dart_IsError(result));
120 121
121 DartUtilities::reportProblem(DartDOMData::current()->scriptExecutionCont ext(), newInstance); 122 result = Dart_InvokeConstructor(newInstance, Dart_NewStringFromCString("crea ted"), 0, 0);
123
124 if (Dart_IsError(result)) {
125 DartUtilities::reportProblem(domData->scriptExecutionContext(), newInsta nce);
122 126
123 // Fall back to the old wrapper if possible. 127 // Fall back to the old wrapper if possible.
124 if (oldInstance) { 128 if (oldInstance) {
125 Dart_Handle oldWrapper = Dart_HandleFromWeakPersistent(oldInstance); 129 Dart_Handle oldWrapper = Dart_HandleFromWeakPersistent(oldInstance);
126 DartDOMWrapper::associateWrapper<DartHTMLElement>(domData, element, oldWrapper); 130 DartDOMWrapper::associateWrapper<DartHTMLElement>(domData, element, oldWrapper);
127 return oldWrapper; 131 return oldWrapper;
128 } 132 }
129 133
130 // When the upgrade fails the failed wrapper may have been associated, 134 // When the upgrade fails the failed wrapper may have been associated,
131 // so we need to create a new one and re-associate it. 135 // so we need to create a new one and re-associate it.
132 Dart_Handle fallbackWrapper = createUpgradeCandidateWrapper(element, cre ateSpecificWrapper); 136 Dart_Handle fallbackWrapper = createUpgradeCandidateWrapper(element, cre ateSpecificWrapper);
133 137
134 DartDOMWrapper::associateWrapper<DartHTMLElement>(domData, element, fall backWrapper); 138 DartDOMWrapper::associateWrapper<DartHTMLElement>(domData, element, fall backWrapper);
135 Dart_Handle result = Dart_SetNativeInstanceField(fallbackWrapper, 0, rei nterpret_cast<intptr_t>(element)); 139 Dart_Handle result = Dart_SetNativeInstanceField(fallbackWrapper, 0, rei nterpret_cast<intptr_t>(element));
136 UNUSED_PARAM(result); 140 UNUSED_PARAM(result);
137 ASSERT(!Dart_IsError(result)); 141 ASSERT(!Dart_IsError(result));
138 142
139 return fallbackWrapper; 143 return fallbackWrapper;
140 } 144 }
141 // Should have come through initializeCustomElement.
142 ASSERT(!domData->isUpgradingCustomElement(element));
143 return newInstance; 145 return newInstance;
144 } 146 }
145 147
146 template<> 148 template<>
147 Dart_Handle DartCustomElementWrapper<SVGElement>::upgradeDartWrapper(SVGElement* element, Dart_Handle (*createSpecificWrapper)(SVGElement* element)) 149 Dart_Handle DartCustomElementWrapper<SVGElement>::upgradeDartWrapper(SVGElement* element, Dart_Handle (*createSpecificWrapper)(SVGElement* element))
148 { 150 {
149 // TODO: support SVG elements. 151 // TODO: support SVG elements.
150 ASSERT(FALSE); 152 ASSERT(FALSE);
151 return Dart_Handle(); 153 return Dart_Handle();
152 } 154 }
153 155
154 template<> 156 template<>
155 void DartCustomElementWrapper<HTMLElement>::initializeCustomElement(Dart_Handle wrapper, Dart_Handle& exception) 157 void DartCustomElementWrapper<HTMLElement>::initializeCustomElement(Dart_Handle wrapper, Dart_Handle& exception)
156 { 158 {
157 DartDOMData* domData = DartDOMData::current(); 159 DartDOMData* domData = DartDOMData::current();
158 HTMLElement* element = reinterpret_cast<HTMLElement*>(domData->popUpgradingC ustomElement()); 160 HTMLElement* element = DartDOMWrapper::unwrapDartWrapper<DartHTMLElement>(do mData, wrapper, exception);
161 if (exception) {
162 return;
163 }
159 if (!element) { 164 if (!element) {
160 exception = Dart_NewStringFromCString("created called outside of custom element creation."); 165 exception = Dart_NewStringFromCString("created called outside of custom element creation.");
161 return; 166 return;
162 } 167 }
163 168
164 DartDOMWrapper::associateWrapper<DartHTMLElement>(domData, element, wrapper) ; 169 DartDOMWrapper::associateWrapper<DartHTMLElement>(domData, element, wrapper) ;
165
166 Dart_Handle result = Dart_SetNativeInstanceField(wrapper, 0, reinterpret_cas t<intptr_t>(element));
167 UNUSED_PARAM(result);
168 ASSERT(!Dart_IsError(result));
169 } 170 }
170 171
171 template 172 template
172 class DartCustomElementWrapper<HTMLElement>; 173 class DartCustomElementWrapper<HTMLElement>;
173 174
174 template 175 template
175 class DartCustomElementWrapper<SVGElement>; 176 class DartCustomElementWrapper<SVGElement>;
176 177
177 } // namespace WebCore 178 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/dart/DartDOMData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698