| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 dart.dom.html; | 5 part of dart.dom.html; |
| 6 | 6 |
| 7 /// Dartium ElementUpgrader implementation. | 7 /// Dartium ElementUpgrader implementation. |
| 8 class _VMElementUpgrader implements ElementUpgrader { | 8 class _VMElementUpgrader implements ElementUpgrader { |
| 9 final Type _type; | 9 final Type _type; |
| 10 final Type _nativeType; | 10 final Type _nativeType; |
| 11 | 11 |
| 12 _VMElementUpgrader(Document document, Type type, String extendsTag) : | 12 _VMElementUpgrader(Document document, Type type, String extendsTag) : |
| 13 _type = type, | 13 _type = type, |
| 14 _nativeType = _validateCustomType(type).reflectedType { | 14 _nativeType = _validateCustomType(type).reflectedType { |
| 15 | 15 |
| 16 if (extendsTag == null) { | 16 if (extendsTag == null) { |
| 17 if (_nativeType != HtmlElement) { | 17 if (_nativeType != HtmlElement) { |
| 18 throw new UnsupportedError('Class must provide extendsTag if base ' | 18 throw new UnsupportedError('Class must provide extendsTag if base ' |
| 19 'native class is not HtmlElement'); | 19 'native class is not HtmlElement'); |
| 20 } | 20 } |
| 21 } else { | 21 } else { |
| 22 if (document.createElement(extendsTag).runtimeType != _nativeType) { | 22 if (document.createElement(extendsTag).runtimeType != _nativeType) { |
| 23 throw new UnsupportedError( | 23 throw new UnsupportedError( |
| 24 'extendsTag does not match base native class'); | 24 'extendsTag does not match base native class'); |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 | 28 |
| 29 Element upgrade(Element element) { | 29 Element upgrade(element) { |
| 30 if (element.runtimeType != _nativeType) { | 30 if (element.runtimeType != js.JsObjectImpl) { |
| 31 throw new UnsupportedError('Element is incorrect type'); | 31 throw new UnsupportedError('Element is incorrect type'); |
| 32 } | 32 } |
| 33 return _Utils.changeElementWrapper(element, _type); | 33 |
| 34 return createCustomUpgrader(_nativeType, element); |
| 34 } | 35 } |
| 35 } | 36 } |
| 36 | 37 |
| 37 /// Validates that the custom type is properly formed- | 38 /// Validates that the custom type is properly formed- |
| 38 /// | 39 /// |
| 39 /// * Is a user-defined class. | 40 /// * Is a user-defined class. |
| 40 /// * Has a created constructor with zero args. | 41 /// * Has a created constructor with zero args. |
| 41 /// * Derives from an Element subclass. | 42 /// * Derives from an Element subclass. |
| 42 /// | 43 /// |
| 43 /// Then returns the native base class. | 44 /// Then returns the native base class. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 return nativeClass; | 85 return nativeClass; |
| 85 } | 86 } |
| 86 | 87 |
| 87 | 88 |
| 88 bool _isBuiltinType(ClassMirror cls) { | 89 bool _isBuiltinType(ClassMirror cls) { |
| 89 // TODO(vsm): Find a less hackish way to do this. | 90 // TODO(vsm): Find a less hackish way to do this. |
| 90 LibraryMirror lib = cls.owner; | 91 LibraryMirror lib = cls.owner; |
| 91 String libName = lib.uri.toString(); | 92 String libName = lib.uri.toString(); |
| 92 return libName.startsWith('dart:'); | 93 return libName.startsWith('dart:'); |
| 93 } | 94 } |
| OLD | NEW |