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

Side by Side Diff: tools/dom/src/native_DOMImplementation.dart

Issue 22859033: Support for type extensions in Dartium (part 1) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | « tests/html/html.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of html; 5 part of html;
6 6
7 class _Utils { 7 class _Utils {
8 static double dateTimeToDouble(DateTime dateTime) => 8 static double dateTimeToDouble(DateTime dateTime) =>
9 dateTime.millisecondsSinceEpoch.toDouble(); 9 dateTime.millisecondsSinceEpoch.toDouble();
10 static DateTime doubleToDateTime(double dateTime) { 10 static DateTime doubleToDateTime(double dateTime) {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 (str != null && str[str.length - 1] == '.') ? str.substring(0, str.length - 1) : str; 188 (str != null && str[str.length - 1] == '.') ? str.substring(0, str.length - 1) : str;
189 189
190 static String addTrailingDot(String str) => '${str}.'; 190 static String addTrailingDot(String str) => '${str}.';
191 191
192 static bool isNoSuchMethodError(obj) => obj is NoSuchMethodError; 192 static bool isNoSuchMethodError(obj) => obj is NoSuchMethodError;
193 193
194 // TODO(jacobr): we need a failsafe way to determine that a Node is really a 194 // TODO(jacobr): we need a failsafe way to determine that a Node is really a
195 // DOM node rather than just a class that extends Node. 195 // DOM node rather than just a class that extends Node.
196 static bool isNode(obj) => obj is Node; 196 static bool isNode(obj) => obj is Node;
197 197
198 static bool _isBuiltinType(ClassMirror cls) {
199 // TODO(vsm): Find a less hackish way to do this.
200 LibraryMirror lib = cls.owner;
201 String libName = lib.uri.toString();
202 return libName.startsWith('dart:');
203 }
204
198 static void register(String tag, Type type) { 205 static void register(String tag, Type type) {
199 // TODO(vsm): Move these checks into native code. 206 // TODO(vsm): Move these checks into native code.
200 if (type == null) { 207 if (type == null) {
201 throw new UnsupportedError("Invalid null type."); 208 throw new UnsupportedError("Invalid null type.");
202 } 209 }
203 ClassMirror cls = reflectClass(type); 210 ClassMirror cls = reflectClass(type);
204 LibraryMirror lib = cls.owner; 211 if (_isBuiltinType(cls)) {
205 String libName = lib.uri.toString();
206 if (libName.startsWith('dart:')) {
207 throw new UnsupportedError("Invalid custom element from $libName."); 212 throw new UnsupportedError("Invalid custom element from $libName.");
208 } 213 }
209 ClassMirror superClass = cls.superclass; 214 ClassMirror superClass = cls.superclass;
210 215
211 Symbol objectName = reflectClass(Object).qualifiedName; 216 Symbol objectName = reflectClass(Object).qualifiedName;
212 bool isRoot(ClassMirror cls) => 217 bool isRoot(ClassMirror cls) =>
213 cls == null || cls.qualifiedName == objectName; 218 cls == null || cls.qualifiedName == objectName;
214 // TODO(vsm): Support extending SvgElement as well. 219 // TODO(vsm): Support extending SvgElement as well.
215 Symbol elementName = reflectClass(HtmlElement).qualifiedName; 220 Symbol elementName = reflectClass(HtmlElement).qualifiedName;
216 bool isElement(ClassMirror cls) => 221 bool isElement(ClassMirror cls) =>
217 cls != null && cls.qualifiedName == elementName; 222 cls != null && cls.qualifiedName == elementName;
218 223
224 ClassMirror nativeClass = _isBuiltinType(superClass) ? superClass : null;
219 while(!isRoot(superClass) && !isElement(superClass)) { 225 while(!isRoot(superClass) && !isElement(superClass)) {
220 superClass = superClass.superclass; 226 superClass = superClass.superclass;
227 if (nativeClass == null && _isBuiltinType(superClass)) {
228 nativeClass = superClass;
229 }
221 } 230 }
222 231
223 if (isRoot(superClass)) { 232 if (isRoot(superClass)) {
224 throw new UnsupportedError("Invalid custom element doesn't inherit from Ht mlElement."); 233 throw new UnsupportedError("Invalid custom element doesn't inherit from Ht mlElement.");
225 } 234 }
226 _register(tag, type); 235 _register(tag, type, nativeClass.reflectedType);
227 } 236 }
228 237
229 static void _register(String tag, Type type) native "Utils_register"; 238 static void _register(String tag, Type customType, Type nativeType) native "Ut ils_register";
230 } 239 }
231 240
232 class _NPObject extends NativeFieldWrapperClass1 { 241 class _NPObject extends NativeFieldWrapperClass1 {
233 _NPObject.internal(); 242 _NPObject.internal();
234 static _NPObject retrieve(String key) native "NPObject_retrieve"; 243 static _NPObject retrieve(String key) native "NPObject_retrieve";
235 property(String propertyName) native "NPObject_property"; 244 property(String propertyName) native "NPObject_property";
236 invoke(String methodName, [List args = null]) native "NPObject_invoke"; 245 invoke(String methodName, [List args = null]) native "NPObject_invoke";
237 } 246 }
238 247
239 class _DOMWindowCrossFrame extends NativeFieldWrapperClass1 implements 248 class _DOMWindowCrossFrame extends NativeFieldWrapperClass1 implements
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 _send(msg) { 430 _send(msg) {
422 _sendToHelperIsolate(msg, _sendPort); 431 _sendToHelperIsolate(msg, _sendPort);
423 } 432 }
424 433
425 bool get isActive => _isActive; 434 bool get isActive => _isActive;
426 } 435 }
427 436
428 get _pureIsolateTimerFactoryClosure => 437 get _pureIsolateTimerFactoryClosure =>
429 ((int milliSeconds, void callback(Timer time), bool repeating) => 438 ((int milliSeconds, void callback(Timer time), bool repeating) =>
430 new _PureIsolateTimer(milliSeconds, callback, repeating)); 439 new _PureIsolateTimer(milliSeconds, callback, repeating));
OLDNEW
« no previous file with comments | « tests/html/html.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698