13ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Copyright 2011 the V8 project authors. All rights reserved. 23ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Redistribution and use in source and binary forms, with or without 33ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// modification, are permitted provided that the following conditions are 43ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// met: 53ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// 63ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// * Redistributions of source code must retain the above copyright 73ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// notice, this list of conditions and the following disclaimer. 83ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// * Redistributions in binary form must reproduce the above 93ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// copyright notice, this list of conditions and the following 103ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// disclaimer in the documentation and/or other materials provided 113ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// with the distribution. 123ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// * Neither the name of Google Inc. nor the names of its 133ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// contributors may be used to endorse or promote products derived 143ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// from this software without specific prior written permission. 153ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// 163ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 283ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Test that redefining the 'prototype' property of a function object 293ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// does actually set the internal value and does not screw up any 303ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// shadowing between said property and the internal value. 313ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 323ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochvar f = function() {}; 333ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 343ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Verify that normal assignment of 'prototype' property works properly 353ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// and updates the internal value. 363ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochvar x = { foo: 'bar' }; 373ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochf.prototype = x; 383ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(f.prototype, x); 393ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(f.prototype.foo, 'bar'); 403ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(new f().foo, 'bar'); 413ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(Object.getPrototypeOf(new f()), x); 423ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(Object.getOwnPropertyDescriptor(f, 'prototype').value, x); 433ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 443ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Verify that 'prototype' behaves like a data property when it comes to 453ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// redefining with Object.defineProperty() and the internal value gets 463ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// updated. 473ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochvar y = { foo: 'baz' }; 483ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochObject.defineProperty(f, 'prototype', { value: y, writable: true }); 493ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(f.prototype, y); 503ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(f.prototype.foo, 'baz'); 513ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(new f().foo, 'baz'); 523ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(Object.getPrototypeOf(new f()), y); 533ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(Object.getOwnPropertyDescriptor(f, 'prototype').value, y); 543ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 553ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Verify that the previous redefinition didn't screw up callbacks and 563ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// the internal value still gets updated. 573ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochvar z = { foo: 'other' }; 583ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochf.prototype = z; 593ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(f.prototype, z); 603ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(f.prototype.foo, 'other'); 613ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(new f().foo, 'other'); 623ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(Object.getPrototypeOf(new f()), z); 633ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertSame(Object.getOwnPropertyDescriptor(f, 'prototype').value, z); 643ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch 653ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Verify that non-writability of other properties is respected. 663ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertThrows("Object.defineProperty(f, 'name', { value: {} })"); 673ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertThrows("Object.defineProperty(f, 'length', { value: {} })"); 683ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertThrows("Object.defineProperty(f, 'caller', { value: {} })"); 693ef787dbeca8a5fb1086949cda830dccee07bfbdBen MurdochassertThrows("Object.defineProperty(f, 'arguments', { value: {} })"); 70