[Pkg-javascript-commits] [dojo] 67/149: Fix #18637: Prevent aspect.before/after errors after removing handles
David Prévot
taffit at moszumanska.debian.org
Sat Feb 27 03:13:48 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository dojo.
commit 89034c5a611a061d456557bd84c08aed4e111674
Author: Kenneth G. Franqueiro <kfranqueiro at sitepen.com>
Date: Thu Jul 9 14:07:38 2015 -0400
Fix #18637: Prevent aspect.before/after errors after removing handles
---
aspect.js | 18 +++++++++++-------
tests/unit/aspect.js | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/aspect.js b/aspect.js
index 391f166..a3af7c6 100644
--- a/aspect.js
+++ b/aspect.js
@@ -84,7 +84,9 @@ define([], function(){
var args = arguments;
var before = dispatcher.before;
while(before){
- args = before.advice.apply(this, args) || args;
+ if(before.advice){
+ args = before.advice.apply(this, args) || args;
+ }
before = before.next;
}
// around advice
@@ -94,12 +96,14 @@ define([], function(){
// after advice
var after = dispatcher.after;
while(after && after.id < executionId){
- if(after.receiveArguments){
- var newResults = after.advice.apply(this, args);
- // change the return value only if a new value was returned
- results = newResults === undefined ? results : newResults;
- }else{
- results = after.advice.call(this, results, args);
+ if(after.advice){
+ if(after.receiveArguments){
+ var newResults = after.advice.apply(this, args);
+ // change the return value only if a new value was returned
+ results = newResults === undefined ? results : newResults;
+ }else{
+ results = after.advice.call(this, results, args);
+ }
}
after = after.next;
}
diff --git a/tests/unit/aspect.js b/tests/unit/aspect.js
index 7594b53..eeca012 100644
--- a/tests/unit/aspect.js
+++ b/tests/unit/aspect.js
@@ -55,6 +55,25 @@ define([
assert.equal(aspectSpy1.lastCall.args[0], 6);
assert.equal(methodSpy.lastCall.args[0], 7);
assert.equal(methodSpy.returnValues[0], 8);
+ },
+
+ 'multiple aspect.before() with removal inside handler': function () {
+ var count = 0;
+
+ var handle1 = aspect.before(obj, 'method', function () {
+ count++;
+ });
+
+ var handle2 = aspect.before(obj, 'method', function () {
+ count++;
+ handle2.remove();
+ handle1.remove();
+ });
+
+ assert.doesNotThrow(function () {
+ obj.method();
+ });
+ assert.strictEqual(count, 1, 'Only one advising function should be called');
}
},
@@ -80,6 +99,25 @@ define([
assert.isTrue(aspectStub2.calledAfter(aspectStub1));
},
+ 'multiple aspect.after() with removal inside handler': function () {
+ var count = 0;
+
+ var handle1 = aspect.after(obj, 'method', function () {
+ handle1.remove();
+ handle2.remove();
+ count++;
+ });
+
+ var handle2 = aspect.after(obj, 'method', function () {
+ count++;
+ });
+
+ assert.doesNotThrow(function () {
+ obj.method();
+ });
+ assert.strictEqual(count, 1, 'Only one advising function should be called');
+ },
+
'recieveArguments is true': {
'provides the original arguments to the aspect method': function () {
var expected = 'expected';
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git
More information about the Pkg-javascript-commits
mailing list