test262/implementation-contributed/javascriptcore/stress/exception-in-to-property-key-should-be-handled-early-in-object-methods.js
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

74 lines
2.1 KiB
JavaScript

var propertyKey = {
toString() {
throw new Error("propertyKey.toString is called.");
}
};
function shouldThrow(func, message) {
var error = null;
try {
func();
} catch (e) {
error = e;
}
if (!error)
throw new Error("not thrown.");
if (String(error) !== message)
throw new Error("bad error: " + String(error));
}
var object = {};
shouldThrow(function () {
object.hasOwnProperty(propertyKey);
}, "Error: propertyKey.toString is called.");
shouldThrow(function () {
Object.prototype.hasOwnProperty.call(null, propertyKey);
}, "Error: propertyKey.toString is called.");
shouldThrow(function () {
Object.prototype.hasOwnProperty.call(null, 'ok');
}, "TypeError: null is not an object (evaluating 'Object.prototype.hasOwnProperty.call(null, 'ok')')");
shouldThrow(function () {
object.propertyIsEnumerable(propertyKey);
}, "Error: propertyKey.toString is called.");
// ToPropertyKey is first, ToObject is following.
shouldThrow(function () {
Object.prototype.propertyIsEnumerable.call(null, propertyKey);
}, "Error: propertyKey.toString is called.");
shouldThrow(function () {
// ToPropertyKey is first, ToObject is following.
Object.prototype.propertyIsEnumerable.call(null, 'ok');
}, "TypeError: null is not an object (evaluating 'Object.prototype.propertyIsEnumerable.call(null, 'ok')')");
shouldThrow(function () {
object.__defineGetter__(propertyKey, function () {
return 'NG';
});
}, "Error: propertyKey.toString is called.");
if (Object.getOwnPropertyDescriptor(object, ''))
throw new Error("bad descriptor");
shouldThrow(function () {
object.__defineSetter__(propertyKey, function () {
return 'NG';
});
}, "Error: propertyKey.toString is called.");
if (Object.getOwnPropertyDescriptor(object, ''))
throw new Error("bad descriptor");
shouldThrow(function () {
object.__lookupGetter__(propertyKey);
}, "Error: propertyKey.toString is called.");
shouldThrow(function () {
object.__lookupSetter__(propertyKey);
}, "Error: propertyKey.toString is called.");