]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/exception-in-to-property-key-should-be-handled-early-in-object-methods.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / exception-in-to-property-key-should-be-handled-early-in-object-methods.js
CommitLineData
ed1e77d3
A
1
2var propertyKey = {
3 toString() {
4 throw new Error("propertyKey.toString is called.");
5 }
6};
7
8function shouldThrow(func, message) {
9 var error = null;
10 try {
11 func();
12 } catch (e) {
13 error = e;
14 }
15 if (!error)
16 throw new Error("not thrown.");
17 if (String(error) !== message)
18 throw new Error("bad error: " + String(error));
19}
20
21var object = {};
22
23shouldThrow(function () {
24 object.hasOwnProperty(propertyKey);
25}, "Error: propertyKey.toString is called.");
26
27shouldThrow(function () {
28 Object.prototype.hasOwnProperty.call(null, propertyKey);
29}, "Error: propertyKey.toString is called.");
30
31shouldThrow(function () {
32 Object.prototype.hasOwnProperty.call(null, 'ok');
33}, "TypeError: null is not an object (evaluating 'Object.prototype.hasOwnProperty.call(null, 'ok')')");
34
35shouldThrow(function () {
36 object.propertyIsEnumerable(propertyKey);
37}, "Error: propertyKey.toString is called.");
38
39// ToPropertyKey is first, ToObject is following.
40shouldThrow(function () {
41 Object.prototype.propertyIsEnumerable.call(null, propertyKey);
42}, "Error: propertyKey.toString is called.");
43
44shouldThrow(function () {
45 // ToPropertyKey is first, ToObject is following.
46 Object.prototype.propertyIsEnumerable.call(null, 'ok');
47}, "TypeError: null is not an object (evaluating 'Object.prototype.propertyIsEnumerable.call(null, 'ok')')");
48
49shouldThrow(function () {
50 object.__defineGetter__(propertyKey, function () {
51 return 'NG';
52 });
53}, "Error: propertyKey.toString is called.");
54
55if (Object.getOwnPropertyDescriptor(object, ''))
56 throw new Error("bad descriptor");
57
58shouldThrow(function () {
59 object.__defineSetter__(propertyKey, function () {
60 return 'NG';
61 });
62}, "Error: propertyKey.toString is called.");
63
64if (Object.getOwnPropertyDescriptor(object, ''))
65 throw new Error("bad descriptor");
66
67shouldThrow(function () {
68 object.__lookupGetter__(propertyKey);
69}, "Error: propertyKey.toString is called.");
70
71shouldThrow(function () {
72 object.__lookupSetter__(propertyKey);
73}, "Error: propertyKey.toString is called.");