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

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

Issue 2394103002: Fix for the missing new keyword on an external factory call and updated expected test failures/e… (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | 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 1b306a74106e06b1567709c1048fa146950435f5..456e8e345c5fae122d444cf393ace275029f5095 100644
--- a/pkg/dev_compiler/lib/src/compiler/code_generator.dart
+++ b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
@@ -3872,6 +3872,7 @@ class CodeGenerator extends GeneralizingAstVisitor
JS.Expression emitNew() {
JS.Expression ctor;
bool isFactory = false;
+ bool isNative = false;
if (element == null) {
// TODO(jmesserly): this only happens if we had a static error.
// Should we generate a throw instead?
@@ -3884,9 +3885,12 @@ class CodeGenerator extends GeneralizingAstVisitor
} else {
ctor = _emitConstructorName(element, type, name);
isFactory = element.isFactory;
+ var classElem = element.enclosingElement;
+ isNative = _isJSNative(classElem);
}
var args = _visit(argumentList) as List<JS.Expression>;
- return isFactory ? new JS.Call(ctor, args) : new JS.New(ctor, args);
+ // Native factory constructors are JS constructors - use new here.
+ return isFactory && !isNative ? new JS.Call(ctor, args) : new JS.New(ctor, args);
}
if (element != null && _isObjectLiteral(element.enclosingElement)) {
@@ -3901,6 +3905,9 @@ class CodeGenerator extends GeneralizingAstVisitor
findAnnotation(classElem, isJSAnonymousAnnotation) != null;
}
+ bool _isJSNative(ClassElement classElem) =>
+ findAnnotation(classElem, isPublicJSAnnotation) != null;
+
JS.Expression _emitObjectLiteral(ArgumentList argumentList) {
var args = _visit(argumentList) as List<JS.Expression>;
if (args.isEmpty) {
« no previous file with comments | « no previous file | pkg/dev_compiler/test/browser/language_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698