Skip to content

Commit 74c7600

Browse files
author
John Messerly
committed
implement null aware ops, fixes #249
this also implements multitest support, which fixes #280 Fixes some other preexisting bugs: * MetaLets did not simplify themselves correctly in some nested cases * Library prefixed identifiers did not work as lvalues in opassign * dsetindex/dput/[]= methods did not return a value * checker did not correctly handle invalid constructor field initializers * cascades did not correctly work with method invocations(?) * postfix ++/-- did not correctly generate lvalues in some cases The good news: because this reuses on our existing lvalue/metalet helpers, it managed to flush out a lot of bugs in other features that use them. R=vsm@google.com Review URL: https://codereview.chromium.org/1316723003 .
1 parent 50eb282 commit 74c7600

31 files changed

+1490
-59
lines changed

pkg/dev_compiler/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ node_modules
1717
test/codegen/expect/dev_compiler/
1818
test/codegen/expect/language/
1919
test/codegen/expect/sunflower/dev_compiler/
20+
test/codegen/language/*_multi.dart
2021

2122
# Created by ./tool/build_sdk.sh
2223
tool/generated_sdk/

pkg/dev_compiler/lib/runtime/_operations.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ dart_library.library('dart_runtime/_operations', null, /* Imports */[
6262
// TODO(vsm): Implement NSM and type checks.
6363
// See: https://github.com/dart-lang/dev_compiler/issues/170
6464
obj[field] = value;
65+
return value;
6566
}
6667
exports.dput = dput;
6768

