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

Unified Diff: sdk/lib/html/dartium/html_dartium.dart

Issue 1374543002: Fixed checking for more complex inheritance (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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:
Download patch
Index: sdk/lib/html/dartium/html_dartium.dart
diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart
index f262bece629db2d77d216fdc6b13a69d4fbc8834..63d115219c51e157c52002ba2f553273abe571c4 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -20148,7 +20148,8 @@ class HtmlDocument extends Document {
while (classMirror.superclass != null) {
var fullName = classMirror.superclass.qualifiedName;
- isElement = isElement || (fullName == #dart.dom.html.Element);
+ isElement = isElement ||
+ (fullName == #dart.dom.html.Element || fullName == #dart.dom.svg.Element);
var domLibrary = MirrorSystem.getName(fullName).startsWith('dart.dom.');
if (jsClassName == null && domLibrary) {
@@ -20158,7 +20159,7 @@ class HtmlDocument extends Document {
var metaDataMirror = metadata.reflectee;
var metaType = reflectClass(metaDataMirror.runtimeType);
if (MirrorSystem.getName(metaType.simpleName) == 'DomName' &&
- metaDataMirror.name.startsWith('HTML')) {
+ (metaDataMirror.name.startsWith('HTML') || metaDataMirror.name.startsWith('SVG'))) {
jsClassName = metadata.reflectee.name;
}
}
@@ -20172,6 +20173,37 @@ class HtmlDocument extends Document {
}
/**
+ * Get the class that immediately derived from a class in dart:html or
+ * dart:svg (has an attribute DomName of either HTML* or SVG*).
+ */
+ ClassMirror _getDomSuperClass(ClassMirror classMirror) {
+ var isElement = false;
+
+ while (classMirror.superclass != null) {
+ var fullName = classMirror.superclass.qualifiedName;
+ isElement = isElement || (fullName == #dart.dom.html.Element || fullName == #dart.dom.svg.Element);
+
+ var domLibrary = MirrorSystem.getName(fullName).startsWith('dart.dom.');
+ if (domLibrary) {
+ // Lookup JS class (if not found).
+ var metadatas = classMirror.metadata;
+ for (var metadata in metadatas) {
+ var metaDataMirror = metadata.reflectee;
+ var metaType = reflectClass(metaDataMirror.runtimeType);
+ if (MirrorSystem.getName(metaType.simpleName) == 'DomName' &&
+ (metaDataMirror.name.startsWith('HTML') || metaDataMirror.name.startsWith('SVG'))) {
+ if (isElement) return classMirror;
+ }
+ }
+ }
+
+ classMirror = classMirror.superclass;
+ }
+
+ return null;
+ }
+
+ /**
* Does this CustomElement class have:
*
* - a created constructor with no arguments?
@@ -20179,26 +20211,39 @@ class HtmlDocument extends Document {
*
* e.g., MyCustomClass.created() : super.created();
*/
- bool _hasCreatedConstructor(ClassMirror classMirror) {
- var createdParametersValid = false;
- var superCreatedCalled = false;
- var className = MirrorSystem.getName(classMirror.simpleName);
- var methodMirror = classMirror.declarations[new Symbol("$className.created")];
- if (methodMirror != null) {
- createdParametersValid = methodMirror.parameters.length == 0;
-
- // Get the created constructor source and look at the initializer;
- // Must call super.created() if not its as an error.
- var createdSource = methodMirror.source;
- RegExp regExp = new RegExp(r":(.*?)(;|}|\n)");
- var match = regExp.firstMatch(createdSource);
- superCreatedCalled = match.input.substring(match.start,match.end).contains("super.created()");
- }
-
- if (!superCreatedCalled) {
- throw new DomException.jsInterop('created constructor initializer must call super.created()');
- } else if (!createdParametersValid) {
- throw new DomException.jsInterop('created constructor must have no parameters');
+ bool _hasCreatedConstructor(ClassMirror classToRegister) {
+ var htmlClassMirror = _getDomSuperClass(classToRegister);
+
+ var classMirror = classToRegister;
+ while (classMirror != null && classMirror != htmlClassMirror) {
+ var createdParametersValid = false;
+ var superCreatedCalled = false;
+ var className = MirrorSystem.getName(classMirror.simpleName);
+ var methodMirror = classMirror.declarations[new Symbol("$className.created")];
+ if (methodMirror != null && methodMirror.isConstructor) {
+ createdParametersValid = true; // Assume no parameters.
+ if (methodMirror.parameters.length != 0) {
+ // If any parameters each one must be optional.
+ methodMirror.parameters.forEach((parameter) {
+ createdParametersValid = createdParametersValid && parameter.isOptional;
+ });
+ }
+
+ // Get the created constructor source and look at the initializer;
+ // Must call super.created() if not its as an error.
+ var createdSource = methodMirror.source.replaceAll('\n', ' ');
+ RegExp regExp = new RegExp(r":(.*?)(;|}|\n)");
+ var match = regExp.firstMatch(createdSource);
+ superCreatedCalled = match.input.substring(match.start,match.end).contains("super.created(");
+ }
+
+ if (!superCreatedCalled) {
+ throw new DomException.jsInterop('created constructor initializer must call super.created()');
+ } else if (!createdParametersValid) {
+ throw new DomException.jsInterop('created constructor must have no parameters');
+ }
+
+ classMirror = classMirror.superclass;
}
return true;

Powered by Google App Engine
This is Rietveld 408576698