[Pkg-javascript-commits] [dojo] 18/58: Fix #18637: Prevent aspect.before/after errors after removing handles
David Prévot
taffit at moszumanska.debian.org
Thu Mar 24 04:28:24 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag 1.10.5
in repository dojo.
commit 2bcaa187b072c07bc9de59c1a9d2930226f4bc5c
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
Backported from master to 1.10.
(cherry picked from commit 89034c5a611a061d456557bd84c08aed4e111674)
---
aspect.js | 18 +++++++++++-------
tests/aspect.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 63 insertions(+), 10 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/aspect.js b/tests/aspect.js
index 460d558..b314291 100644
--- a/tests/aspect.js
+++ b/tests/aspect.js
@@ -26,7 +26,31 @@ doh.register("tests.aspect",
obj.method(9);
t.is(order, [0,1,2,3,4,5,6,7,8,9]);
},
+ function beforeMultipleRemoveInHandler(t){
+ var count = 0;
+ var error;
+ var obj = {
+ method: function(){}
+ };
+
+ var handle1 = aspect.before(obj, 'method', function(){
+ count++;
+ });
+
+ var handle2 = aspect.before(obj, 'method', function(){
+ count++;
+ handle2.remove();
+ handle1.remove();
+ });
+ try{
+ obj.method();
+ }catch(e){
+ error = e;
+ }
+ t.f(error, 'Calling method should not throw an error');
+ t.is(count, 1, 'Only one advising function should be called');
+ },
function after(t){
var order = [];
var obj = {
@@ -82,7 +106,7 @@ doh.register("tests.aspect",
},
function afterMultiple(t){
var order = [];
- obj = {
+ var obj = {
foo: function(){}
};
aspect.after(obj, "foo", function(){order.push(1)});
@@ -91,6 +115,31 @@ doh.register("tests.aspect",
obj.foo();
t.is([1,2,3], order);
},
+ function afterMultipleRemoveInHandler(t){
+ var count = 0;
+ var error;
+ var obj = {
+ method: function(){}
+ };
+
+ var handle1 = aspect.after(obj, 'method', function () {
+ handle1.remove();
+ handle2.remove();
+ count++;
+ });
+
+ var handle2 = aspect.after(obj, 'method', function () {
+ count++;
+ });
+
+ try{
+ obj.method();
+ }catch(e){
+ error = e;
+ }
+ t.f(error, 'Calling method should not throw an error');
+ t.is(count, 1, 'Only one advising function should be called');
+ },
function around(t){
var order = [];
var obj = {
@@ -160,14 +209,14 @@ doh.register("tests.aspect",
// This should execute all 3 callbacks
foo.bar();
-
+
signal2.remove();
signal3.remove();
// Ideally signal2 should not be removed again, but can happen if the app
// fails to clear its state.
signal2.remove();
-
+
// This should execute only the first callback, but notice that the third callback
// is executed as well
foo.bar();
--
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