mirror of
https://github.com/tc39/test262.git
synced 2025-07-27 07:54:41 +02:00
Move completesNormally and raisesException to non262-strict-shell.js
This commit is contained in:
parent
1b63fba5ca
commit
e0f3a70c5a
@ -5,43 +5,13 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
defines: [completesNormally, raisesException, deepEqual, makeIterator, Permutations, assertThrowsValue, assertThrownErrorContains, assertThrowsInstanceOfWithMessageCheck, assertThrowsInstanceOf, assertThrowsInstanceOfWithMessage, assertThrowsInstanceOfWithMessageContains, assertDeepEq]
|
defines: [makeIterator, Permutations, assertThrowsValue, assertThrownErrorContains, assertThrowsInstanceOfWithMessageCheck, assertThrowsInstanceOf, assertThrowsInstanceOfWithMessage, assertThrowsInstanceOfWithMessageContains, assertDeepEq]
|
||||||
allow_unused: True
|
allow_unused: True
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
const undefined = void 0;
|
const undefined = void 0;
|
||||||
|
|
||||||
/*
|
|
||||||
* completesNormally(CODE) returns true if evaluating CODE (as eval
|
|
||||||
* code) completes normally (rather than throwing an exception).
|
|
||||||
*/
|
|
||||||
globalThis.completesNormally = function completesNormally(code) {
|
|
||||||
try {
|
|
||||||
eval(code);
|
|
||||||
return true;
|
|
||||||
} catch (exception) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* raisesException(EXCEPTION)(CODE) returns true if evaluating CODE (as
|
|
||||||
* eval code) throws an exception object that is an instance of EXCEPTION,
|
|
||||||
* and returns false if it throws any other error or evaluates
|
|
||||||
* successfully. For example: raises(TypeError)("0()") == true.
|
|
||||||
*/
|
|
||||||
globalThis.raisesException = function raisesException(exception) {
|
|
||||||
return function (code) {
|
|
||||||
try {
|
|
||||||
eval(code);
|
|
||||||
return false;
|
|
||||||
} catch (actual) {
|
|
||||||
return actual instanceof exception;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Make an iterator with a return method. */
|
/** Make an iterator with a return method. */
|
||||||
globalThis.makeIterator = function makeIterator(overrides) {
|
globalThis.makeIterator = function makeIterator(overrides) {
|
||||||
var throwMethod;
|
var throwMethod;
|
||||||
|
@ -5,11 +5,41 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
defines: [testLenientAndStrict, parsesSuccessfully, parseRaisesException, returns]
|
defines: [completesNormally, raisesException, testLenientAndStrict, parsesSuccessfully, parseRaisesException, returns]
|
||||||
allow_unused: True
|
allow_unused: True
|
||||||
---*/
|
---*/
|
||||||
(function(global) {
|
(function(global) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* completesNormally(CODE) returns true if evaluating CODE (as eval
|
||||||
|
* code) completes normally (rather than throwing an exception).
|
||||||
|
*/
|
||||||
|
globalThis.completesNormally = function completesNormally(code) {
|
||||||
|
try {
|
||||||
|
eval(code);
|
||||||
|
return true;
|
||||||
|
} catch (exception) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* raisesException(EXCEPTION)(CODE) returns true if evaluating CODE (as
|
||||||
|
* eval code) throws an exception object that is an instance of EXCEPTION,
|
||||||
|
* and returns false if it throws any other error or evaluates
|
||||||
|
* successfully. For example: raises(TypeError)("0()") == true.
|
||||||
|
*/
|
||||||
|
globalThis.raisesException = function raisesException(exception) {
|
||||||
|
return function (code) {
|
||||||
|
try {
|
||||||
|
eval(code);
|
||||||
|
return false;
|
||||||
|
} catch (actual) {
|
||||||
|
return actual instanceof exception;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return true if both of these return true:
|
* Return true if both of these return true:
|
||||||
* - LENIENT_PRED applied to CODE
|
* - LENIENT_PRED applied to CODE
|
||||||
|
@ -4,21 +4,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
includes: [sm/non262.js, sm/non262-shell.js]
|
|
||||||
flags:
|
|
||||||
- noStrict
|
|
||||||
description: |
|
description: |
|
||||||
pending
|
pending
|
||||||
esid: pending
|
esid: pending
|
||||||
---*/
|
---*/
|
||||||
assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call(42)'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call("")'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call({})'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call(null)'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call([])'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call(undefined)'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call(new String())'), true);
|
|
||||||
|
|
||||||
assert.sameValue(completesNormally('Boolean.prototype.toString.call(true)'), true);
|
assert.throws(TypeError, function() { Boolean.prototype.toString.call(42); });
|
||||||
assert.sameValue(completesNormally('Boolean.prototype.toString.call(new Boolean(true))'), true);
|
assert.throws(TypeError, function() { Boolean.prototype.toString.call(""); });
|
||||||
|
assert.throws(TypeError, function() { Boolean.prototype.toString.call({}); });
|
||||||
|
assert.throws(TypeError, function() { Boolean.prototype.toString.call(null); });
|
||||||
|
assert.throws(TypeError, function() { Boolean.prototype.toString.call([]); });
|
||||||
|
assert.throws(TypeError, function() { Boolean.prototype.toString.call(undefined); });
|
||||||
|
assert.throws(TypeError, function() { Boolean.prototype.toString.call(new String()); });
|
||||||
|
|
||||||
|
assert.sameValue(Boolean.prototype.toString.call(true), "true");
|
||||||
|
assert.sameValue(Boolean.prototype.toString.call(new Boolean(true)), "true");
|
||||||
|
@ -4,23 +4,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
includes: [sm/non262.js, sm/non262-shell.js]
|
|
||||||
flags:
|
|
||||||
- noStrict
|
|
||||||
description: |
|
description: |
|
||||||
pending
|
pending
|
||||||
esid: pending
|
esid: pending
|
||||||
---*/
|
---*/
|
||||||
assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call(true)'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call("")'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call({})'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call(null)'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call([])'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call(undefined)'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call(new Boolean(true))'), true);
|
|
||||||
|
|
||||||
assert.sameValue(completesNormally('Number.prototype.toString.call(42)'), true);
|
assert.throws(TypeError, function() { Number.prototype.toString.call(true); });
|
||||||
assert.sameValue(completesNormally('Number.prototype.toString.call(new Number(42))'), true);
|
assert.throws(TypeError, function() { Number.prototype.toString.call(""); });
|
||||||
|
assert.throws(TypeError, function() { Number.prototype.toString.call({}); });
|
||||||
|
assert.throws(TypeError, function() { Number.prototype.toString.call(null); });
|
||||||
|
assert.throws(TypeError, function() { Number.prototype.toString.call([]); });
|
||||||
|
assert.throws(TypeError, function() { Number.prototype.toString.call(undefined); });
|
||||||
|
assert.throws(TypeError, function() { Number.prototype.toString.call(new Boolean(true)); });
|
||||||
|
|
||||||
|
assert.sameValue(Number.prototype.toString.call(42), "42");
|
||||||
|
assert.sameValue(Number.prototype.toString.call(new Number(42)), "42");
|
||||||
|
|
||||||
function testAround(middle)
|
function testAround(middle)
|
||||||
{
|
{
|
||||||
|
@ -4,18 +4,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
includes: [sm/non262.js, sm/non262-shell.js, sm/non262-String-shell.js]
|
|
||||||
flags:
|
|
||||||
- noStrict
|
|
||||||
description: |
|
description: |
|
||||||
pending
|
pending
|
||||||
esid: pending
|
esid: pending
|
||||||
---*/
|
---*/
|
||||||
assert.sameValue(raisesException(TypeError)('String.prototype.toString.call(42)'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('String.prototype.toString.call(true)'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('String.prototype.toString.call({})'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('String.prototype.toString.call(null)'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('String.prototype.toString.call([])'), true);
|
|
||||||
assert.sameValue(raisesException(TypeError)('String.prototype.toString.call(undefined)'), true);
|
|
||||||
assert.sameValue(completesNormally('String.prototype.toString.call("")'), true);
|
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() { String.prototype.toString.call(42); });
|
||||||
|
assert.throws(TypeError, function() { String.prototype.toString.call(true); });
|
||||||
|
assert.throws(TypeError, function() { String.prototype.toString.call({}); });
|
||||||
|
assert.throws(TypeError, function() { String.prototype.toString.call(null); });
|
||||||
|
assert.throws(TypeError, function() { String.prototype.toString.call([]); });
|
||||||
|
assert.throws(TypeError, function() { String.prototype.toString.call(undefined); });
|
||||||
|
assert.sameValue(String.prototype.toString.call(""), "");
|
||||||
|
@ -26,11 +26,11 @@ function test()
|
|||||||
printStatus(summary);
|
printStatus(summary);
|
||||||
|
|
||||||
let testAwaitInDefaultExprOfAsyncFunc = (code) => {
|
let testAwaitInDefaultExprOfAsyncFunc = (code) => {
|
||||||
assertThrowsInstanceOf(() => eval(code), SyntaxError, "await expression can't be used in parameter");
|
assert.throws(SyntaxError, () => eval(code), "await expression can't be used in parameter");
|
||||||
};
|
};
|
||||||
|
|
||||||
let testNoException = (code) => {
|
let testNoException = (code) => {
|
||||||
assert.sameValue(completesNormally(code), true);
|
eval(code);
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://www.ecma-international.org/ecma-262/9.0/
|
// https://www.ecma-international.org/ecma-262/9.0/
|
||||||
|
@ -2,13 +2,11 @@
|
|||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
includes: [sm/non262.js, sm/non262-shell.js]
|
|
||||||
flags:
|
|
||||||
- noStrict
|
|
||||||
description: |
|
description: |
|
||||||
pending
|
pending
|
||||||
esid: pending
|
esid: pending
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
var await = 1;
|
var await = 1;
|
||||||
|
|
||||||
async function getClass() {
|
async function getClass() {
|
||||||
@ -21,11 +19,10 @@ getClass().then(cl => {
|
|||||||
assert.sameValue(new cl().x, 1);
|
assert.sameValue(new cl().x, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.sameValue(raisesException(SyntaxError)(`
|
assert.throws(SyntaxError, function() {
|
||||||
async () => class { [await] = 1 };
|
eval("async () => class { [await] = 1 };");
|
||||||
`), true);
|
});
|
||||||
|
|
||||||
assert.sameValue(raisesException(SyntaxError)(`
|
|
||||||
async () => class { x = await 1 };
|
|
||||||
`), true);
|
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
eval("async () => class { x = await 1 };");
|
||||||
|
});
|
||||||
|
@ -2,13 +2,11 @@
|
|||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
includes: [sm/non262.js, sm/non262-shell.js]
|
|
||||||
flags:
|
|
||||||
- noStrict
|
|
||||||
description: |
|
description: |
|
||||||
pending
|
pending
|
||||||
esid: pending
|
esid: pending
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
// Don't Crash
|
// Don't Crash
|
||||||
var testStr = `
|
var testStr = `
|
||||||
class C extends Object {
|
class C extends Object {
|
||||||
@ -20,5 +18,8 @@ class C extends Object {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
new C;`
|
new C;`
|
||||||
assert.sameValue(raisesException(ReferenceError)(testStr), true);
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
eval(testStr);
|
||||||
|
});
|
||||||
|
|
||||||
|
@ -4,18 +4,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
includes: [sm/non262.js, sm/non262-strict-shell.js, sm/non262-shell.js]
|
|
||||||
flags:
|
|
||||||
- noStrict
|
|
||||||
description: |
|
description: |
|
||||||
pending
|
pending
|
||||||
esid: pending
|
esid: pending
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
/* Check that assignment to a let-bound variable is permitted in both lenient and strict modes. */
|
/* Check that assignment to a let-bound variable is permitted in both lenient and strict modes. */
|
||||||
|
|
||||||
/* Assigning to a let-declared variable is okay in strict and loose modes. */
|
/* Assigning to a let-declared variable is okay in strict and loose modes. */
|
||||||
assert.sameValue(testLenientAndStrict('let let_declared; let_declared=1',
|
let let_declared;
|
||||||
completesNormally,
|
let_declared = 1;
|
||||||
completesNormally),
|
|
||||||
true);
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user