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

Unified Diff: tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate

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:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate
diff --git a/tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate b/tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate
index 25a632da63d862ff321b4bd21ef0108775ad365c..c97d4f5cc09f7417cadb7be5ab24b6f4ad4a5578 100644
--- a/tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate
+++ b/tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate
@@ -199,7 +199,8 @@ $if DARTIUM
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) {
@@ -209,7 +210,7 @@ $if DARTIUM
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;
}
}
@@ -223,6 +224,37 @@ $if DARTIUM
}
/**
+ * 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'))) {
Alan Knight 2015/09/28 22:31:42 Aren't there classes in HTML that don't start with
+ if (isElement) return classMirror;
+ }
+ }
+ }
+
+ classMirror = classMirror.superclass;
+ }
+
+ return null;
+ }
+
+ /**
* Does this CustomElement class have:
*
* - a created constructor with no arguments?
@@ -230,26 +262,39 @@ $if DARTIUM
*
* 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()");
- }
+ 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');
+ 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;
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698