Skip to content

Commit

Permalink
Desperately terminating infinite loops.
Browse files Browse the repository at this point in the history
  • Loading branch information
PoneyClairDeLune committed Sep 2, 2022
1 parent 89293e0 commit 07117f2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion svc/ics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let ICS = function () {
const levels = ["error", "warn", "info", "debug"],
realConsole = console;
let upThis = this;
this.level = levels.indexOf("info");
this.level = levels.indexOf("debug");
levels.forEach(function (e, i) {
upThis[e] = function () {
if (upThis.level >= i) {
Expand Down
4 changes: 2 additions & 2 deletions svc/minuette.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {smartClone} from "./minuette/smartClone.js";
import {errorFilter, stackFilter} from "./minuette/stackFilter.js";
self.blacklistEvent = ["visibilitychange", "pagehide", "pageshow"];
self.fakeScreenVideo = undefined;
//self.FunStore = {}, self.FunProxy = {};
self.FunStore = {}, self.FunProxy = {};
{
let extDataId = "-ReplaceMeWithSomethingUnique-";
// Constants
Expand All @@ -28,7 +28,7 @@ self.fakeScreenVideo = undefined;
let MinConf = {};
MinConf.h = {g: 1, f: 1, b: 1, p: 1, r: 1}; // History API
// Store pool for all event listeners
let FunStore = {}, FunProxy = {};
//let FunStore = {}, FunProxy = {};
// Original console API exposure
RawApi.console = console;
// Console hijack
Expand Down
27 changes: 24 additions & 3 deletions svc/minuette/smartClone.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {getCSSSelector} from "./cssSelector.js";

const propBlacklist = [];
const recursiveLevel = 8;
const recursiveLevel = 4;

let canClone = function (value, step = 0) {
let newStep = step + 1;
Expand Down Expand Up @@ -87,6 +87,7 @@ let selectiveBlock = function (value) {
};
return prompt;
};
let ownPos;
let smartClone = function (value, step = 0) {
let newStep = step + 1;
if (canClone(value)) {
Expand All @@ -98,6 +99,24 @@ let smartClone = function (value, step = 0) {
//console.error(err.stack);
//return smartClone(err, newStep);
};
let ownStk = (new Error()).stack.split("\n");
if (!ownPos) {
ownPos = ownStk[0].slice(0, ownStk[0].lastIndexOf(":"));
ownPos = ownPos.slice(0, ownPos.lastIndexOf(":"));
};
let layerCount = 0;
ownStk.forEach(function (e) {
if (e.indexOf(ownPos) == 0) {
layerCount ++;
};
if (layerCount > 6) {
throw(new InternalError("maximum call stack reached"));
return {
uncloned: value?.constructor.name
};
};
});
//console.info(`Code block ${step}, ${layerCount} at: ${ownPos}`);
switch (value?.constructor) {
case ArrayBuffer: {
return {
Expand Down Expand Up @@ -187,8 +206,9 @@ let smartClone = function (value, step = 0) {
break;
};
case Array: {
if (step < 8) {
if (step < recursiveLevel) {
let newArr = [];
debugger;
value?.forEach(function (e, i) {
let prompt = selectiveBlock(e);
newArr[i] = smartClone(prompt, newStep);
Expand All @@ -202,8 +222,9 @@ let smartClone = function (value, step = 0) {
break;
};
default: {
if (step < 8) {
if (step < recursiveLevel) {
let newObj = {};
debugger;
for (let prop in value) {
let prompt = selectiveBlock(value[prop]);
newObj[prop] = smartClone(prompt, newStep);
Expand Down
38 changes: 20 additions & 18 deletions svc/minuette/stackFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@ const blacklist = [
];

let stackFilter = function (loc) {
let sepAt = loc.indexOf("@");
let funs = loc.slice(0, sepAt).split("/");
let result = funs[0];
if (funs.length > 1) {
let c = 0;
while (c < funs.length) {
let d = c + 1;
if ("0123456789<".indexOf(result[0]) > -1) {
result = funs[d];
} else if (blacklist.indexOf(result) > -1) {
result = funs[d];
if (loc.length > 0) {
let sepAt = loc.indexOf("@");
let funs = loc.slice(0, sepAt).split("/");
let result = funs[0];
if (funs.length > 1) {
let c = 0;
while (c < funs.length) {
let d = c + 1;
if ("0123456789<".indexOf(result[0]) > -1) {
result = funs[d];
} else if (blacklist.indexOf(result) > -1) {
result = funs[d];
};
c ++;
};
c ++;
} else if (result.length == 0) {
result = "<unnamed>";
};
} else if (result.length == 0) {
result = "<unnamed>";
result += `@${loc.slice(sepAt + 1)}`;
return result;
};
result += `@${loc.slice(sepAt + 1)}`;
return result;
};
let errorFilter = function (err) {
if (err.name && err.message?.length >= 0 && err.stack?.length >= 0) {
Expand All @@ -35,7 +37,7 @@ let errorFilter = function (err) {
};
err.stack.split("\n").forEach(function (e) {
if (e) {
msg += `\n ${smartFilter(e)}`;
msg += `\n ${stackFilter(e)}`;
};
});
} else {
Expand All @@ -46,4 +48,4 @@ let errorFilter = function (err) {
export {
errorFilter,
stackFilter
};
};
8 changes: 5 additions & 3 deletions svc/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ listeners.pageMsg = function (conn) {
case "evDel": {
break;
};
case "asyncNew":
/*case "asyncNew":
case "asyncRun":
case "asyncThen":
case "asyncCatch":
Expand All @@ -86,7 +86,7 @@ listeners.pageMsg = function (conn) {
case "promRace":
case "promSettle": {
break;
};
};*/
default: {
console.debug(msg);
};
Expand Down Expand Up @@ -195,7 +195,9 @@ let getNetLoc = async function () {
let pushNetLoc = async function () {
let geoMsg = getGeoMsg();
for (let tid in inPages) {
inPages[tid].port.postMessage(geoMsg);
try {
inPages[tid].port.postMessage(geoMsg);
} catch (err) {};
};
};
let thrgNetLoc = setInterval(function () {
Expand Down

0 comments on commit 07117f2

Please sign in to comment.