[dart2js] Some tear-off cleanup

Replace jsArguments with isIntercepted

Change-Id: I440a86fb411d3e278fa60ed86e5d43c5efb79033
Reviewed-on: https://dart-review.googlesource.com/c/80721
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
diff --git a/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
index b816f95..ea23cbd 100644
--- a/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
@@ -273,16 +273,16 @@
   return isIntercepted
       ? new Function("funcs", "applyTrampolineIndex", "reflectionInfo", "name",
                      #tearOffGlobalObjectString, "c",
-          "return function tearOff_" + name + (functionCounter++) + "(x) {" +
+          "return function tearOff_" + name + (functionCounter++) + "(receiver) {" +
             "if (c === null) c = " + #tearOffAccessText + "(" +
-                "this, funcs, applyTrampolineIndex, reflectionInfo, false, [x], name);" +
-                "return new c(this, funcs[0], x, name);" +
+                "this, funcs, applyTrampolineIndex, reflectionInfo, false, true, name);" +
+                "return new c(this, funcs[0], receiver, name);" +
            "}")(funcs, applyTrampolineIndex, reflectionInfo, name, #tearOffGlobalObject, null)
       : new Function("funcs", "applyTrampolineIndex", "reflectionInfo", "name",
                      #tearOffGlobalObjectString, "c",
           "return function tearOff_" + name + (functionCounter++)+ "() {" +
             "if (c === null) c = " + #tearOffAccessText + "(" +
-                "this, funcs, applyTrampolineIndex, reflectionInfo, false, [], name);" +
+                "this, funcs, applyTrampolineIndex, reflectionInfo, false, false, name);" +
                 "return new c(this, funcs[0], null, name);" +
              "}")(funcs, applyTrampolineIndex, reflectionInfo, name, #tearOffGlobalObject, null);
 }''', {
@@ -292,17 +292,17 @@
     });
   } else {
     tearOffGetter = js.statement('''
-        function tearOffGetter(funcs, applyTrampolineIndex, reflectionInfo, name, isIntercepted) {
+      function tearOffGetter(funcs, applyTrampolineIndex, reflectionInfo, name, isIntercepted) {
         var cache = null;
         return isIntercepted
-            ? function(x) {
+            ? function(receiver) {
                 if (cache === null) cache = #(
-                    this, funcs, applyTrampolineIndex, reflectionInfo, false, [x], name);
-                return new cache(this, funcs[0], x, name);
+                    this, funcs, applyTrampolineIndex, reflectionInfo, false, true, name);
+                return new cache(this, funcs[0], receiver, name);
               }
             : function() {
                 if (cache === null) cache = #(
-                    this, funcs, applyTrampolineIndex, reflectionInfo, false, [], name);
+                    this, funcs, applyTrampolineIndex, reflectionInfo, false, false, name);
                 return new cache(this, funcs[0], null, name);
               };
       }''', [tearOffAccessExpression, tearOffAccessExpression]);
@@ -311,12 +311,12 @@
   jsAst.Statement tearOff = js.statement('''
       function tearOff(funcs, applyTrampolineIndex,
           reflectionInfo, isStatic, name, isIntercepted) {
-      var cache;
+      var cache = null;
       return isStatic
           ? function() {
-              if (cache === void 0) cache = #tearOff(
+              if (cache === null) cache = #tearOff(
                   this, funcs, applyTrampolineIndex,
-                  reflectionInfo, true, [], name).prototype;
+                  reflectionInfo, true, false, name).prototype;
               return cache;
             }
           : tearOffGetter(funcs, applyTrampolineIndex,
diff --git a/sdk/lib/_internal/js_runtime/lib/js_helper.dart b/sdk/lib/_internal/js_runtime/lib/js_helper.dart
index 4a5831c..14bf26d 100644
--- a/sdk/lib/_internal/js_runtime/lib/js_helper.dart
+++ b/sdk/lib/_internal/js_runtime/lib/js_helper.dart
@@ -2360,7 +2360,7 @@
     int applyTrampolineIndex,
     var reflectionInfo,
     bool isStatic,
-    jsArguments,
+    bool isIntercepted,
     String propertyName,
   ) {
     JS_EFFECT(() {
@@ -2446,12 +2446,7 @@
 
     // Create a closure and "monkey" patch it with call stubs.
     var trampoline = function;
-    var isIntercepted = false;
     if (!isStatic) {
-      if (JS('bool', '#.length == 1', jsArguments)) {
-        // Intercepted call.
-        isIntercepted = true;
-      }
       trampoline = forwardCallTo(receiver, function, isIntercepted);
       JS('', '#.\$reflectionInfo = #', trampoline, reflectionInfo);
     } else {
@@ -2793,16 +2788,14 @@
 
 /// Called from implicit method getter (aka tear-off).
 closureFromTearOff(receiver, functions, applyTrampolineIndex, reflectionInfo,
-    isStatic, jsArguments, name) {
+    isStatic, isIntercepted, name) {
   return Closure.fromTearOff(
       receiver,
-      JSArray.markFixedList(functions),
+      JS('JSArray', '#', functions),
       applyTrampolineIndex,
-      reflectionInfo is List
-          ? JSArray.markFixedList(reflectionInfo)
-          : reflectionInfo,
+      reflectionInfo,
       JS('bool', '!!#', isStatic),
-      jsArguments,
+      JS('bool', '!!#', isIntercepted),
       JS('String', '#', name));
 }