Add more tests verifying errors from ShadowRealms evaluation

This commit is contained in:
Leo Balter 2021-09-21 13:59:46 -07:00 committed by Rick Waldron
parent 61bd4e9453
commit 49819bc0bc
3 changed files with 69 additions and 0 deletions

View File

@ -19,3 +19,8 @@ assert.throws(SyntaxError, () => r.evaluate('...'), 'SyntaxError exposed to Pare
assert.throws(TypeError, () => r.evaluate('throw 42'), 'throw primitive => TypeError');
assert.throws(TypeError, () => r.evaluate('throw new ReferenceError("aaa")'), 'custom ctor => TypeError');
assert.throws(TypeError, () => r.evaluate('throw new TypeError("aaa")'), 'Child TypeError => Parent TypeError');
assert.throws(TypeError, () => r.evaluate('eval("...");'), 'syntaxerror parsing coming after runtime evaluation');
assert.throws(TypeError, () => r.evaluate(`
'use strict';
eval("var public = 1;");
`), 'strict-mode only syntaxerror parsing coming after runtime evaluation');

View File

@ -0,0 +1,34 @@
// Copyright (C) 2021 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-shadowrealm.prototype.evaluate
description: >
The new realm has no conditional strict mode based on its outer realm
info: |
This test should always run with the outer realm in both strict and non
strict mode to verify the realm code starts in non-strict mode.
features: [ShadowRealm]
---*/
assert.sameValue(
typeof ShadowRealm.prototype.evaluate,
'function',
'This test must fail if ShadowRealm.prototype.evaluate is not a function'
);
const r = new ShadowRealm();
const res = r.evaluate(`
function lol() {
arguments = 42; // This would be a SyntaxError if in strict mode
return arguments;
}
lol;
`);
assert.sameValue(res(), 42);
const res2 = r.evaluate('var public = 1; 42');
assert.sameValue(res2, 42);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2021 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-shadowrealm.prototype.evaluate
description: >
ShadowRealm.prototype.evaluate throws a SyntaxError if the syntax can't be parsed
features: [ShadowRealm]
---*/
assert.sameValue(
typeof ShadowRealm.prototype.evaluate,
'function',
'This test must fail if ShadowRealm.prototype.evaluate is not a function'
);
const r = new ShadowRealm();
assert.throws(SyntaxError, () => r.evaluate('...'), 'SyntaxError exposed to Parent');
assert.throws(SyntaxError, () => r.evaluate(`
"use strict";
throw "do not evaluate";
function lol(){
arguments = 1;
}
`), 'Strict mode only SyntaxError, setting value to a fn arguments');
assert.throws(SyntaxError, () => r.evaluate(`
"use strict";
throw "do not evaluate";
var public = 1;
`), 'Strict mode only SyntaxError, var public');