Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changed API of post-traps to include all arguments of the pre-trap as…

… well
  • Loading branch information...
commit 7ebbcd467dd3c9e44af81869513c43dbbcd722ef 1 parent 89b4243
@tvcutsem authored
View
5 notification/README.md
@@ -15,7 +15,10 @@ Pre-trap generic signature:
`on{Operation}(target, ...args) -> undefined | callable`
Post-trap generic signature:
-`function(target, result) -> void`
+`function(target, ...args, result) -> void`
+
+The post-trap receives all the arguments of the pre-trap, including the result
+of applying the operation to the target object.
Notification Proxy Handler API
==============================
View
5 notification/logger.js
@@ -52,7 +52,8 @@ function logPreAndPost(/*...args*/) {
var args = Array.prototype.slice.call(arguments);
indent++;
log("before", args);
- return function(target, result) {
+ return function(/*target, ...args, result*/) {
+ var result = arguments[arguments.length-1];
log("after", result);
indent--;
}
@@ -139,7 +140,7 @@ function makeGenericLoggingProxy(target) {
onGet: function(stash, trapName) {
if (!(trapName in stash)) {
stash[trapName] = logPreAndPost.bind(undefined, trapName);
- return function(tgt, res) {
+ return function(/*...args*/) {
delete stash[trapName];
}
}
View
3  notification/notify-reflect.js
@@ -367,7 +367,8 @@ function trap(target, handler, onTrapName, trapArgs, realArgs, protectResult) {
if (typeof postTrap !== "function") {
throw new TypeError(trapName + " post-trap is not callable: "+postTrap);
}
- postTrap.call(handler, target, protectResult(result));
+ tTrapArgs.push(protectResult(result)); // add result as last argument
+ postTrap.apply(handler, tTrapArgs);
}
return result;
}
Please sign in to comment.
Something went wrong with that request. Please try again.