Skip to content

Instantly share code, notes, and snippets.

@mikesamuel
Last active April 3, 2019 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikesamuel/5c71584fc10a603167111e933cdc650d to your computer and use it in GitHub Desktop.
Save mikesamuel/5c71584fc10a603167111e933cdc650d to your computer and use it in GitHub Desktop.
Informal tests for augmented HostEnsureCanCompileStrings
// Run in the context of a HostEnsureCanCompileStrings callout that
// throws an EvalError (from the callee realm) for string values, and
// arrays.
const PASS = {}, FAIL = {};
function tryCompileAsFunctionBody(description, source, expectedStatus) {
let status = FAIL;
try {
new Function(source);
status = PASS;
} catch (ex) {
if (!(ex instanceof EvalError)) {
$ERROR(`Function host check failed with unexpected error type: ${ description }`);
return;
}
if (status !== expectedStatus) {
$ERROR(
expectedStatus === PASS
? `Function() host check should not have failed: ${ description }`
: `Function () host check should not have passed: ${ description }`
);
}
}
}
tryCompileAsFunctionBody('raw string value', '/*string*/', FAIL);
tryCompileAsFunctionBody('object', { toString() { return '/*object*/' } }, PASS);
tryCompileAsFunctionBody('array', '[ "/*array*/" ]', FAIL);
// TODO: call from another realm to test callee vs caller realms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment