Skip to content

Commit

Permalink
use include
Browse files Browse the repository at this point in the history
  • Loading branch information
asukaminato0721 committed Dec 28, 2024
1 parent 94951b9 commit 0bc9fed
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/core/friendly_errors/sketch_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ if (typeof IS_MINIFIED !== 'undefined') {
}

let p5Constructors = {};
for (let key of Object.keys(p5)) {
for (let [key, value] of Object.entries(p5)) {
// Get a list of all constructors in p5. They are functions whose names
// start with a capital letter
if (typeof p5[key] === 'function' && key[0] !== key[0].toLowerCase()) {
p5Constructors[key] = p5[key];
if (typeof value === 'function' && key[0] !== key[0].toLowerCase()) {
p5Constructors[key] = value;
}
}
for (let i = 0; i < variableArray.length; i++) {
Expand Down
45 changes: 31 additions & 14 deletions src/core/friendly_errors/stacktrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function ErrorStackParser() {
* Given an Error object, extract the most information from it.
* @private
* @param {Error} error object
* @return {Array} of stack frames
*/
parse: function ErrorStackParser$$parse(error) {
if (
Expand All @@ -50,25 +49,33 @@ function ErrorStackParser() {
}
},

// Separate line and column numbers from a string of the form: (URI:Line:Column)
/**
* @description Separate line and column numbers from a string of the form: (URI:Line:Column)
* @param {string} urlLike
* @returns
*/
extractLocation: function ErrorStackParser$$extractLocation(urlLike) {
// Fail-fast but return locations like "(native)"
if (urlLike.indexOf(':') === -1) {
if (!urlLike.includes(':')) {
return [urlLike];
}

let regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
let parts = regExp.exec(urlLike.replace(/[()]/g, ''));
return [parts[1], parts[2] || undefined, parts[3] || undefined];
},

/**
*
* @param {Error} error
* @returns
*/
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) {
let filtered = error.stack.split('\n').filter(function(line) {
return !!line.match(CHROME_IE_STACK_REGEXP);
}, this);

return filtered.map(function(line) {
if (line.indexOf('(eval ') > -1) {
if (line.includes('(eval ')) {
// Throw away eval information until we implement stacktrace.js/stackframe#8
line = line
.replace(/eval code/g, 'eval')
Expand Down Expand Up @@ -107,22 +114,24 @@ function ErrorStackParser() {
};
}, this);
},

/**
* @param {Error} error
*/
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) {
let filtered = error.stack.split('\n').filter(function(line) {
return !line.match(SAFARI_NATIVE_CODE_REGEXP);
}, this);

return filtered.map(function(line) {
// Throw away eval information until we implement stacktrace.js/stackframe#8
if (line.indexOf(' > eval') > -1) {
if (line.includes(' > eval')) {
line = line.replace(
/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
':$1'
);
}

if (line.indexOf('@') === -1 && line.indexOf(':') === -1) {
if (!line.includes('@') && !line.includes(':')) {
// Safari eval frames only have function names and nothing else
return {
functionName: line
Expand All @@ -145,11 +154,13 @@ function ErrorStackParser() {
}
}, this);
},

/**
* @param {Error} e
*/
parseOpera: function ErrorStackParser$$parseOpera(e) {
if (
!e.stacktrace ||
(e.message.indexOf('\n') > -1 &&
(e.message.includes('\n') &&
e.message.split('\n').length > e.stacktrace.split('\n').length)
) {
return this.parseOpera9(e);
Expand All @@ -159,7 +170,9 @@ function ErrorStackParser() {
return this.parseOpera11(e);
}
},

/**
* @param {Error} e
*/
parseOpera9: function ErrorStackParser$$parseOpera9(e) {
let lineRE = /Line (\d+).*script (?:in )?(\S+)/i;
let lines = e.message.split('\n');
Expand All @@ -178,7 +191,9 @@ function ErrorStackParser() {

return result;
},

/**
* @param {Error} e
*/
parseOpera10: function ErrorStackParser$$parseOpera10(e) {
let lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i;
let lines = e.stacktrace.split('\n');
Expand All @@ -198,8 +213,10 @@ function ErrorStackParser() {

return result;
},

// Opera 10.65+ Error.stack very similar to FF/Safari
/**
* @description Opera 10.65+ Error.stack very similar to FF/Safari
* @param {Error} error
*/
parseOpera11: function ErrorStackParser$$parseOpera11(error) {
let filtered = error.stack.split('\n').filter(function(line) {
return (
Expand Down

0 comments on commit 0bc9fed

Please sign in to comment.