test262-automation e9a5a7f918 [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) (#1620)
* [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)
2018-07-03 15:59:58 -04:00

80 lines
2.2 KiB
JavaScript

"use strict";
function assert(b) {
if (!b)
throw new Error("Bad assertion");
}
function shouldNotThrow(expr) {
let testFunc = new Function(expr);
let error;
try {
testFunc();
} catch (e) {
error = e;
}
assert(!error);
}
function checkEmptyErrorPropertiesDescriptors(error) {
let descriptor = Object.getOwnPropertyDescriptor(error, "message");
assert(descriptor === undefined);
}
function checkNonEmptyErrorPropertiesDescriptors(error) {
let descriptor = Object.getOwnPropertyDescriptor(error, "message");
assert(descriptor.configurable);
assert(!descriptor.enumerable);
assert(descriptor.writable);
}
function checkErrorPropertiesWritable(error) {
let properties = ["name", "message", "line", "lineNumber", "column", "columnNumber", "sourceURL", "stack"];
for (let p of properties) {
assert(error[p] !== 999);
error[p] = 999;
assert(error[p] === 999);
}
}
// User created error instances.
let errorConstructors = [Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError];
for (let constructor of errorConstructors) {
shouldNotThrow(`checkErrorPropertiesWritable(new ${constructor.name})`);
shouldNotThrow(`checkEmptyErrorPropertiesDescriptors(new ${constructor.name})`);
shouldNotThrow(`checkNonEmptyErrorPropertiesDescriptors(new ${constructor.name}('message'))`);
}
// Engine created error instances.
var globalError = null;
try {
eval("{");
} catch (e) {
globalError = e;
assert(e.name === "SyntaxError");
assert(e.message.length);
shouldNotThrow("checkNonEmptyErrorPropertiesDescriptors(globalError)");
shouldNotThrow("checkErrorPropertiesWritable(globalError)");
}
try {
a.b.c;
} catch (e) {
globalError = e;
assert(e.name === "ReferenceError");
assert(e.message.length);
shouldNotThrow("checkNonEmptyErrorPropertiesDescriptors(globalError)");
shouldNotThrow("checkErrorPropertiesWritable(globalError)");
}
try {
undefined.x;
} catch (e) {
globalError = e;
assert(e.name === "TypeError");
assert(e.message.length);
shouldNotThrow("checkNonEmptyErrorPropertiesDescriptors(globalError)");
shouldNotThrow("checkErrorPropertiesWritable(globalError)");
}