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

Side by Side Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1294423002: cps: Use BuiltinOperator.IsNumber for 'is num' (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library code_generator; 5 library code_generator;
6 6
7 import 'glue.dart'; 7 import 'glue.dart';
8 8
9 import '../../closure.dart' show ClosureClassElement; 9 import '../../closure.dart' show ClosureClassElement;
10 import '../../common/codegen.dart' show CodegenRegistry; 10 import '../../common/codegen.dart' show CodegenRegistry;
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 return new js.Binary('===', args[0], args[1]); 860 return new js.Binary('===', args[0], args[1]);
861 case BuiltinOperator.StrictNeq: 861 case BuiltinOperator.StrictNeq:
862 return new js.Binary('!==', args[0], args[1]); 862 return new js.Binary('!==', args[0], args[1]);
863 case BuiltinOperator.LooseEq: 863 case BuiltinOperator.LooseEq:
864 return new js.Binary('==', args[0], args[1]); 864 return new js.Binary('==', args[0], args[1]);
865 case BuiltinOperator.LooseNeq: 865 case BuiltinOperator.LooseNeq:
866 return new js.Binary('!=', args[0], args[1]); 866 return new js.Binary('!=', args[0], args[1]);
867 case BuiltinOperator.IsFalsy: 867 case BuiltinOperator.IsFalsy:
868 return new js.Prefix('!', args[0]); 868 return new js.Prefix('!', args[0]);
869 case BuiltinOperator.IsNumber: 869 case BuiltinOperator.IsNumber:
870 return js.js("typeof # === 'number'", args); 870 return js.js('typeof # === "number"', args);
871 case BuiltinOperator.IsNotNumber: 871 case BuiltinOperator.IsNotNumber:
872 return js.js("typeof # !== 'number'", args); 872 return js.js('typeof # !== "number"', args);
873 case BuiltinOperator.IsFloor: 873 case BuiltinOperator.IsFloor:
874 return js.js("Math.floor(#) === #", args); 874 return js.js('Math.floor(#) === #', args);
875 case BuiltinOperator.IsNumberAndFloor: 875 case BuiltinOperator.IsNumberAndFloor:
876 return js.js("typeof # === 'number' && Math.floor(#) === #", args); 876 return js.js('typeof # === "number" && Math.floor(#) === #', args);
877 } 877 }
878 } 878 }
879 879
880 /// The JS name of a built-in method. 880 /// The JS name of a built-in method.
881 static final Map<BuiltinMethod, String> builtinMethodName = 881 static final Map<BuiltinMethod, String> builtinMethodName =
882 const <BuiltinMethod, String>{ 882 const <BuiltinMethod, String>{
883 BuiltinMethod.Push: 'push', 883 BuiltinMethod.Push: 'push',
884 BuiltinMethod.Pop: 'pop', 884 BuiltinMethod.Pop: 'pop',
885 }; 885 };
886 886
887 @override 887 @override
888 js.Expression visitApplyBuiltinMethod(tree_ir.ApplyBuiltinMethod node) { 888 js.Expression visitApplyBuiltinMethod(tree_ir.ApplyBuiltinMethod node) {
889 String name = builtinMethodName[node.method]; 889 String name = builtinMethodName[node.method];
890 js.Expression receiver = visitExpression(node.receiver); 890 js.Expression receiver = visitExpression(node.receiver);
891 List<js.Expression> args = visitExpressionList(node.arguments); 891 List<js.Expression> args = visitExpressionList(node.arguments);
892 return js.js('#.#(#)', [receiver, name, args]); 892 return js.js('#.#(#)', [receiver, name, args]);
893 } 893 }
894 894
895 @override 895 @override
896 js.Expression visitAwait(tree_ir.Await node) { 896 js.Expression visitAwait(tree_ir.Await node) {
897 return new js.Await(visitExpression(node.input)); 897 return new js.Await(visitExpression(node.input));
898 } 898 }
899 899
900 visitFunctionExpression(tree_ir.FunctionExpression node) { 900 visitFunctionExpression(tree_ir.FunctionExpression node) {
901 // FunctionExpressions are currently unused. 901 // FunctionExpressions are currently unused.
902 // We might need them if we want to emit raw JS nested functions. 902 // We might need them if we want to emit raw JS nested functions.
903 throw 'FunctionExpressions should not be used'; 903 throw 'FunctionExpressions should not be used';
904 } 904 }
905 } 905 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698