1402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Copyright 2010 the V8 project authors. All rights reserved. 2402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Redistribution and use in source and binary forms, with or without 3402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// modification, are permitted provided that the following conditions are 4402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// met: 5402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// 6402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// * Redistributions of source code must retain the above copyright 7402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// notice, this list of conditions and the following disclaimer. 8402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// * Redistributions in binary form must reproduce the above 9402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// copyright notice, this list of conditions and the following 10402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// disclaimer in the documentation and/or other materials provided 11402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// with the distribution. 12402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// * Neither the name of Google Inc. nor the names of its 13402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// contributors may be used to endorse or promote products derived 14402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// from this software without specific prior written permission. 15402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// 16402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 28402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Simple class using inline constructor. 29402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescufunction C1() { 30402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu this.x = 23; 31402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu}; 32402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescuvar c1 = new C1(); 33402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals(23, c1.x); 34402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals("undefined", typeof c1.y); 35589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch 36402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Add setter somewhere on the prototype chain after having constructed the 37402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// first instance. 38402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuC1.prototype = { set x(value) { this.y = 23; } }; 39402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescuvar c1 = new C1(); 40402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals("undefined", typeof c1.x); 41402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals(23, c1.y); 42589d6979ff2ef66fca2d8fa51404c369ca5e9250Ben Murdoch 43402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Simple class using inline constructor. 44402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescufunction C2() { 45402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu this.x = 23; 46402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu}; 47402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescuvar c2 = new C2(); 48402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals(23, c2.x); 49402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals("undefined", typeof c2.y); 50402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 51402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Add setter somewhere on the prototype chain after having constructed the 52402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// first instance. 53402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuC2.prototype.__proto__ = { set x(value) { this.y = 23; } }; 54402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescuvar c2 = new C2(); 55402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals("undefined", typeof c2.x); 56402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals(23, c2.y); 57402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 58402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Simple class using inline constructor. 59402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescufunction C3() { 60402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu this.x = 23; 61402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu}; 62402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescuvar c3 = new C3(); 63402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals(23, c3.x); 64402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals("undefined", typeof c3.y); 65402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 66402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Add setter somewhere on the prototype chain after having constructed the 67402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// first instance. 68402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuC3.prototype.__defineSetter__('x', function(value) { this.y = 23; }); 69402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescuvar c3 = new C3(); 70402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals("undefined", typeof c3.x); 71402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals(23, c3.y); 72402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 73402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Simple class using inline constructor. 74402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescufunction C4() { 75402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu this.x = 23; 76402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu}; 77402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescuvar c4 = new C4(); 78402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals(23, c4.x); 79402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals("undefined", typeof c4.y); 80402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 81402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// Add setter somewhere on the prototype chain after having constructed the 82402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu// first instance. 83402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuC4.prototype.__proto__.__defineSetter__('x', function(value) { this.y = 23; }); 84402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescuvar c4 = new C4(); 85402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals("undefined", typeof c4.x); 86402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei PopescuassertEquals(23, c4.y); 87