OLD | NEW |
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 _ConsoleVariables { | 7 class _ConsoleVariables { |
8 Map<String, Object> _data = new Map<String, Object>(); | 8 Map<String, Object> _data = new Map<String, Object>(); |
9 | 9 |
10 /** | 10 /** |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 | 404 |
405 static void register(Document document, String tag, Type type, | 405 static void register(Document document, String tag, Type type, |
406 String extendsTagName) { | 406 String extendsTagName) { |
407 // TODO(vsm): Move these checks into native code. | 407 // TODO(vsm): Move these checks into native code. |
408 ClassMirror cls = reflectClass(type); | 408 ClassMirror cls = reflectClass(type); |
409 if (_isBuiltinType(cls)) { | 409 if (_isBuiltinType(cls)) { |
410 throw new UnsupportedError("Invalid custom element from $libName."); | 410 throw new UnsupportedError("Invalid custom element from $libName."); |
411 } | 411 } |
412 var className = MirrorSystem.getName(cls.simpleName); | 412 var className = MirrorSystem.getName(cls.simpleName); |
413 if (!cls.constructors.containsKey(new Symbol('$className.created'))) { | 413 if (!cls.constructors.containsKey(new Symbol('$className.created'))) { |
414 throw new UnsupportedError('Class is missing constructor $className.create
d'); | 414 throw new UnsupportedError( |
| 415 'Class is missing constructor $className.created'); |
415 } | 416 } |
| 417 |
| 418 Symbol objectName = reflectClass(Object).qualifiedName; |
| 419 bool isRoot(ClassMirror cls) => |
| 420 cls == null || cls.qualifiedName == objectName; |
| 421 Symbol elementName = reflectClass(HtmlElement).qualifiedName; |
| 422 bool isElement(ClassMirror cls) => |
| 423 cls != null && cls.qualifiedName == elementName; |
| 424 ClassMirror superClass = cls.superclass; |
| 425 ClassMirror nativeClass = _isBuiltinType(superClass) ? superClass : null; |
| 426 while(!isRoot(superClass) && !isElement(superClass)) { |
| 427 superClass = superClass.superclass; |
| 428 if (nativeClass == null && _isBuiltinType(superClass)) { |
| 429 nativeClass = superClass; |
| 430 } |
| 431 } |
| 432 if (extendsTagName == null) { |
| 433 if (nativeClass.reflectedType != HtmlElement) { |
| 434 throw new UnsupportedError('Class must provide extendsTag if base ' |
| 435 'native class is not HTMLElement'); |
| 436 } |
| 437 } |
| 438 |
416 _register(document, tag, type, extendsTagName); | 439 _register(document, tag, type, extendsTagName); |
417 } | 440 } |
418 | 441 |
419 static void _register(Document document, String tag, Type customType, | 442 static void _register(Document document, String tag, Type customType, |
420 String extendsTagName) native "Utils_register"; | 443 String extendsTagName) native "Utils_register"; |
421 | 444 |
422 static Element createElement(Document document, String tagName) native "Utils_
createElement"; | 445 static Element createElement(Document document, String tagName) native "Utils_
createElement"; |
423 | 446 |
424 static void initializeCustomElement(HtmlElement element) native "Utils_initial
izeCustomElement"; | 447 static void initializeCustomElement(HtmlElement element) native "Utils_initial
izeCustomElement"; |
425 } | 448 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 _scheduleImmediateHelper._schedule(callback); | 595 _scheduleImmediateHelper._schedule(callback); |
573 }; | 596 }; |
574 | 597 |
575 get _pureIsolateScheduleImmediateClosure => ((void callback()) => | 598 get _pureIsolateScheduleImmediateClosure => ((void callback()) => |
576 throw new UnimplementedError("scheduleMicrotask in background isolates " | 599 throw new UnimplementedError("scheduleMicrotask in background isolates " |
577 "are not supported in the browser")); | 600 "are not supported in the browser")); |
578 | 601 |
579 void _initializeCustomElement(Element e) { | 602 void _initializeCustomElement(Element e) { |
580 _Utils.initializeCustomElement(e); | 603 _Utils.initializeCustomElement(e); |
581 } | 604 } |
OLD | NEW |