Skip to content

Commit b91df1f

Browse files
committed
Simplify _normalizeFrame edgecase and comment on event factories
1 parent f8ac9e2 commit b91df1f

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

src/raven.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,21 +1387,6 @@ Raven.prototype = {
13871387
},
13881388

13891389
_normalizeFrame: function(frame, stackInfoUrl) {
1390-
if (!frame.url) {
1391-
// Case when we don't have any information about the error
1392-
// E.g. throwing a string or raw object in Firefox
1393-
// Generating synthetic error doesn't add any value here
1394-
//
1395-
// We should probably somehow let user know that he should fix his code
1396-
return {
1397-
filename: stackInfoUrl, // fallback to whole stacks url from onerror handler
1398-
lineno: frame.line,
1399-
colno: frame.column,
1400-
function: frame.func || '?', // if we dont have a file url, we most likely won't have a function name either
1401-
in_app: true // this will always come from the user's code
1402-
};
1403-
}
1404-
14051390
// normalize the frames data
14061391
var normalized = {
14071392
filename: frame.url,
@@ -1410,6 +1395,15 @@ Raven.prototype = {
14101395
function: frame.func || '?'
14111396
};
14121397

1398+
// Case when we don't have any information about the error
1399+
// E.g. throwing a string or raw object, instead of an `Error` in Firefox
1400+
// Generating synthetic error doesn't add any value here
1401+
//
1402+
// We should probably somehow let a user know that they should fix their code
1403+
if (!frame.url) {
1404+
normalized.filename = stackInfoUrl; // fallback to whole stacks url from onerror handler
1405+
}
1406+
14131407
normalized.in_app = !// determine if an exception came from outside of our app
14141408
// first we check the global includePaths list.
14151409
(

test/integration/frame.html

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,22 @@
3838
};
3939
}());
4040

41-
// Custom event factories for cross-browser compatibility
42-
41+
/**
42+
* Custom event factories for cross-browser compatibility
43+
*
44+
* Gecko browsers are using non-standard `initKeyEvent`, where others implemented `initKeyboardEvent`.
45+
* To make it more consistent, we try to use standardized `MouseEvent`/`KeyboardEvent` now
46+
* and fallback to older implementations for legacy browsers only.
47+
*
48+
* See deprecation notes:
49+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent
50+
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent
51+
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent
52+
*
53+
* References:
54+
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#Specifications
55+
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Specifications
56+
*/
4357
function createMouseEvent (options) {
4458
var options = {
4559
bubbles: true,
@@ -62,14 +76,14 @@
6276
}
6377
}
6478

65-
function createKeyboardEvent (key = 'a') {
79+
function createKeyboardEvent (key) {
6680
var options = {
6781
bubbles: true,
6882
cancelable: true,
6983
view: window,
70-
key: key,
71-
charCode: key.charCodeAt()
84+
key: key || 'a'
7285
}
86+
options.charCode = options.key.charCodeAt();
7387

7488
if ('KeyboardEvent' in window) {
7589
return new KeyboardEvent('keypress', options);

0 commit comments

Comments
 (0)