Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit c9d909c

Browse files
author
Olivier Chafik
committed
Before (for f(a, {b, c: c_default})):
function f(a, opts) { let b = opts && 'b' in opts ? opts.b : null; let c = opts && 'c' in opts ? opts.c : c_default; ... After: function f(a, {b = null, c = c_default} = {}) { ... Note: - Still reverting to old code when any parameter clashes with reserved JS names (see discussion in #392) - When a parameter clashes with a Object.prototype property, using a clean default opts value (Object.create(null)). - Passing opts through in aliased constructors, both for speed/concision and correctness (since default param value semantic is weird there) BUG= [email protected] Review URL: https://codereview.chromium.org/1484263002 .
1 parent 835ec3f commit c9d909c

28 files changed

+471
-438
lines changed

bin/devrun.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ _writeHtmlRunner(
8888
'--js-flags="--harmony-arrow-functions '
8989
'--harmony-classes '
9090
'--harmony-computed-property-names '
91+
'--harmony_destructuring '
9192
'--harmony-spreadcalls"'
9293
'\n');
9394
}

lib/runtime/dart/_interceptors.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,13 @@ dart_library.library('dart/_interceptors', null, /* Imports */[
208208
dart.as(combine, dart.functionType(dart.dynamic, [dart.dynamic, E]));
209209
return _internal.IterableMixinWorkaround.fold(this, initialValue, combine);
210210
}
211-
[dartx.firstWhere](test, opts) {
211+
[dartx.firstWhere](test, {orElse = null} = {}) {
212212
dart.as(test, dart.functionType(core.bool, [E]));
213-
let orElse = opts && 'orElse' in opts ? opts.orElse : null;
214213
dart.as(orElse, dart.functionType(E, []));
215214
return dart.as(_internal.IterableMixinWorkaround.firstWhere(this, test, orElse), E);
216215
}
217-
[dartx.lastWhere](test, opts) {
216+
[dartx.lastWhere](test, {orElse = null} = {}) {
218217
dart.as(test, dart.functionType(core.bool, [E]));
219-
let orElse = opts && 'orElse' in opts ? opts.orElse : null;
220218
dart.as(orElse, dart.functionType(E, []));
221219
return dart.as(_internal.IterableMixinWorkaround.lastWhereList(this, test, orElse), E);
222220
}
@@ -345,8 +343,7 @@ dart_library.library('dart/_interceptors', null, /* Imports */[
345343
toString() {
346344
return collection.ListBase.listToString(this);
347345
}
348-
[dartx.toList](opts) {
349-
let growable = opts && 'growable' in opts ? opts.growable : true;
346+
[dartx.toList]({growable = true} = {}) {
350347
let list = this.slice();
351348
if (!dart.notNull(growable))
352349
JSArray$().markFixedList(dart.as(list, core.List));
@@ -1005,9 +1002,7 @@ dart_library.library('dart/_interceptors', null, /* Imports */[
10051002
[dartx.replaceAllMapped](from, convert) {
10061003
return this[dartx.splitMapJoin](from, {onMatch: convert});
10071004
}
1008-
[dartx.splitMapJoin](from, opts) {
1009-
let onMatch = opts && 'onMatch' in opts ? opts.onMatch : null;
1010-
let onNonMatch = opts && 'onNonMatch' in opts ? opts.onNonMatch : null;
1005+
[dartx.splitMapJoin](from, {onMatch = null, onNonMatch = null} = {}) {
10111006
return dart.as(_js_helper.stringReplaceAllFuncUnchecked(this, from, onMatch, onNonMatch), core.String);
10121007
}
10131008
[dartx.replaceFirst](from, to, startIndex) {

lib/runtime/dart/_internal.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ dart_library.library('dart/_internal', null, /* Imports */[
8383
}
8484
return false;
8585
}
86-
firstWhere(test, opts) {
86+
firstWhere(test, {orElse = null} = {}) {
8787
dart.as(test, dart.functionType(core.bool, [E]));
88-
let orElse = opts && 'orElse' in opts ? opts.orElse : null;
8988
dart.as(orElse, dart.functionType(E, []));
9089
let length = this.length;
9190
for (let i = 0; dart.notNull(i) < dart.notNull(length); i = dart.notNull(i) + 1) {
@@ -100,9 +99,8 @@ dart_library.library('dart/_internal', null, /* Imports */[
10099
return orElse();
101100
dart.throw(IterableElementError.noElement());
102101
}
103-
lastWhere(test, opts) {
102+
lastWhere(test, {orElse = null} = {}) {
104103
dart.as(test, dart.functionType(core.bool, [E]));
105-
let orElse = opts && 'orElse' in opts ? opts.orElse : null;
106104
dart.as(orElse, dart.functionType(E, []));
107105
let length = this.length;
108106
for (let i = dart.notNull(length) - 1; dart.notNull(i) >= 0; i = dart.notNull(i) - 1) {
@@ -218,8 +216,7 @@ dart_library.library('dart/_internal', null, /* Imports */[
218216
dart.as(test, dart.functionType(core.bool, [E]));
219217
return super.takeWhile(test);
220218
}
221-
toList(opts) {
222-
let growable = opts && 'growable' in opts ? opts.growable : true;
219+
toList({growable = true} = {}) {
223220
let result = null;
224221
if (dart.notNull(growable)) {
225222
result = core.List$(E).new();
@@ -357,8 +354,7 @@ dart_library.library('dart/_internal', null, /* Imports */[
357354
return new (SubListIterable$(E))(this[_iterable], this[_start], newEnd);
358355
}
359356
}
360-
toList(opts) {
361-
let growable = opts && 'growable' in opts ? opts.growable : true;
357+
toList({growable = true} = {}) {
362358
let start = this[_start];
363359
let end = this[_iterable][dartx.length];
364360
if (this[_endOrLength] != null && dart.notNull(this[_endOrLength]) < dart.notNull(end))
@@ -972,25 +968,22 @@ dart_library.library('dart/_internal', null, /* Imports */[
972968
dart.as(test, dart.functionType(core.bool, [E]));
973969
return false;
974970
}
975-
firstWhere(test, opts) {
971+
firstWhere(test, {orElse = null} = {}) {
976972
dart.as(test, dart.functionType(core.bool, [E]));
977-
let orElse = opts && 'orElse' in opts ? opts.orElse : null;
978973
dart.as(orElse, dart.functionType(E, []));
979974
if (orElse != null)
980975
return orElse();
981976
dart.throw(IterableElementError.noElement());
982977
}
983-
lastWhere(test, opts) {
978+
lastWhere(test, {orElse = null} = {}) {
984979
dart.as(test, dart.functionType(core.bool, [E]));
985-
let orElse = opts && 'orElse' in opts ? opts.orElse : null;
986980
dart.as(orElse, dart.functionType(E, []));
987981
if (orElse != null)
988982
return orElse();
989983
dart.throw(IterableElementError.noElement());
990984
}
991-
singleWhere(test, opts) {
985+
singleWhere(test, {orElse = null} = {}) {
992986
dart.as(test, dart.functionType(core.bool, [E]));
993-
let orElse = opts && 'orElse' in opts ? opts.orElse : null;
994987
dart.as(orElse, dart.functionType(E, []));
995988
if (orElse != null)
996989
return orElse();
@@ -1033,8 +1026,7 @@ dart_library.library('dart/_internal', null, /* Imports */[
10331026
dart.as(test, dart.functionType(core.bool, [E]));
10341027
return this;
10351028
}
1036-
toList(opts) {
1037-
let growable = opts && 'growable' in opts ? opts.growable : true;
1029+
toList({growable = true} = {}) {
10381030
return dart.notNull(growable) ? dart.list([], E) : core.List$(E).new(0);
10391031
}
10401032
toSet() {

lib/runtime/dart/_isolate_helper.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ dart_library.library('dart/_isolate_helper', null, /* Imports */[
3434
const _id = Symbol('_id');
3535
const _receivePort = Symbol('_receivePort');
3636
class _Serializer extends core.Object {
37-
_Serializer(opts) {
38-
let serializeSendPorts = opts && 'serializeSendPorts' in opts ? opts.serializeSendPorts : true;
37+
_Serializer({serializeSendPorts = true} = {}) {
3938
this.serializedObjectIds = core.Map$(dart.dynamic, core.int).identity();
4039
this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool);
4140
}
@@ -191,8 +190,7 @@ dart_library.library('dart/_isolate_helper', null, /* Imports */[
191190
});
192191
const _adjustSendPorts = Symbol('_adjustSendPorts');
193192
class _Deserializer extends core.Object {
194-
_Deserializer(opts) {
195-
let adjustSendPorts = opts && 'adjustSendPorts' in opts ? opts.adjustSendPorts : true;
193+
_Deserializer({adjustSendPorts = true} = {}) {
196194
this.deserializedObjects = core.List.new();
197195
this[_adjustSendPorts] = dart.as(adjustSendPorts, core.bool);
198196
}
@@ -1412,10 +1410,7 @@ dart_library.library('dart/_isolate_helper', null, /* Imports */[
14121410
this[_controller] = async.StreamController.new({onCancel: dart.bind(this, 'close'), sync: true});
14131411
this[_rawPort].handler = dart.bind(this[_controller], 'add');
14141412
}
1415-
listen(onData, opts) {
1416-
let onError = opts && 'onError' in opts ? opts.onError : null;
1417-
let onDone = opts && 'onDone' in opts ? opts.onDone : null;
1418-
let cancelOnError = opts && 'cancelOnError' in opts ? opts.cancelOnError : null;
1413+
listen(onData, {onError = null, onDone = null, cancelOnError = null} = {}) {
14191414
return this[_controller].stream.listen(onData, {onError: onError, onDone: onDone, cancelOnError: cancelOnError});
14201415
}
14211416
close() {

lib/runtime/dart/_js_helper.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
3131
constructors: () => ({Native: [Native, [core.String]]})
3232
});
3333
class JsPeerInterface extends core.Object {
34-
JsPeerInterface(opts) {
35-
let name = opts && 'name' in opts ? opts.name : null;
34+
JsPeerInterface({name = null} = {}) {
3635
this.name = name;
3736
}
3837
}
@@ -79,9 +78,7 @@ dart_library.library('dart/_js_helper', null, /* Imports */[
7978
toString() {
8079
return `RegExp/${this.pattern}/`;
8180
}
82-
JSSyntaxRegExp(source, opts) {
83-
let multiLine = opts && 'multiLine' in opts ? opts.multiLine : false;
84-
let caseSensitive = opts && 'caseSensitive' in opts ? opts.caseSensitive : true;
81+
JSSyntaxRegExp(source, {multiLine = false, caseSensitive = true} = {}) {
8582
this.pattern = source;
8683
this[_nativeRegExp] = JSSyntaxRegExp.makeNative(source, multiLine, caseSensitive, false);
8784
this[_nativeGlobalRegExp] = null;

0 commit comments

Comments
 (0)