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

Unified Diff: lib/runtime/dart_runtime.js

Issue 1088943006: implement tear offs (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 8 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
Index: lib/runtime/dart_runtime.js
diff --git a/lib/runtime/dart_runtime.js b/lib/runtime/dart_runtime.js
index dee8918910d4007f8ae4881cb392094f0d61b8d3..d81ba2aa6ca13b7cc9a0c53437f9883aeb0331c1 100644
--- a/lib/runtime/dart_runtime.js
+++ b/lib/runtime/dart_runtime.js
@@ -36,7 +36,13 @@ var dart, _js_helper;
if (!(field in obj)) {
throw new core.NoSuchMethodError(obj, field);
}
- return obj[field];
+ var result = obj[field];
+ if (typeof result == "function") {
+ // We can't tell if the result needs binding. Fortunately binding the
+ // same function twice has no effect, so we can simply attempt to bind.
+ return result.bind(obj);
+ }
+ return result;
}
dart.dload = dload;
@@ -98,6 +104,17 @@ var dart, _js_helper;
}
dart.dsetindex = dsetindex;
+ /**
+ * Returns bound `method`.
+ * This helper function avoids needing a temp for `obj`.
+ */
+ function bind(obj, method) {
+ // This is a static bind (dynamic would use `dload`) so no need to check
+ // if `method` is really there on `obj`.`
+ return obj[method].bind(obj);
+ }
+ dart.bind = bind;
+
function cast(obj, type) {
// TODO(vsm): handle non-nullable types
if (obj == null) return obj;

Powered by Google App Engine
This is Rietveld 408576698