-
-
Save yorickvP/f3b5cf3f97f65f05c9ad5b94a6716098 to your computer and use it in GitHub Desktop.
testcase for gf3/sandbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* jslint esversion: 6, asi: true */ | |
const Sandbox = require('sandbox') | |
function testCallStack() { | |
let stack | |
Error.prepareStackTrace = (e, sb) => { stack = sb } | |
void (new Error()).stack | |
for (const fun of stack) { | |
// if the thisobj isn't null and not an instance of Object, | |
// it's from another context; same for function | |
if ((fun.getThis() && !(fun.getThis() instanceof Object)) || | |
(fun.getFunction() && !(fun.getFunction() instanceof Function))) { | |
const res = `breakout on ${fun}` | |
console.log(res) | |
return res | |
} | |
} | |
} | |
function tryThrow() { | |
function v() { | |
const res = testCallStack(); | |
if (res) return res; | |
else throw x; /* try the error handler */ | |
} | |
let x = { | |
get name() { return v(); }, | |
get value() { return v(); } | |
}; | |
return v(); | |
} | |
function tryOutput() { | |
function v() { | |
const res = testCallStack(); | |
if (res) return res; | |
else tryThrow(); | |
} | |
return ({ | |
toJSON() { | |
return v(); | |
} | |
}) | |
} | |
void function() { | |
const s = new Sandbox(); | |
s.run(` | |
${testCallStack.toString()}; | |
${tryThrow.toString()}; | |
tryThrow(); | |
`) | |
s.run(` | |
${testCallStack.toString()}; | |
${tryThrow.toString()}; | |
${tryOutput.toString()}; | |
tryOutput(); | |
`) | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment