mirror of https://github.com/tc39/test262.git
Add more tests verifying errors from ShadowRealms evaluation
This commit is contained in:
parent
61bd4e9453
commit
49819bc0bc
|
@ -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');
|
||||
|
|
|
@ -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
test/built-ins/ShadowRealm/prototype/evaluate/throws-syntaxerror-on-bad-syntax.js
vendored
Normal file
30
test/built-ins/ShadowRealm/prototype/evaluate/throws-syntaxerror-on-bad-syntax.js
vendored
Normal 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');
|
Loading…
Reference in New Issue