blob: 182eb4da771837b08b0a74abd20c3c223cfdc11e [file] [log] [blame]
Iain Merrick75681382010-08-19 15:07:18 +01001// Copyright 2010 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28var x = {};
29
30// Add property a with getter/setter.
31x.__defineGetter__("a", function() {
32 try {
33 y.x = 40;
34 } catch (e) {
Ben Murdoch589d6972011-11-30 16:04:58 +000035 assertEquals(3, e.stack.split('\n').length);
Iain Merrick75681382010-08-19 15:07:18 +010036 }
37 return 40;
38});
39
40x.__defineSetter__("a", function(val) {
41 try {
42 y.x = 40;
43 } catch(e) {
Ben Murdoch589d6972011-11-30 16:04:58 +000044 assertEquals(3, e.stack.split('\n').length);
Iain Merrick75681382010-08-19 15:07:18 +010045 }
46});
47
48// Add property b with getter/setter.
49function getB() {
50 try {
51 y.x = 30;
52 } catch (e) {
Ben Murdoch589d6972011-11-30 16:04:58 +000053 assertEquals(3, e.stack.split('\n').length);
Iain Merrick75681382010-08-19 15:07:18 +010054 }
55 return 30;
56}
57
58function setB(val) {
59 try {
60 y.x = 30;
61 } catch(e) {
Ben Murdoch589d6972011-11-30 16:04:58 +000062 assertEquals(3, e.stack.split('\n').length);
Iain Merrick75681382010-08-19 15:07:18 +010063 }
64}
65
66x.__defineGetter__("b", getB);
67x.__defineSetter__("b", setB);
68
69// Add property c with getter/setter.
70var descriptor = {
71 get: function() {
72 try {
73 y.x = 40;
74 } catch (e) {
Ben Murdoch589d6972011-11-30 16:04:58 +000075 assertEquals(3, e.stack.split('\n').length);
Iain Merrick75681382010-08-19 15:07:18 +010076 }
77 return 40;
78 },
79 set: function(val) {
80 try {
81 y.x = 40;
82 } catch(e) {
Ben Murdoch589d6972011-11-30 16:04:58 +000083 assertEquals(3, e.stack.split('\n').length);
Iain Merrick75681382010-08-19 15:07:18 +010084 }
85 }
86}
87
88Object.defineProperty(x, 'c', descriptor)
89
90// Check that the stack for an exception in a getter and setter produce the
Ben Murdoch589d6972011-11-30 16:04:58 +000091// expected stack height.
Iain Merrick75681382010-08-19 15:07:18 +010092x.a;
93x.b;
94x.c;
95x.a = 1;
96x.b = 1;
97x.c = 1;
98
99// Do the same with the getters/setters on the a prototype object.
100xx = {}
101xx.__proto__ = x
102
103xx.a;
104xx.b;
105xx.c;
106xx.a = 1;
107xx.b = 1;
108xx.c = 1;