summaryrefslogtreecommitdiffstats
path: root/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/flight/lib/advice.js
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/flight/lib/advice.js')
-rw-r--r--third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/flight/lib/advice.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/flight/lib/advice.js b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/flight/lib/advice.js
new file mode 100644
index 0000000000..0f4686929a
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/flight/lib/advice.js
@@ -0,0 +1,69 @@
+// ==========================================
+// Copyright 2013 Twitter, Inc
+// Licensed under The MIT License
+// http://opensource.org/licenses/MIT
+// ==========================================
+
+"use strict";
+
+define(
+
+ [
+ './utils',
+ './compose'
+ ],
+
+ function (util, compose) {
+
+ var advice = {
+
+ around: function(base, wrapped) {
+ return function composedAround() {
+ // unpacking arguments by hand benchmarked faster
+ var i = 0, l = arguments.length, args = new Array(l + 1);
+ args[0] = base.bind(this);
+ for (; i < l; i++) args[i + 1] = arguments[i];
+
+ return wrapped.apply(this, args);
+ }
+ },
+
+ before: function(base, before) {
+ var beforeFn = (typeof before == 'function') ? before : before.obj[before.fnName];
+ return function composedBefore() {
+ beforeFn.apply(this, arguments);
+ return base.apply(this, arguments);
+ }
+ },
+
+ after: function(base, after) {
+ var afterFn = (typeof after == 'function') ? after : after.obj[after.fnName];
+ return function composedAfter() {
+ var res = (base.unbound || base).apply(this, arguments);
+ afterFn.apply(this, arguments);
+ return res;
+ }
+ },
+
+ // a mixin that allows other mixins to augment existing functions by adding additional
+ // code before, after or around.
+ withAdvice: function() {
+ ['before', 'after', 'around'].forEach(function(m) {
+ this[m] = function(method, fn) {
+
+ compose.unlockProperty(this, method, function() {
+ if (typeof this[method] == 'function') {
+ return this[method] = advice[m](this[method], fn);
+ } else {
+ return this[method] = fn;
+ }
+ });
+
+ };
+ }, this);
+ }
+ };
+
+ return advice;
+ }
+);