From 8a42f6e49cd2dae11eada1a54bd7e425cfa87f88 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Thu, 25 Mar 2021 02:48:15 -0400 Subject: [PATCH] user stack trace now works for firefox --- src/Constants.ts | 1 + src/Missions.js | 1 - src/NetscriptFunctions.js | 42 ++++++++++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/Constants.ts b/src/Constants.ts index 503259489..67ad67485 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -236,6 +236,7 @@ export let CONSTANTS: IMap = { Netscript * 'connect': a new singularity function that connects you to a server. (like the terminal command) * 'manualHack': a new singularity function that performs a manual hack on the players current server. + * ns2 stack trace works on Firefox now. Misc. * New shortcut, Alt + b, brings you to bladeburner diff --git a/src/Missions.js b/src/Missions.js index f4ad73640..1eeab6c05 100644 --- a/src/Missions.js +++ b/src/Missions.js @@ -1516,7 +1516,6 @@ HackingMission.prototype.finishMission = function(win) { var gain = this.reward * Player.faction_rep_mult * favorMult; dialogBoxCreate("Mission won! You earned " + numeralWrapper.format(gain, '0.000a') + " reputation with " + this.faction.name); - console.log(`diff ${this.difficulty}`); Player.gainIntelligenceExp(this.difficulty * CONSTANTS.IntelligenceHackingMissionBaseExpGain); this.faction.playerReputation += gain; } else { diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 9536bf89a..9085ab29d 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -406,16 +406,42 @@ function NetscriptFunctions(workerScript) { } if(!filename) continue - const lineRe = /.*:(\d+):\d+.*/; - const lineMatch = stackline.match(lineRe); + function parseChromeStackline(line) { + const lineRe = /.*:(\d+):\d+.*/; + const funcRe = /.*at (.+) \(.*/; + const lineMatch = line.match(lineRe); + const funcMatch = line.match(funcRe); + if(lineMatch && funcMatch) { + let func = funcMatch[1]; + return {line: lineMatch[1], func: func}; + } + return null; + } + let call = {line: "-1", func: "unknown"};; + let chromeCall = parseChromeStackline(stackline); + if (chromeCall) { + call = chromeCall; + } - const funcRe = /.*at (.+) \(.*/; - const funcMatch = stackline.match(funcRe); - let func = funcMatch[1]; - if(func.includes('.')) func = func.split('.')[1]; + function parseFirefoxStackline(line) { + const lineRe = /.*:(\d+):\d+$/; + const lineMatch = line.match(lineRe); - userstack.push(`${filename}:L${lineMatch[1]}@${func}`); + const lio = line.lastIndexOf("@"); + + if(lineMatch && lio !== -1) { + return {line: lineMatch[1], func: line.slice(0, lio)}; + } + return null; + } + + let firefoxCall = parseFirefoxStackline(stackline); + if (firefoxCall) { + call = firefoxCall; + } + + userstack.push(`${filename}:L${call.line}@${call.func}`); } workerScript.log(caller, msg); @@ -1688,8 +1714,6 @@ function NetscriptFunctions(workerScript) { checkTixApiAccess("buyStock"); const stock = getStockFromSymbol(symbol, "buyStock"); const res = buyStock(stock, shares, workerScript, { rerenderFn: displayStockMarketContent }); - console.log(stock); - console.log(res); return res ? stock.price : 0; }, sellStock: function(symbol, shares) {