mgechev / aspect.js

JavaScript library for aspect-oriented programming using modern syntax.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow user to completely handle invocation & return value in around advice (like AspectJ does)

matthewadams opened this issue · comments

It is impossible for the user of aspect.js to completely handle around advice and prevent the advice from executing twice. Note comments in code block from master lib/src/advices/sync_advices.ts below:

export class AroundAdvice extends Advice {                                      // line 20
  wove(target: Function, metadata: Metadata) {
    this.advice.bind(this.context, metadata).apply(null, metadata.method.args); // calls advice, user can set metadata.method.proceed to false
    this.invoke(target, metadata);                                              // if metadata.method.proceed is false, invocation is skipped as it should be
    this.advice.bind(this.context, metadata).apply(null, metadata.method.args); // if metadata.method.proceed is false, advice is _still_ called -- this is inconvenient!
    return metadata.method.result;
  }
}