Skip to content

Commit

Permalink
Add more tests verifying errors from ShadowRealms evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
leobalter authored and rwaldron committed Sep 22, 2021
1 parent 61bd4e9 commit 49819bc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 49819bc

Please sign in to comment.