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

Unified Diff: lib/runtime/_operations.js

Issue 1316723003: implement null aware ops, fixes #249 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « .gitignore ('k') | lib/runtime/dart/_interceptors.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/runtime/_operations.js
diff --git a/lib/runtime/_operations.js b/lib/runtime/_operations.js
index 1dfae7521d77167646681dad5585e86007e3ba3b..c018641c47b2daa9051e886bc7b2d646f0395e90 100644
--- a/lib/runtime/_operations.js
+++ b/lib/runtime/_operations.js
@@ -62,6 +62,7 @@ dart_library.library('dart_runtime/_operations', null, /* Imports */[
// TODO(vsm): Implement NSM and type checks.
// See: https://github.com/dart-lang/dev_compiler/issues/170
obj[field] = value;
+ return value;
}
exports.dput = dput;
@@ -168,7 +169,8 @@ dart_library.library('dart_runtime/_operations', null, /* Imports */[
exports.dindex = dindex;
function dsetindex(obj, index, value) {
- return callMethod(obj, 'set', [index, value], '[]=');
+ callMethod(obj, 'set', [index, value], '[]=');
+ return value;
}
exports.dsetindex = dsetindex;
@@ -318,6 +320,23 @@ dart_library.library('dart_runtime/_operations', null, /* Imports */[
}
exports.stackTrace = stackTrace;
+ /**
+ * Implements a sequence of .? operations.
+ *
+ * Will call each successive callback, unless one returns null, which stops
+ * the sequence.
+ */
+ function nullSafe(obj /*, ...callbacks*/) {
+ let callbacks = slice.call(arguments, 1);
+ if (obj == null) return obj;
+ for (const callback of callbacks) {
+ obj = callback(obj);
+ if (obj == null) break;
+ }
+ return obj;
+ }
+ exports.nullSafe = nullSafe;
+
let _value = Symbol('_value');
/**
* Looks up a sequence of [keys] in [map], recursively, and
« no previous file with comments | « .gitignore ('k') | lib/runtime/dart/_interceptors.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698