-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests verifying errors from ShadowRealms evaluation
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
test/built-ins/ShadowRealm/prototype/evaluate/no-conditional-strict-mode.js
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
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); |
30 changes: 30 additions & 0 deletions
30
test/built-ins/ShadowRealm/prototype/evaluate/throws-syntaxerror-on-bad-syntax.js
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
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'); |