Home | History | Annotate | Download | only in bugs
      1 // Copyright 2008 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 
     28 // This test fails because we copy the arguments array on indirect
     29 // access
     30 
     31 function g(f) {
     32   assertEquals(100, f.arguments = 100);  // read-only
     33   assertEquals(3, f.arguments.length);
     34   assertEquals(1, f.arguments[0]);
     35   assertEquals(2, f.arguments[1]);
     36   assertEquals(3, f.arguments[2]);
     37   f.arguments[0] = 999;
     38   f.arguments.extra = 'kallevip';
     39 }
     40 
     41 function h(f) {
     42   assertEquals('kallevip', f.arguments.extra);
     43   return f.arguments;
     44 }
     45 
     46 // Test function with a materialized arguments array.
     47 function f0() {
     48   g(f0);
     49   var result = h(f0);
     50   var a = arguments;
     51   assertEquals(999, a[0]);
     52   return result;
     53 }
     54 
     55 
     56 // Test function without a materialized arguments array.
     57 function f1(x) {
     58   g(f1);
     59   var result = h(f1);
     60   assertEquals(999, x);
     61   return result;
     62 }
     63 
     64 
     65 function test(f) {
     66   assertTrue(null === f.arguments);
     67   var args = f(1,2,3);
     68   assertTrue(null === f.arguments);
     69 
     70   assertEquals(3, args.length);
     71   assertEquals(999, args[0]);
     72   assertEquals(2, args[1]);
     73   assertEquals(3, args[2]);
     74   assertEquals('kallevip', args.extra);
     75 }
     76 
     77 test(f0);
     78 test(f1);
     79 
     80 
     81 
     82 
     83 function w() {
     84   return q.arguments;
     85 }
     86 
     87 function q(x, y) {
     88   x = 2;
     89   var result = w();
     90   y = 3;
     91   return result;
     92 }
     93 
     94 var a = q(0, 1);
     95 // x is set locally *before* the last use of arguments before the
     96 // activation of q is popped from the stack.
     97 assertEquals(2, a[0]);
     98 // y is set locally *after* the last use of arguments before the
     99 // activation of q is popped from the stack.
    100 assertEquals(1, a[1]);
    101