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: lib/src/codegen/js_codegen.dart

Issue 962083002: support the JS builtin (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 10 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 | « lib/src/checker/resolver.dart ('k') | lib/src/js/builder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_codegen.dart
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart
index 554b4bbea171189c09aafbb4f6d3c4e3c3c1048c..81166e316a183f91531a59a2153e2b305fa155f5 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -757,9 +757,12 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
JS.Block visitBlock(Block node) => new JS.Block(_visitList(node.statements));
@override
- JS.Expression visitMethodInvocation(MethodInvocation node) {
+ visitMethodInvocation(MethodInvocation node) {
var target = node.isCascaded ? _cascadeTarget : node.target;
+ var result = _emitForeignJS(node);
+ if (result != null) return result;
+
if (rules.isDynamicCall(node.methodName)) {
var args = node.argumentList.accept(this);
if (target != null) {
@@ -787,6 +790,25 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
return js.call('#(#)', [targetJs, node.argumentList.accept(this)]);
}
+ /// Emits code for the `JS(...)` builtin.
+ _emitForeignJS(MethodInvocation node) {
+ var e = node.methodName.staticElement;
+ if (e is FunctionElement &&
+ e.library.name == '_foreign_helper' &&
+ e.name == 'JS') {
+ var args = node.argumentList.arguments;
+ // arg[0] is static return type, used in `RestrictedStaticTypeAnalyzer`
+ var code = args[1] as StringLiteral;
+
+ var template = js.parseForeignJS(code.stringValue);
+ var result = template.instantiate(_visitList(args.skip(2)));
+ // `throw` is emitted as a statement by `parseForeignJS`.
+ assert(result is JS.Expression || node.parent is ExpressionStatement);
+ return result;
+ }
+ return null;
+ }
+
@override
JS.Expression visitFunctionExpressionInvocation(
FunctionExpressionInvocation node) {
« no previous file with comments | « lib/src/checker/resolver.dart ('k') | lib/src/js/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698