js/src/tests/js1_5/Function/regress-222029-001.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/Function/regress-222029-001.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + *
    1.11 + * Date:    13 Oct 2003
    1.12 + * SUMMARY: Make our f.caller property match IE's wrt f.apply and f.call
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=222029
    1.14 + *
    1.15 + * Below, when gg calls f via |f.call|, we have this call chain:
    1.16 + *
    1.17 + *          calls                                  calls
    1.18 + *   gg() --------->  Function.prototype.call()  --------->  f()
    1.19 + *
    1.20 + *
    1.21 + * The question this bug addresses is, "What should we say |f.caller| is?"
    1.22 + *
    1.23 + * Before this fix, SpiderMonkey said it was |Function.prototype.call|.
    1.24 + * After this fix, SpiderMonkey emulates IE and says |gg| instead.
    1.25 + *
    1.26 + */
    1.27 +//-----------------------------------------------------------------------------
    1.28 +var UBound = 0;
    1.29 +var BUGNUMBER = 222029;
    1.30 +var summary = "Make our f.caller property match IE's wrt f.apply and f.call";
    1.31 +var status = '';
    1.32 +var statusitems = [];
    1.33 +var actual = '';
    1.34 +var actualvalues = [];
    1.35 +var expect= '';
    1.36 +var expectedvalues = [];
    1.37 +
    1.38 +
    1.39 +function f()
    1.40 +{
    1.41 +  return f.caller.p ;
    1.42 +}
    1.43 +
    1.44 +
    1.45 +/*
    1.46 + * Call |f| directly
    1.47 + */
    1.48 +function g()
    1.49 +{
    1.50 +  return f();
    1.51 +}
    1.52 +g.p = "hello";
    1.53 +
    1.54 +
    1.55 +/*
    1.56 + * Call |f| via |f.call|
    1.57 + */
    1.58 +function gg()
    1.59 +{
    1.60 +  return f.call(this);
    1.61 +}
    1.62 +gg.p = "hello";
    1.63 +
    1.64 +
    1.65 +/*
    1.66 + * Call |f| via |f.apply|
    1.67 + */
    1.68 +function ggg()
    1.69 +{
    1.70 +  return f.apply(this);
    1.71 +}
    1.72 +ggg.p = "hello";
    1.73 +
    1.74 +
    1.75 +/*
    1.76 + * Shadow |p| on |Function.prototype.call|, |Function.prototype.apply|.
    1.77 + * In Sections 2 and 3 below, we no longer expect to recover this value -
    1.78 + */
    1.79 +Function.prototype.call.p = "goodbye";
    1.80 +Function.prototype.apply.p = "goodbye";
    1.81 +
    1.82 +
    1.83 +
    1.84 +status = inSection(1);
    1.85 +actual = g();
    1.86 +expect = "hello";
    1.87 +addThis();
    1.88 +
    1.89 +status = inSection(2);
    1.90 +actual = gg();
    1.91 +expect = "hello";
    1.92 +addThis();
    1.93 +
    1.94 +status = inSection(3);
    1.95 +actual = ggg();
    1.96 +expect = "hello";
    1.97 +addThis();
    1.98 +
    1.99 +
   1.100 +
   1.101 +
   1.102 +//-----------------------------------------------------------------------------
   1.103 +test();
   1.104 +//-----------------------------------------------------------------------------
   1.105 +
   1.106 +
   1.107 +
   1.108 +function addThis()
   1.109 +{
   1.110 +  statusitems[UBound] = status;
   1.111 +  actualvalues[UBound] = actual;
   1.112 +  expectedvalues[UBound] = expect;
   1.113 +  UBound++;
   1.114 +}
   1.115 +
   1.116 +
   1.117 +function test()
   1.118 +{
   1.119 +  enterFunc('test');
   1.120 +  printBugNumber(BUGNUMBER);
   1.121 +  printStatus(summary);
   1.122 +
   1.123 +  for (var i=0; i<UBound; i++)
   1.124 +  {
   1.125 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.126 +  }
   1.127 +
   1.128 +  exitFunc ('test');
   1.129 +}

mercurial