mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 14:30:27 +02:00
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
function shouldThrow(func, errorMessage) {
|
|
var errorThrown = false;
|
|
var error = null;
|
|
try {
|
|
func();
|
|
} catch (e) {
|
|
errorThrown = true;
|
|
error = e;
|
|
}
|
|
if (!errorThrown)
|
|
throw new Error('not thrown');
|
|
if (String(error) !== errorMessage)
|
|
throw new Error(`bad error: ${String(error)}`);
|
|
}
|
|
|
|
var symbol = Symbol("Cocoa");
|
|
|
|
shouldThrow(() => {
|
|
// ToString => error.
|
|
"" + symbol;
|
|
}, `TypeError: Cannot convert a symbol to a string`);
|
|
|
|
shouldThrow(() => {
|
|
// ToNumber => error.
|
|
+symbol;
|
|
}, `TypeError: Cannot convert a symbol to a number`);
|
|
|
|
shouldThrow(() => {
|
|
Symbol.keyFor("Cappuccino");
|
|
}, `TypeError: Symbol.keyFor requires that the first argument be a symbol`);
|
|
|
|
shouldThrow(() => {
|
|
Symbol.prototype.toString.call(null);
|
|
}, `TypeError: Symbol.prototype.toString requires that |this| be a symbol or a symbol object`);
|
|
|
|
shouldThrow(() => {
|
|
Symbol.prototype.toString.call({});
|
|
}, `TypeError: Symbol.prototype.toString requires that |this| be a symbol or a symbol object`);
|
|
|
|
shouldThrow(() => {
|
|
Symbol.prototype.valueOf.call(null);
|
|
}, `TypeError: Symbol.prototype.valueOf requires that |this| be a symbol or a symbol object`);
|
|
|
|
shouldThrow(() => {
|
|
Symbol.prototype.valueOf.call({});
|
|
}, `TypeError: Symbol.prototype.valueOf requires that |this| be a symbol or a symbol object`);
|