Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 4 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 14 additions & 1 deletion meld.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ define(function () {
joinpoint = pushJoinpoint({
target: context,
method: func,
args: args
args: args,
uuid: generateUUID()
});

try {
Expand Down Expand Up @@ -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 });
Expand Down
27 changes: 27 additions & 0 deletions test/joinpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

});
Expand Down