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

Side by Side Diff: compiler/lib/implementation/number.js

Issue 8511023: Use strict when possible. Don't even try to cache the hashcode for strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 5
6 6
7 function native_NumberImplementation_BIT_OR(other) { 7 function native_NumberImplementation_BIT_OR(other) {
8 "use strict";
8 return this | other; 9 return this | other;
9 } 10 }
10 11
11 function native_NumberImplementation_BIT_XOR(other) { 12 function native_NumberImplementation_BIT_XOR(other) {
13 "use strict";
12 return this ^ other; 14 return this ^ other;
13 } 15 }
14 16
15 function native_NumberImplementation_BIT_AND(other) { 17 function native_NumberImplementation_BIT_AND(other) {
18 "use strict";
16 return this & other; 19 return this & other;
17 } 20 }
18 21
19 function native_NumberImplementation_SHL(other) { 22 function native_NumberImplementation_SHL(other) {
23 "use strict";
20 return this << other; 24 return this << other;
21 } 25 }
22 26
23 function native_NumberImplementation_SAR(other) { 27 function native_NumberImplementation_SAR(other) {
28 "use strict";
24 return this >> other; 29 return this >> other;
25 } 30 }
26 31
27 function native_NumberImplementation_ADD(other) { 32 function native_NumberImplementation_ADD(other) {
33 "use strict";
28 return this + other; 34 return this + other;
29 } 35 }
30 36
31 function native_NumberImplementation_SUB(other) { 37 function native_NumberImplementation_SUB(other) {
32 return this - other; 38 "use strict";
39 return this - other;
33 } 40 }
34 41
35 function native_NumberImplementation_MUL(other) { 42 function native_NumberImplementation_MUL(other) {
43 "use strict";
36 return this * other; 44 return this * other;
37 } 45 }
38 46
39 function native_NumberImplementation_DIV(other) { 47 function native_NumberImplementation_DIV(other) {
48 "use strict";
40 return this / other; 49 return this / other;
41 } 50 }
42 51
43 function native_NumberImplementation_TRUNC(other) { 52 function native_NumberImplementation_TRUNC(other) {
53 "use strict";
44 var tmp = this / other; 54 var tmp = this / other;
45 if (tmp < 0) { 55 if (tmp < 0) {
46 return Math.ceil(tmp); 56 return Math.ceil(tmp);
47 } else { 57 } else {
48 return Math.floor(tmp); 58 return Math.floor(tmp);
49 } 59 }
50 } 60 }
51 61
52 function number$euclideanModulo(a, b) { 62 function number$euclideanModulo(a, b) {
53 var result = a % b; 63 var result = a % b;
54 if (result == 0) { 64 if (result == 0) {
55 return 0; // Make sure we don't return -0.0. 65 return 0; // Make sure we don't return -0.0.
56 } else if (result < 0) { 66 } else if (result < 0) {
57 if (b < 0) { 67 if (b < 0) {
58 return result - b; 68 return result - b;
59 } else { 69 } else {
60 return result + b; 70 return result + b;
61 } 71 }
62 } 72 }
63 return result; 73 return result;
64 } 74 }
65 75
66 function native_NumberImplementation_MOD(other) { 76 function native_NumberImplementation_MOD(other) {
77 "use strict";
67 return number$euclideanModulo(this, other); 78 return number$euclideanModulo(this, other);
68 } 79 }
69 80
70 function native_NumberImplementation_LT(other) { 81 function native_NumberImplementation_LT(other) {
82 "use strict";
71 return this < other; 83 return this < other;
72 } 84 }
73 85
74 function native_NumberImplementation_GT(other) { 86 function native_NumberImplementation_GT(other) {
87 "use strict";
75 return this > other; 88 return this > other;
76 } 89 }
77 90
78 function native_NumberImplementation_LTE(other) { 91 function native_NumberImplementation_LTE(other) {
92 "use strict";
79 return this <= other; 93 return this <= other;
80 } 94 }
81 95
82 function native_NumberImplementation_GTE(other) { 96 function native_NumberImplementation_GTE(other) {
97 "use strict";
83 return this >= other; 98 return this >= other;
84 } 99 }
85 100
86 function native_NumberImplementation_EQ(other) { 101 function native_NumberImplementation_EQ(other) {
102 "use strict";
87 return typeof other == 'number' && this == other; 103 return typeof other == 'number' && this == other;
88 } 104 }
89 105
90 function native_NumberImplementation_BIT_NOT() { 106 function native_NumberImplementation_BIT_NOT() {
107 "use strict";
91 return ~this; 108 return ~this;
92 } 109 }
93 110
94 function native_NumberImplementation_negate() { return -this; } 111 function native_NumberImplementation_negate() {
112 "use strict";
113 return -this;
114 }
95 115
96 function native_NumberImplementation_remainder(other) { 116 function native_NumberImplementation_remainder(other) {
117 "use strict";
97 return this % other; 118 return this % other;
98 } 119 }
99 120
100 function native_NumberImplementation_abs() { return Math.abs(this); } 121 function native_NumberImplementation_abs() {
122 "use strict";
123 return Math.abs(this);
124 }
101 125
102 function native_NumberImplementation_round() { return Math.round(this); } 126 function native_NumberImplementation_round() {
103 function native_NumberImplementation_floor() { return Math.floor(this); } 127 "use strict";
104 function native_NumberImplementation_ceil() { return Math.ceil(this); } 128 return Math.round(this);
129 }
130 function native_NumberImplementation_floor() {
131 "use strict";
132 return Math.floor(this);
133 }
134 function native_NumberImplementation_ceil() {
135 "use strict";
136 return Math.ceil(this);
137 }
105 function native_NumberImplementation_truncate() { 138 function native_NumberImplementation_truncate() {
139 "use strict";
106 return (this < 0) ? Math.ceil(this) : Math.floor(this); 140 return (this < 0) ? Math.ceil(this) : Math.floor(this);
107 } 141 }
108 function native_NumberImplementation_isNegative() { 142 function native_NumberImplementation_isNegative() {
143 "use strict";
109 // TODO(floitsch): is there a faster way to detect -0? 144 // TODO(floitsch): is there a faster way to detect -0?
110 if (this == 0) return (1 / this) < 0; 145 if (this == 0) return (1 / this) < 0;
111 return this < 0; 146 return this < 0;
112 } 147 }
113 function native_NumberImplementation_isEven() { return ((this & 1) == 0); } 148 function native_NumberImplementation_isEven() {
114 function native_NumberImplementation_isOdd() { return ((this & 1) == 1); } 149 "use strict";
115 function native_NumberImplementation_isNaN() { return isNaN(this); } 150 return ((this & 1) == 0);
151 }
152 function native_NumberImplementation_isOdd() {
153 "use strict";
154 return ((this & 1) == 1);
155 }
156 function native_NumberImplementation_isNaN() {
157 "use strict";
158 return isNaN(this);
159 }
116 function native_NumberImplementation_isInfinite() { 160 function native_NumberImplementation_isInfinite() {
161 "use strict";
117 return (this == Infinity) || (this == -Infinity); 162 return (this == Infinity) || (this == -Infinity);
118 } 163 }
119 164
120 function native_NumberImplementation_toDouble() { 165 function native_NumberImplementation_toDouble() {
121 return this.valueOf(); 166 "use strict";
167 return +this;
122 } 168 }
123 169
124 function native_NumberImplementation_toString() { 170 function native_NumberImplementation_toString() {
125 return this.toString(); 171 return this.toString();
126 } 172 }
127 function native_NumberImplementation_toStringAsFixed(fractionDigits) { 173 function native_NumberImplementation_toStringAsFixed(fractionDigits) {
128 return this.toFixed(fractionDigits); 174 return this.toFixed(fractionDigits);
129 } 175 }
130 function native_NumberImplementation_toStringAsPrecision(precision) { 176 function native_NumberImplementation_toStringAsPrecision(precision) {
131 return this.toPrecision(precision); 177 return this.toPrecision(precision);
132 } 178 }
133 function native_NumberImplementation_toStringAsExponential(fractionDigits) { 179 function native_NumberImplementation_toStringAsExponential(fractionDigits) {
134 return this.toExponential(fractionDigits); 180 return this.toExponential(fractionDigits);
135 } 181 }
136 function native_NumberImplementation_toRadixString(radix) { 182 function native_NumberImplementation_toRadixString(radix) {
137 return this.toString(radix); 183 return this.toString(radix);
138 } 184 }
139 185
140 function native_NumberImplementation_hashCode() { 186 function native_NumberImplementation_hashCode() {
187 "use strict";
141 return this & 0xFFFFFFF; 188 return this & 0xFFFFFFF;
142 } 189 }
OLDNEW
« no previous file with comments | « no previous file | compiler/lib/implementation/string.js » ('j') | compiler/lib/implementation/string.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698