Skip to content

Commit

Permalink
fix: escape functions before "isolated logging" (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
archan937 authored Jun 23, 2022
1 parent 79dc79d commit 0ad1b94
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/functions/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,32 @@ const run = (workingDir: string): Promise<string> => {
let failures = 0;
const console = (() => {
const escape = (value) => {
switch (typeof(value)) {
case "function":
return value.toString();
case "object":
if (value == null) {
return value;
}
if (value instanceof Array) {
return value.map(escape);
} else {
return Object.keys(value).reduce((o, k) => {
o[k] = escape(value[k]);
return o;
}, {});
}
default:
return value;
}
};
const log = (level) =>
(...args) =>
$console.apply(null, [
level,
new ivm.ExternalCopy(args).copyInto()
new ivm.ExternalCopy(escape(args)).copyInto()
]);
return {
Expand Down

0 comments on commit 0ad1b94

Please sign in to comment.