@@ -168,7 +169,8 @@ dart_library.library('dart_runtime/_operations', null, /* Imports */[
168169
exports.dindex = dindex;
169170

170171
function dsetindex(obj, index, value) {
171-
return callMethod(obj, 'set', [index, value], '[]=');
172+
callMethod(obj, 'set', [index, value], '[]=');
173+
return value;
172174
}
173175
exports.dsetindex = dsetindex;
174176

@@ -318,6 +320,23 @@ dart_library.library('dart_runtime/_operations', null, /* Imports */[
318320
}
319321
exports.stackTrace = stackTrace;
320322

323+
/**
324+
* Implements a sequence of .? operations.
325+
*
326+
* Will call each successive callback, unless one returns null, which stops
327+
* the sequence.
328+
*/
329+
function nullSafe(obj /*, ...callbacks*/) {
330+
let callbacks = slice.call(arguments, 1);
331+
if (obj == null) return obj;
332+
for (const callback of callbacks) {
333+
obj = callback(obj);
334+
if (obj == null) break;
335+
}
336+
return obj;
337+
}
338+
exports.nullSafe = nullSafe;
339+
321340
let _value = Symbol('_value');
322341
/**
323342
* Looks up a sequence of [keys] in [map], recursively, and

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ dart_library.library('dart/_interceptors', null, /* Imports */[
386386
if (dart.notNull(index) >= dart.notNull(this[dartx.length]) || dart.notNull(index) < 0)
387387
dart.throw(new core.RangeError.value(index));
388388
this[index] = value;
389+
return value;
389390
}
390391
[dartx.asMap]() {
391392
return new (_internal.IterableMixinWorkaround$(E))().asMapList(this);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,7 @@ dart_library.library('dart/_internal', null, /* Imports */[
16551655
set(index, value) {
16561656
dart.as(value, E);
16571657
dart.throw(new core.UnsupportedError("Cannot modify an unmodifiable list"));
1658+
return value;
16581659
}
16591660
set length(newLength) {
16601661
dart.throw(new core.UnsupportedError("Cannot change the length of an unmodifiable list"));
@@ -1857,6 +1858,7 @@ dart_library.library('dart/_internal', null, /* Imports */[
18571858
set(key, value) {
18581859
dart.as(value, E);
18591860
dart.throw(new core.UnsupportedError("Cannot modify an unmodifiable map"));
1861+
return value;
18601862
}
18611863
putIfAbsent(key, ifAbsent) {
18621864
dart.as(ifAbsent, dart.functionType(E, []));

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[
232232
this[_storage].set(dart.notNull(index) * 4 + 1, value.y);
233233
this[_storage].set(dart.notNull(index) * 4 + 2, value.z);
234234
this[_storage].set(dart.notNull(index) * 4 + 3, value.w);
235+
return value;
235236
}
236237
sublist(start, end) {
237238
if (end === void 0)
@@ -340,6 +341,7 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[
340341
this[_storage].set(dart.notNull(index) * 4 + 1, value.y);
341342
this[_storage].set(dart.notNull(index) * 4 + 2, value.z);
342343
this[_storage].set(dart.notNull(index) * 4 + 3, value.w);
344+
return value;
343345
}
344346
sublist(start, end) {
345347
if (end === void 0)
@@ -442,6 +444,7 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[
442444
this[_checkIndex](index, this.length);
443445
this[_storage].set(dart.notNull(index) * 2 + 0, value.x);
444446
this[_storage].set(dart.notNull(index) * 2 + 1, value.y);
447+
return value;
445448
}
446449
sublist(start, end) {
447450
if (end === void 0)
@@ -745,6 +748,7 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[
745748
set(index, value) {
746749
this[_checkIndex](index, this.length);
747750
this[index] = value;
751+
return value;
748752
}
749753
setRange(start, end, iterable, skipCount) {
750754
if (skipCount === void 0)
@@ -771,6 +775,7 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[
771775
set(index, value) {
772776
this[_checkIndex](index, this.length);
773777
this[index] = value;
778+
return value;
774779
}
775780
setRange(start, end, iterable, skipCount) {
776781
if (skipCount === void 0)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,8 @@ dart_library.library('dart/async', null, /* Imports */[
863863
let _cancelFuture = Symbol('_cancelFuture');
864864
let _pending = Symbol('_pending');
865865
let _setPendingEvents = Symbol('_setPendingEvents');
866-
let _extractPending = Symbol('_extractPending');
867866
let _isCanceled = Symbol('_isCanceled');
867+
let _extractPending = Symbol('_extractPending');
868868
let _isPaused = Symbol('_isPaused');
869869
let _isInputPaused = Symbol('_isInputPaused');
870870
let _inCallback = Symbol('_inCallback');
@@ -884,8 +884,8 @@ dart_library.library('dart/async', null, /* Imports */[
884884
let _sendData = Symbol('_sendData');
885885
let _addPending = Symbol('_addPending');
886886
let _sendError = Symbol('_sendError');
887-
let _close = Symbol('_close');
888887
let _sendDone = Symbol('_sendDone');
888+
let _close = Symbol('_close');
889889
let _checkState = Symbol('_checkState');
890890
let _BufferingStreamSubscription$ = dart.generic(function(T) {
891891
class _BufferingStreamSubscription extends core.Object {

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,7 @@ dart_library.library('dart/collection', null, /* Imports */[
22902290
dart.as(key, K);
22912291
dart.as(value, V);
22922292
dart.throw(new core.UnsupportedError("Cannot modify unmodifiable map"));
2293+
return value;
22932294
}
22942295
addAll(other) {
22952296
dart.as(other, core.Map$(K, V));
@@ -2414,6 +2415,7 @@ dart_library.library('dart/collection', null, /* Imports */[
24142415
dart.as(key, K);
24152416
dart.as(value, V);
24162417
this[_map].set(key, value);
2418+
return value;
24172419
}
24182420
addAll(other) {
24192421
dart.as(other, core.Map$(K, V));
@@ -3324,8 +3326,8 @@ dart_library.library('dart/collection', null, /* Imports */[
33243326
let _root = Symbol('_root');
33253327
let _count = Symbol('_count');
33263328
let _splayCount = Symbol('_splayCount');
3327-
let _splay = Symbol('_splay');
33283329
let _compare = Symbol('_compare');
3330+
let _splay = Symbol('_splay');
33293331
let _splayMin = Symbol('_splayMin');
33303332
let _splayMax = Symbol('_splayMax');
33313333
let _addNewRoot = Symbol('_addNewRoot');
@@ -3561,17 +3563,20 @@ dart_library.library('dart/collection', null, /* Imports */[
35613563
return null;
35623564
}
35633565
set(key, value) {
3564-
dart.as(key, K);
3565-
dart.as(value, V);
3566-
if (key == null)
3567-
dart.throw(new core.ArgumentError(key));
3568-
let comp = this[_splay](key);
3569-
if (comp == 0) {
3570-
let mapRoot = dart.as(this[_root], _SplayTreeMapNode);
3571-
mapRoot.value = value;
3572-
return;
3573-
}
3574-
this[_addNewRoot](new (_SplayTreeMapNode$(K, dart.dynamic))(key, value), comp);
3566+
((() => {
3567+
dart.as(key, K);
3568+
dart.as(value, V);
3569+
if (key == null)
3570+
dart.throw(new core.ArgumentError(key));
3571+
let comp = this[_splay](key);
3572+
if (comp == 0) {
3573+
let mapRoot = dart.as(this[_root], _SplayTreeMapNode);
3574+
mapRoot.value = value;
3575+
return;
3576+
}
3577+
this[_addNewRoot](new (_SplayTreeMapNode$(K, dart.dynamic))(key, value), comp);
3578+
}).bind(this))();
3579+
return value;
35753580
}
35763581
putIfAbsent(key, ifAbsent) {
35773582
dart.as(key, K);
@@ -4227,6 +4232,7 @@ dart_library.library('dart/collection', null, /* Imports */[
42274232
} else {
42284233
this[_set](key, value);
42294234
}
4235+
return value;
42304236
}
42314237
[_set](key, value) {
42324238
dart.as(key, K);
@@ -4489,6 +4495,7 @@ dart_library.library('dart/collection', null, /* Imports */[
44894495
dart.as(key, K);
44904496
dart.as(value, V);
44914497
super[_set](key, value);
4498+
return value;
44924499
}
44934500
containsKey(key) {
44944501
if (!dart.notNull(this[_validKey](key)))
@@ -4718,6 +4725,7 @@ dart_library.library('dart/collection', null, /* Imports */[
47184725
} else {
47194726
this[_set](key, value);
47204727
}
4728+
return value;
47214729
}
47224730
[_set](key, value) {
47234731
dart.as(key, K);
@@ -4970,6 +4978,7 @@ dart_library.library('dart/collection', null, /* Imports */[
49704978
dart.as(key, K);
49714979
dart.as(value, V);
49724980
super[_set](key, value);
4981+
return value;
49734982
}
49744983
containsKey(key) {
49754984
if (!dart.notNull(this[_validKey](key)))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,7 @@ dart_library.library('dart/convert', null, /* Imports */[
26652665
} else {
26662666
this[_upgrade]().set(key, value);
26672667
}
2668+
return value;
26682669
}
26692670
addAll(other) {
26702671
other.forEach(dart.fn(((key, value) => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ dart_library.library('dart/core', null, /* Imports */[
11791179
_js_helper.Primitives.setProperty(object, Expando$()._EXPANDO_PROPERTY_NAME, values);
11801180
}
11811181
_js_helper.Primitives.setProperty(values, this[_getKey](), value);
1182+
return value;
11821183
}
11831184
[_getKey]() {
11841185
let key = dart.as(_js_helper.Primitives.getProperty(this, Expando$()._KEY_PROPERTY_NAME), String);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ dart_library.library('dart/js', null, /* Imports */[
7575
dart.throw(new core.ArgumentError("property is not a String or num"));
7676
}
7777
this[_jsObject][property] = _convertToJS(value);
78+
return value;
7879
}
7980
get hashCode() {
8081
return 0;
@@ -212,6 +213,7 @@ dart_library.library('dart/js', null, /* Imports */[
212213
this[_checkIndex](index);
213214
}
214215
super.set(index, value);
216+
return value;
215217
}
216218
get length() {
217219
let len = this[_jsObject].length;

0 commit comments

Comments
 (0)