diff --git a/CHANGES.md b/CHANGES.md index 91ba781..02e65d5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +### 1.3.3 + +* Added joinpoint UUID for tracing a single method invocation. + ### 1.3.2 * * Update `package.json` to use `"repository"` to avoid npm warnings. diff --git a/docs/api.md b/docs/api.md index 0de5093..69982b3 100644 --- a/docs/api.md +++ b/docs/api.md @@ -68,6 +68,10 @@ joinpoint = { // Name of the original method method: String, + + // UUID to trace a single method invocation + uuid: String, + // When, called, causes the original method to be invoked // When called without arguments, the original arguments will diff --git a/docs/reference.md b/docs/reference.md index 04c0aa6..fd9c64e 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -117,6 +117,7 @@ A joinpoint has the following properties: * target - context with which the original method was called * method - String name of the method that was called * args - Array of arguments that were passed to the method +* uuid - UUID for tracing a single method invocation ## Accessing the Joinpoint diff --git a/meld.js b/meld.js index d31bda5..78bb33c 100644 --- a/meld.js +++ b/meld.js @@ -120,7 +120,8 @@ define(function () { joinpoint = pushJoinpoint({ target: context, method: func, - args: args + args: args, + uuid: generateUUID() }); try { @@ -160,6 +161,18 @@ define(function () { function callAfter(afterType, args) { advisor._callSimpleAdvice(afterType, context, args); } + + function generateUUID() { + var d = new Date().getTime(); + var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = (d + Math.random()*16)%16 | 0; + d = Math.floor(d/16); + return (c=='x' ? r : (r&0x3|0x8)).toString(16); + }); + + return uuid; + } + }; defineProperty(advised, '_advisor', { value: advisor, configurable: true }); diff --git a/test/joinpoint.js b/test/joinpoint.js index 1ad9437..ff47e24 100644 --- a/test/joinpoint.js +++ b/test/joinpoint.js @@ -107,6 +107,33 @@ buster.testCase('joinpoint', { assert.equals(meldJoinpoint.args, expected); } + }, + + 'should identify advised function stack': function() { + var target, expected; + + target = { + method: function() {} + }; + + expected = [1, 2, 3]; + + meld.before(target, 'method', verifyJoinpoint); + meld.on(target, 'method', verifyJoinpoint); + meld.afterReturning(target, 'method', verifyJoinpoint); + meld.after(target, 'method', verifyJoinpoint); + + target.method.apply(target, expected); + + refute.defined(meld.joinpoint()); + + function verifyJoinpoint() { + var jp = meld.joinpoint(); + assert.equals(jp.target, target); + assert.equals(jp.method, 'method'); + assert.equals(jp.args, expected); + assert.defined(jp.uuid); + } } });