Skip to content

Commit 3307317

Browse files
author
Olivier Chafik
committed
JS: Format if statements with no else on a single line
To match Dart style: https://www.dartlang.org/effective-dart/style/#do-use-curly-braces-for-all-flow-control-structures (also, that's the style we use in our .js runtime files, so that will help with diffs of the js->dart runtime migration from dart-archive/dev_compiler#310) BUG= [email protected] Review URL: https://codereview.chromium.org/1524843002 .
1 parent e29437a commit 3307317

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+146368
-2742
lines changed

pkg/dev_compiler/lib/runtime/dart/_foreign_helper.js

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,18 @@ dart_library.library('dart/_foreign_helper', null, /* Imports */[
66
'use strict';
77
let dartx = dart.dartx;
88
function JS(typeDescription, codeTemplate, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) {
9-
if (arg0 === void 0)
10-
arg0 = null;
11-
if (arg1 === void 0)
12-
arg1 = null;
13-
if (arg2 === void 0)
14-
arg2 = null;
15-
if (arg3 === void 0)
16-
arg3 = null;
17-
if (arg4 === void 0)
18-
arg4 = null;
19-
if (arg5 === void 0)
20-
arg5 = null;
21-
if (arg6 === void 0)
22-
arg6 = null;
23-
if (arg7 === void 0)
24-
arg7 = null;
25-
if (arg8 === void 0)
26-
arg8 = null;
27-
if (arg9 === void 0)
28-
arg9 = null;
29-
if (arg10 === void 0)
30-
arg10 = null;
31-
if (arg11 === void 0)
32-
arg11 = null;
9+
if (arg0 === void 0) arg0 = null;
10+
if (arg1 === void 0) arg1 = null;
11+
if (arg2 === void 0) arg2 = null;
12+
if (arg3 === void 0) arg3 = null;
13+
if (arg4 === void 0) arg4 = null;
14+
if (arg5 === void 0) arg5 = null;
15+
if (arg6 === void 0) arg6 = null;
16+
if (arg7 === void 0) arg7 = null;
17+
if (arg8 === void 0) arg8 = null;
18+
if (arg9 === void 0) arg9 = null;
19+
if (arg10 === void 0) arg10 = null;
20+
if (arg11 === void 0) arg11 = null;
3321
}
3422
dart.fn(JS, dart.dynamic, [core.String, core.String], [dart.dynamic, dart.dynamic, dart.dynamic, dart.dynamic, dart.dynamic, dart.dynamic, dart.dynamic, dart.dynamic, dart.dynamic, dart.dynamic, dart.dynamic, dart.dynamic]);
3523
function JS_CURRENT_ISOLATE_CONTEXT() {

pkg/dev_compiler/lib/runtime/dart/_interceptors.js

Lines changed: 81 additions & 162 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/runtime/dart/_internal.js

Lines changed: 71 additions & 142 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/runtime/dart/_isolate_helper.js

Lines changed: 48 additions & 96 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/runtime/dart/_js_helper.js

Lines changed: 39 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,11 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
8888
this[_nativeAnchoredRegExp] = null;
8989
}
9090
get [_nativeGlobalVersion]() {
91-
if (this[_nativeGlobalRegExp] != null)
92-
return this[_nativeGlobalRegExp];
91+
if (this[_nativeGlobalRegExp] != null) return this[_nativeGlobalRegExp];
9392
return this[_nativeGlobalRegExp] = JSSyntaxRegExp.makeNative(this.pattern, this[_isMultiLine], this[_isCaseSensitive], true);
9493
}
9594
get [_nativeAnchoredVersion]() {
96-
if (this[_nativeAnchoredRegExp] != null)
97-
return this[_nativeAnchoredRegExp];
95+
if (this[_nativeAnchoredRegExp] != null) return this[_nativeAnchoredRegExp];
9896
return this[_nativeAnchoredRegExp] = JSSyntaxRegExp.makeNative(`${this.pattern}|()`, this[_isMultiLine], this[_isCaseSensitive], true);
9997
}
10098
get [_isMultiLine]() {
@@ -116,29 +114,25 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
116114
}
117115

118116
})();
119-
if (regexp instanceof RegExp)
120-
return regexp;
117+
if (regexp instanceof RegExp) return regexp;
121118
let errorMessage = String(regexp);
122119
dart.throw(new core.FormatException(`Illegal RegExp pattern: ${source}, ${errorMessage}`));
123120
}
124121
firstMatch(string) {
125122
let m = dart.as(this[_nativeRegExp].exec(checkString(string)), core.List$(core.String));
126-
if (m == null)
127-
return null;
123+
if (m == null) return null;
128124
return new _MatchImplementation(this, m);
129125
}
130126
hasMatch(string) {
131127
return this[_nativeRegExp].test(checkString(string));
132128
}
133129
stringMatch(string) {
134130
let match = this.firstMatch(string);
135-
if (match != null)
136-
return match.group(0);
131+
if (match != null) return match.group(0);
137132
return null;
138133
}
139134
allMatches(string, start) {
140-
if (start === void 0)
141-
start = 0;
135+
if (start === void 0) start = 0;
142136
checkString(string);
143137
checkInt(start);
144138
if (dart.notNull(start) < 0 || dart.notNull(start) > dart.notNull(string[dartx.length])) {
@@ -150,24 +144,20 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
150144
let regexp = this[_nativeGlobalVersion];
151145
regexp.lastIndex = start;
152146
let match = dart.as(regexp.exec(string), core.List);
153-
if (match == null)
154-
return null;
147+
if (match == null) return null;
155148
return new _MatchImplementation(this, dart.as(match, core.List$(core.String)));
156149
}
157150
[_execAnchored](string, start) {
158151
let regexp = this[_nativeAnchoredVersion];
159152
regexp.lastIndex = start;
160153
let match = dart.as(regexp.exec(string), core.List);
161-
if (match == null)
162-
return null;
163-
if (match[dartx.get](dart.notNull(match[dartx.length]) - 1) != null)
164-
return null;
154+
if (match == null) return null;
155+
if (match[dartx.get](dart.notNull(match[dartx.length]) - 1) != null) return null;
165156
match[dartx.length] = dart.notNull(match[dartx.length]) - 1;
166157
return new _MatchImplementation(this, dart.as(match, core.List$(core.String)));
167158
}
168159
matchAsPrefix(string, start) {
169-
if (start === void 0)
170-
start = 0;
160+
if (start === void 0) start = 0;
171161
if (dart.notNull(start) < 0 || dart.notNull(start) > dart.notNull(string[dartx.length])) {
172162
dart.throw(new core.RangeError.range(start, 0, string[dartx.length]));
173163
}
@@ -271,8 +261,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
271261
return this[_current];
272262
}
273263
moveNext() {
274-
if (this[_string] == null)
275-
return false;
264+
if (this[_string] == null) return false;
276265
if (dart.notNull(this[_nextIndex]) <= dart.notNull(this[_string][dartx.length])) {
277266
let match = this[_regExp][_execGlobal](this[_string], this[_nextIndex]);
278267
if (match != null) {
@@ -377,8 +366,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
377366
dart.fn(stringReplaceJS);
378367
function stringReplaceFirstRE(receiver, regexp, to, startIndex) {
379368
let match = dart.dsend(regexp, _execGlobal, receiver, startIndex);
380-
if (match == null)
381-
return receiver;
369+
if (match == null) return receiver;
382370
let start = dart.dload(match, 'start');
383371
let end = dart.dload(match, 'end');
384372
return `${dart.dsend(receiver, 'substring', 0, start)}${to}${dart.dsend(receiver, 'substring', end)}`;
@@ -428,10 +416,8 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
428416
if (!dart.is(pattern, core.Pattern)) {
429417
dart.throw(new core.ArgumentError(`${pattern} is not a Pattern`));
430418
}
431-
if (onMatch == null)
432-
onMatch = _matchString;
433-
if (onNonMatch == null)
434-
onNonMatch = _stringIdentity;
419+
if (onMatch == null) onMatch = _matchString;
420+
if (onNonMatch == null) onNonMatch = _stringIdentity;
435421
if (typeof pattern == 'string') {
436422
return stringReplaceAllStringFuncUnchecked(receiver, pattern, onMatch, onNonMatch);
437423
}
@@ -492,12 +478,10 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
492478
}
493479
dart.fn(stringReplaceAllStringFuncUnchecked);
494480
function stringReplaceFirstUnchecked(receiver, from, to, startIndex) {
495-
if (startIndex === void 0)
496-
startIndex = 0;
481+
if (startIndex === void 0) startIndex = 0;
497482
if (typeof from == 'string') {
498483
let index = dart.dsend(receiver, 'indexOf', from, startIndex);
499-
if (dart.notNull(dart.as(dart.dsend(index, '<', 0), core.bool)))
500-
return receiver;
484+
if (dart.notNull(dart.as(dart.dsend(index, '<', 0), core.bool))) return receiver;
501485
return `${dart.dsend(receiver, 'substring', 0, index)}${to}` + `${dart.dsend(receiver, 'substring', dart.dsend(index, '+', dart.dload(from, 'length')))}`;
502486
} else if (dart.is(from, JSSyntaxRegExp)) {
503487
return startIndex == 0 ? stringReplaceJS(receiver, regExpGetNative(dart.as(from, JSSyntaxRegExp)), to) : stringReplaceFirstRE(receiver, from, to, startIndex);
@@ -555,8 +539,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
555539
dart.throw(new core.FormatException(string));
556540
}
557541
static parseInt(source, radix, handleError) {
558-
if (handleError == null)
559-
handleError = dart.fn(s => dart.as(Primitives._throwFormatException(dart.as(s, core.String)), core.int), core.int, [dart.dynamic]);
542+
if (handleError == null) handleError = dart.fn(s => dart.as(Primitives._throwFormatException(dart.as(s, core.String)), core.int), core.int, [dart.dynamic]);
560543
checkString(source);
561544
let match = /^\s*[+-]?((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$/i.exec(source);
562545
let digitsIndex = 1;
@@ -575,8 +558,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
575558
return handleError(source);
576559
}
577560
} else {
578-
if (!(typeof radix == 'number'))
579-
dart.throw(new core.ArgumentError("Radix is not an integer"));
561+
if (!(typeof radix == 'number')) dart.throw(new core.ArgumentError("Radix is not an integer"));
580562
if (dart.notNull(radix) < 2 || dart.notNull(radix) > 36) {
581563
dart.throw(new core.RangeError(`Radix ${radix} not in range 2..36`));
582564
}
@@ -601,14 +583,12 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
601583
}
602584
}
603585
}
604-
if (match == null)
605-
return handleError(source);
586+
if (match == null) return handleError(source);
606587
return parseInt(source, radix);
607588
}
608589
static parseDouble(source, handleError) {
609590
checkString(source);
610-
if (handleError == null)
611-
handleError = dart.fn(s => dart.as(Primitives._throwFormatException(dart.as(s, core.String)), core.double), core.double, [dart.dynamic]);
591+
if (handleError == null) handleError = dart.fn(s => dart.as(Primitives._throwFormatException(dart.as(s, core.String)), core.double), core.double, [dart.dynamic]);
612592
if (!/^\s*[+-]?(?:Infinity|NaN|(?:\.\d+|\d+(?:\.\d*)?)(?:[eE][+-]?\d+)?)\s*$/.test(source)) {
613593
return handleError(source);
614594
}
@@ -633,20 +613,15 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
633613
return Date.now();
634614
}
635615
static initTicker() {
636-
if (Primitives.timerFrequency != null)
637-
return;
616+
if (Primitives.timerFrequency != null) return;
638617
Primitives.timerFrequency = 1000;
639618
Primitives.timerTicks = Primitives.dateNow;
640-
if (typeof window == "undefined")
641-
return;
619+
if (typeof window == "undefined") return;
642620
let jsWindow = window;
643-
if (jsWindow == null)
644-
return;
621+
if (jsWindow == null) return;
645622
let performance = jsWindow.performance;
646-
if (performance == null)
647-
return;
648-
if (typeof performance.now != "function")
649-
return;
623+
if (performance == null) return;
624+
if (typeof performance.now != "function") return;
650625
Primitives.timerFrequency = 1000000;
651626
Primitives.timerTicks = dart.fn(() => (1000 * performance.now())[dartx.floor](), core.int, []);
652627
}
@@ -680,8 +655,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
680655
static stringFromCodePoints(codePoints) {
681656
let a = dart.list([], core.int);
682657
for (let i of dart.as(codePoints, core.Iterable)) {
683-
if (!(typeof i == 'number'))
684-
dart.throw(new core.ArgumentError(i));
658+
if (!(typeof i == 'number')) dart.throw(new core.ArgumentError(i));
685659
if (dart.notNull(dart.as(dart.dsend(i, '<=', 65535), core.bool))) {
686660
a[dartx.add](dart.as(i, core.int));
687661
} else if (dart.notNull(dart.as(dart.dsend(i, '<=', 1114111), core.bool))) {
@@ -695,12 +669,9 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
695669
}
696670
static stringFromCharCodes(charCodes) {
697671
for (let i of dart.as(charCodes, core.Iterable)) {
698-
if (!(typeof i == 'number'))
699-
dart.throw(new core.ArgumentError(i));
700-
if (dart.notNull(dart.as(dart.dsend(i, '<', 0), core.bool)))
701-
dart.throw(new core.ArgumentError(i));
702-
if (dart.notNull(dart.as(dart.dsend(i, '>', 65535), core.bool)))
703-
return Primitives.stringFromCodePoints(charCodes);
672+
if (!(typeof i == 'number')) dart.throw(new core.ArgumentError(i));
673+
if (dart.notNull(dart.as(dart.dsend(i, '<', 0), core.bool))) dart.throw(new core.ArgumentError(i));
674+
if (dart.notNull(dart.as(dart.dsend(i, '>', 65535), core.bool))) return Primitives.stringFromCodePoints(charCodes);
704675
}
705676
return Primitives._fromCharCodeApply(dart.as(charCodes, core.List$(core.int)));
706677
}
@@ -727,14 +698,11 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
727698
static getTimeZoneName(receiver) {
728699
let d = Primitives.lazyAsJsDate(receiver);
729700
let match = dart.as(/\((.*)\)/.exec(d.toString()), core.List);
730-
if (match != null)
731-
return dart.as(match[dartx.get](1), core.String);
701+
if (match != null) return dart.as(match[dartx.get](1), core.String);
732702
match = dart.as(/^[A-Z,a-z]{3}\s[A-Z,a-z]{3}\s\d+\s\d{2}:\d{2}:\d{2}\s([A-Z]{3,5})\s\d{4}$/.exec(d.toString()), core.List);
733-
if (match != null)
734-
return dart.as(match[dartx.get](1), core.String);
703+
if (match != null) return dart.as(match[dartx.get](1), core.String);
735704
match = dart.as(/(?:GMT|UTC)[+-]\d{4}/.exec(d.toString()), core.List);
736-
if (match != null)
737-
return dart.as(match[dartx.get](0), core.String);
705+
if (match != null) return dart.as(match[dartx.get](0), core.String);
738706
return "";
739707
}
740708
static getTimeZoneOffsetInMinutes(receiver) {
@@ -760,8 +728,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
760728
if (dart.notNull(dart.as(dart.dload(value, 'isNaN'), core.bool)) || dart.notNull(dart.as(dart.dsend(value, '<', -dart.notNull(MAX_MILLISECONDS_SINCE_EPOCH)), core.bool)) || dart.notNull(dart.as(dart.dsend(value, '>', MAX_MILLISECONDS_SINCE_EPOCH), core.bool))) {
761729
return null;
762730
}
763-
if (dart.notNull(dart.as(dart.dsend(years, '<=', 0), core.bool)) || dart.notNull(dart.as(dart.dsend(years, '<', 100), core.bool)))
764-
return Primitives.patchUpY2K(value, years, isUtc);
731+
if (dart.notNull(dart.as(dart.dsend(years, '<=', 0), core.bool)) || dart.notNull(dart.as(dart.dsend(years, '<', 100), core.bool))) return Primitives.patchUpY2K(value, years, isUtc);
765732
return value;
766733
}
767734
static patchUpY2K(value, years, isUtc) {
@@ -805,11 +772,9 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
805772
return (dart.notNull(weekday) + 6) % 7 + 1;
806773
}
807774
static valueFromDateString(str) {
808-
if (!(typeof str == 'string'))
809-
dart.throw(new core.ArgumentError(str));
775+
if (!(typeof str == 'string')) dart.throw(new core.ArgumentError(str));
810776
let value = Date.parse(str);
811-
if (dart.notNull(value[dartx.isNaN]))
812-
dart.throw(new core.ArgumentError(str));
777+
if (dart.notNull(value[dartx.isNaN])) dart.throw(new core.ArgumentError(str));
813778
return value;
814779
}
815780
static getProperty(object, key) {
@@ -880,8 +845,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
880845
}
881846
dart.fn(stringLastIndexOfUnchecked);
882847
function checkNull(object) {
883-
if (object == null)
884-
dart.throw(new core.ArgumentError(null));
848+
if (object == null) dart.throw(new core.ArgumentError(null));
885849
return object;
886850
}
887851
dart.fn(checkNull);
@@ -930,8 +894,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
930894
super.Error();
931895
}
932896
toString() {
933-
if (this[_method] == null)
934-
return `NullError: ${this[_message]}`;
897+
if (this[_method] == null) return `NullError: ${this[_message]}`;
935898
return `NullError: Cannot call "${this[_method]}" on null`;
936899
}
937900
}
@@ -948,8 +911,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
948911
super.Error();
949912
}
950913
toString() {
951-
if (this[_method] == null)
952-
return `NoSuchMethodError: ${this[_message]}`;
914+
if (this[_method] == null) return `NoSuchMethodError: ${this[_message]}`;
953915
if (this[_receiver] == null) {
954916
return `NoSuchMethodError: Cannot call "${this[_method]}" (${this[_message]})`;
955917
}
@@ -984,8 +946,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
984946
this[_trace] = null;
985947
}
986948
toString() {
987-
if (this[_trace] != null)
988-
return this[_trace];
949+
if (this[_trace] != null) return this[_trace];
989950
let trace = null;
990951
if (typeof this[_exception] === "object") {
991952
trace = dart.as(this[_exception].stack, core.String);

pkg/dev_compiler/lib/runtime/dart/_js_mirrors.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[
6767
return new JsInstanceMirror._(value);
6868
}
6969
invoke(symbol, args, namedArgs) {
70-
if (namedArgs === void 0)
71-
namedArgs = null;
70+
if (namedArgs === void 0) namedArgs = null;
7271
let name = getName(symbol);
7372
if (namedArgs != null) {
7473
args = core.List.from(args);
@@ -118,8 +117,7 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[
118117
this[_declarations].set(this.simpleName, new JsMethodMirror._(this, this[_cls]));
119118
}
120119
newInstance(constructorName, args, namedArgs) {
121-
if (namedArgs === void 0)
122-
namedArgs = null;
120+
if (namedArgs === void 0) namedArgs = null;
123121
dart.assert(getName(constructorName) == "");
124122
dart.assert(namedArgs == null || dart.notNull(namedArgs.isEmpty));
125123
let instance = new this[_cls](...args);
@@ -138,8 +136,7 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[
138136
return dart.throw(new core.UnimplementedError("ClassMirror.getField unimplemented"));
139137
}
140138
invoke(memberName, positionalArguments, namedArguments) {
141-
if (namedArguments === void 0)
142-
namedArguments = null;
139+
if (namedArguments === void 0) namedArguments = null;
143140
return dart.throw(new core.UnimplementedError("ClassMirror.invoke unimplemented"));
144141
}
145142
isAssignableTo(other) {

pkg/dev_compiler/lib/runtime/dart/_metadata.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ dart_library.library('dart/_metadata', null, /* Imports */[
77
let dartx = dart.dartx;
88
class SupportedBrowser extends core.Object {
99
SupportedBrowser(browserName, minimumVersion) {
10-
if (minimumVersion === void 0)
11-
minimumVersion = null;
10+
if (minimumVersion === void 0) minimumVersion = null;
1211
this.browserName = browserName;
1312
this.minimumVersion = minimumVersion;
1413
}

0 commit comments

Comments
 (0)