Last active
April 3, 2019 19:20
-
-
Save mikesamuel/5c71584fc10a603167111e933cdc650d to your computer and use it in GitHub Desktop.
Informal tests for augmented HostEnsureCanCompileStrings
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
// 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