1add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// Copyright 2011 the V8 project authors. All rights reserved. 2add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// Redistribution and use in source and binary forms, with or without 3add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// modification, are permitted provided that the following conditions are 4add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// met: 5add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// 6add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// * Redistributions of source code must retain the above copyright 7add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// notice, this list of conditions and the following disclaimer. 8add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// * Redistributions in binary form must reproduce the above 9add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// copyright notice, this list of conditions and the following 10add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// disclaimer in the documentation and/or other materials provided 11add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// with the distribution. 12add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// * Neither the name of Google Inc. nor the names of its 13add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// contributors may be used to endorse or promote products derived 14add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// from this software without specific prior written permission. 15add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// 16add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19fed16d043a14e8b86c97a6413aec7281fefcbcb5srs// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2224bba6e4f3a57cd8b4812c1976190356919d9c47Roderick W. Smith// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263488294d718a0e8b7f312c80c9e5729671173f6asrs// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs 28bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs// Test that using bind several time does not change the length of existing 29bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs// bound functions. 30bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs 31bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrsfunction foo() { 32add79a6e1b3a1af1305f02d51eb3aa148f580caasrs} 33add79a6e1b3a1af1305f02d51eb3aa148f580caasrs 34add79a6e1b3a1af1305f02d51eb3aa148f580caasrsvar f1 = function (x) {}.bind(foo); 35add79a6e1b3a1af1305f02d51eb3aa148f580caasrsvar f2 = function () {}; 36add79a6e1b3a1af1305f02d51eb3aa148f580caasrs 37add79a6e1b3a1af1305f02d51eb3aa148f580caasrsassertEquals(1, f1.length); 38add79a6e1b3a1af1305f02d51eb3aa148f580caasrs 39add79a6e1b3a1af1305f02d51eb3aa148f580caasrs// the object we bind to can be any object 40add79a6e1b3a1af1305f02d51eb3aa148f580caasrsf2.bind(foo); 41add79a6e1b3a1af1305f02d51eb3aa148f580caasrs 42add79a6e1b3a1af1305f02d51eb3aa148f580caasrsassertEquals(1, f1.length); 43add79a6e1b3a1af1305f02d51eb3aa148f580caasrs 4455d926192adc984462509b2966e23bc0d1129bbdsrsvar desc = Object.getOwnPropertyDescriptor(f1, 'length'); 4555d926192adc984462509b2966e23bc0d1129bbdsrsassertEquals(false, desc.writable); 4655d926192adc984462509b2966e23bc0d1129bbdsrsassertEquals(false, desc.enumerable); 47add79a6e1b3a1af1305f02d51eb3aa148f580caasrsassertEquals(true, desc.configurable); 48add79a6e1b3a1af1305f02d51eb3aa148f580caasrs 498f1b2d6edcb4ab45c8cf80c6e58c5c776d2e550esrsObject.defineProperty(f1, 'length', { 50add79a6e1b3a1af1305f02d51eb3aa148f580caasrs value: 'abc', 51add79a6e1b3a1af1305f02d51eb3aa148f580caasrs writable: true 52add79a6e1b3a1af1305f02d51eb3aa148f580caasrs}); 53add79a6e1b3a1af1305f02d51eb3aa148f580caasrsassertEquals('abc', f1.length); 54add79a6e1b3a1af1305f02d51eb3aa148f580caasrsf1.length = 42; 55add79a6e1b3a1af1305f02d51eb3aa148f580caasrsassertEquals(42, f1.length); 56add79a6e1b3a1af1305f02d51eb3aa148f580caasrs