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

Unified Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2659063002: Fix DOM constructors in inline JS (Closed)
Patch Set: restrict to containing extension class Created 3 years, 11 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 | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | pkg/dev_compiler/test/browser/language_tests.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/src/compiler/code_generator.dart
diff --git a/pkg/dev_compiler/lib/src/compiler/code_generator.dart b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
index 79ac857a76947ee40b01748cc93354bdf5504444..3db18c433c4eaabe163af9c417d873e8151ec40b 100644
--- a/pkg/dev_compiler/lib/src/compiler/code_generator.dart
+++ b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
@@ -3707,7 +3707,7 @@ class CodeGenerator extends GeneralizingAstVisitor
// arg[0] is static return type, used in `RestrictedStaticTypeAnalyzer`
var code = args[1];
List<AstNode> templateArgs;
- var source;
+ String source;
if (code is StringInterpolation) {
if (args.length > 2) {
throw new ArgumentError(
@@ -3727,6 +3727,28 @@ class CodeGenerator extends GeneralizingAstVisitor
source = (code as StringLiteral).stringValue;
}
+ // TODO(vsm): Constructors in dart:html and friends are trying to
+ // allocate a type defined on window/self, but this often conflicts a
+ // with the generated extenstion class in scope. We really should
+ // qualify explicitly in dart:html itself.
+ var constructorPattern = new RegExp("new [A-Z][A-Za-z]+\\(");
+ if (constructorPattern.matchAsPrefix(source) != null) {
+ var containingClass = node.parent;
+ while (
+ containingClass != null && containingClass is! ClassDeclaration) {
+ containingClass = containingClass.parent;
+ }
+ if (containingClass is ClassDeclaration &&
+ _extensionTypes.isNativeClass(containingClass.element)) {
+ var constructorName = source.substring(4, source.indexOf('('));
+ var className = containingClass.name.name;
+ if (className == constructorName) {
+ source =
+ source.replaceFirst('new $className(', 'new self.$className(');
+ }
+ }
+ }
+
// TODO(rnystrom): The JS() calls are almost never nested, and probably
// really shouldn't be, but there are at least a couple of calls in the
// HTML library where an argument to JS() is itself a JS() call. If those
« no previous file with comments | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | pkg/dev_compiler/test/browser/language_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698