Skip to content
Merged
Changes from 1 commit
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
36 changes: 30 additions & 6 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,13 +805,37 @@ function joinRegExp(patterns) {
return new RegExp(sources.join('|'), 'i');
}

// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
function uuid4() {
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0,
v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
var crypto = window.crypto || window.msCrypto;

if (typeof(crypto) !== 'undefined' && crypto.getRandomValues) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to isUndefined(crypto) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem, did not see that function up there

// Use window.crypto API if available
var arr = new Uint16Array(8);
crypto.getRandomValues(arr);

// set 4 in byte 7
arr[3] = arr[3] & 0xFFF | 0x4000;
// set 2 most significant bits of byte 9 to '10'
arr[4] = arr[4] & 0x3FFF | 0x8000;

var pad = function(num) {
var v = num.toString(16);
while (v.length < 4) {
v = '0' + v;
}
return v;
};

return (pad(arr[0]) + pad(arr[1]) + pad(arr[2]) + pad(arr[3]) + pad(arr[4]) +
pad(arr[5]) + pad(arr[6]) + pad(arr[7]));
} else {
// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0,
v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
}

function logDebug(level, message) {
Expand Down