Skip to content

Instantly share code, notes, and snippets.

@yorickvP
Created May 17, 2016 21:22
Show Gist options
  • Save yorickvP/f3b5cf3f97f65f05c9ad5b94a6716098 to your computer and use it in GitHub Desktop.
Save yorickvP/f3b5cf3f97f65f05c9ad5b94a6716098 to your computer and use it in GitHub Desktop.
testcase for gf3/sandbox
/* 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