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

Unified Diff: tools/dom/src/native_DOMImplementation.dart

Issue 220403008: Revert "Adding a mechanism to 'upgrade' the Dart type of elements" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: tools/dom/src/native_DOMImplementation.dart
diff --git a/tools/dom/src/native_DOMImplementation.dart b/tools/dom/src/native_DOMImplementation.dart
index d8c4edc808c2dca027d1e8b4ee61a7a0c39124c9..8387a0f752fc3301a3d183cdc091f1f6f6de1a95 100644
--- a/tools/dom/src/native_DOMImplementation.dart
+++ b/tools/dom/src/native_DOMImplementation.dart
@@ -396,10 +396,48 @@ class _Utils {
static bool isNoSuchMethodError(obj) => obj is NoSuchMethodError;
+ static bool _isBuiltinType(ClassMirror cls) {
+ // TODO(vsm): Find a less hackish way to do this.
+ LibraryMirror lib = cls.owner;
+ String libName = lib.uri.toString();
+ return libName.startsWith('dart:');
+ }
+
static void register(Document document, String tag, Type type,
String extendsTagName) {
- var nativeClass = _validateCustomType(type);
+ // TODO(vsm): Move these checks into native code.
+ ClassMirror cls = reflectClass(type);
+ if (_isBuiltinType(cls)) {
+ throw new UnsupportedError("Invalid custom element from ${(cls.owner as LibraryMirror).uri}.");
+ }
+ var className = MirrorSystem.getName(cls.simpleName);
+ var createdConstructor = cls.declarations[new Symbol('$className.created')];
+ if (createdConstructor == null ||
+ createdConstructor is! MethodMirror ||
+ !createdConstructor.isConstructor) {
+ throw new UnsupportedError(
+ 'Class is missing constructor $className.created');
+ }
+ if (createdConstructor.parameters.length > 0) {
+ throw new UnsupportedError(
+ 'Constructor $className.created must take zero arguments');
+ }
+
+ Symbol objectName = reflectClass(Object).qualifiedName;
+ bool isRoot(ClassMirror cls) =>
+ cls == null || cls.qualifiedName == objectName;
+ Symbol elementName = reflectClass(HtmlElement).qualifiedName;
+ bool isElement(ClassMirror cls) =>
+ cls != null && cls.qualifiedName == elementName;
+ ClassMirror superClass = cls.superclass;
+ ClassMirror nativeClass = _isBuiltinType(superClass) ? superClass : null;
+ while(!isRoot(superClass) && !isElement(superClass)) {
+ superClass = superClass.superclass;
+ if (nativeClass == null && _isBuiltinType(superClass)) {
+ nativeClass = superClass;
+ }
+ }
if (extendsTagName == null) {
if (nativeClass.reflectedType != HtmlElement) {
throw new UnsupportedError('Class must provide extendsTag if base '
@@ -416,8 +454,6 @@ class _Utils {
static Element createElement(Document document, String tagName) native "Utils_createElement";
static void initializeCustomElement(HtmlElement element) native "Utils_initializeCustomElement";
-
- static void changeElementWrapper(HtmlElement element, Type type) native "Utils_changeElementWrapper";
}
class _DOMWindowCrossFrame extends NativeFieldWrapperClass2 implements
« no previous file with comments | « tools/dom/src/dartium_CustomElementSupport.dart ('k') | tools/dom/templates/html/dartium/html_dartium.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698