js/src/tests/ecma_3/Function/15.3.4.3-1.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/Function/15.3.4.3-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,176 @@
     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:    21 May 2002
    1.12 + * SUMMARY: ECMA conformance of Function.prototype.apply
    1.13 + *
    1.14 + *   Function.prototype.apply(thisArg, argArray)
    1.15 + *
    1.16 + * See ECMA-262 Edition 3 Final, Section 15.3.4.3
    1.17 + */
    1.18 +//-----------------------------------------------------------------------------
    1.19 +var UBound = 0;
    1.20 +var BUGNUMBER = 145791;
    1.21 +var summary = 'Testing ECMA conformance of Function.prototype.apply';
    1.22 +var status = '';
    1.23 +var statusitems = [];
    1.24 +var actual = '';
    1.25 +var actualvalues = [];
    1.26 +var expect= '';
    1.27 +var expectedvalues = [];
    1.28 +
    1.29 +
    1.30 +function F0(a)
    1.31 +{
    1.32 +  return "" + this + arguments.length;
    1.33 +}
    1.34 +
    1.35 +function F1(a)
    1.36 +{
    1.37 +  return "" + this + a;
    1.38 +}
    1.39 +
    1.40 +function F2()
    1.41 +{
    1.42 +  return "" + this;
    1.43 +}
    1.44 +
    1.45 +
    1.46 +
    1.47 +/*
    1.48 + * Function.prototype.apply.length should return 2
    1.49 + */
    1.50 +status = inSection(1);
    1.51 +actual = Function.prototype.apply.length;
    1.52 +expect = 2;
    1.53 +addThis();
    1.54 +
    1.55 +
    1.56 +/*
    1.57 + * When |thisArg| is not provided to the apply() method, the
    1.58 + * called function must be passed the global object as |this|
    1.59 + */
    1.60 +status = inSection(2);
    1.61 +actual = F0.apply();
    1.62 +expect = "" + this + 0;
    1.63 +addThis();
    1.64 +
    1.65 +
    1.66 +/*
    1.67 + * If |argArray| is not provided to the apply() method, the
    1.68 + * called function should be invoked with an empty argument list
    1.69 + */
    1.70 +status = inSection(3);
    1.71 +actual = F0.apply("");
    1.72 +expect = "" + "" + 0;
    1.73 +addThis();
    1.74 +
    1.75 +status = inSection(4);
    1.76 +actual = F0.apply(true);
    1.77 +expect = "" + true + 0;
    1.78 +addThis();
    1.79 +
    1.80 +
    1.81 +/*
    1.82 + * Function.prototype.apply(x) and
    1.83 + * Function.prototype.apply(x, undefined) should return the same result
    1.84 + */
    1.85 +status = inSection(5);
    1.86 +actual = F1.apply(0, undefined);
    1.87 +expect = F1.apply(0);
    1.88 +addThis();
    1.89 +
    1.90 +status = inSection(6);
    1.91 +actual = F1.apply("", undefined);
    1.92 +expect = F1.apply("");
    1.93 +addThis();
    1.94 +
    1.95 +status = inSection(7);
    1.96 +actual = F1.apply(null, undefined);
    1.97 +expect = F1.apply(null);
    1.98 +addThis();
    1.99 +
   1.100 +status = inSection(8);
   1.101 +actual = F1.apply(undefined, undefined);
   1.102 +expect = F1.apply(undefined);
   1.103 +addThis();
   1.104 +
   1.105 +
   1.106 +/*
   1.107 + * Function.prototype.apply(x) and
   1.108 + * Function.prototype.apply(x, null) should return the same result
   1.109 + */
   1.110 +status = inSection(9);
   1.111 +actual = F1.apply(0, null);
   1.112 +expect = F1.apply(0);
   1.113 +addThis();
   1.114 +
   1.115 +status = inSection(10);
   1.116 +actual = F1.apply("", null);
   1.117 +expect = F1.apply("");
   1.118 +addThis();
   1.119 +
   1.120 +status = inSection(11);
   1.121 +actual = F1.apply(null, null);
   1.122 +expect = F1.apply(null);
   1.123 +addThis();
   1.124 +
   1.125 +status = inSection(12);
   1.126 +actual = F1.apply(undefined, null);
   1.127 +expect = F1.apply(undefined);
   1.128 +addThis();
   1.129 +
   1.130 +
   1.131 +/*
   1.132 + * Function.prototype.apply() and
   1.133 + * Function.prototype.apply(undefined) should return the same result
   1.134 + */
   1.135 +status = inSection(13);
   1.136 +actual = F2.apply(undefined);
   1.137 +expect = F2.apply();
   1.138 +addThis();
   1.139 +
   1.140 +
   1.141 +/*
   1.142 + * Function.prototype.apply() and
   1.143 + * Function.prototype.apply(null) should return the same result
   1.144 + */
   1.145 +status = inSection(14);
   1.146 +actual = F2.apply(null);
   1.147 +expect = F2.apply();
   1.148 +addThis();
   1.149 +
   1.150 +
   1.151 +
   1.152 +//-----------------------------------------------------------------------------
   1.153 +test();
   1.154 +//-----------------------------------------------------------------------------
   1.155 +
   1.156 +
   1.157 +
   1.158 +function addThis()
   1.159 +{
   1.160 +  statusitems[UBound] = status;
   1.161 +  actualvalues[UBound] = actual;
   1.162 +  expectedvalues[UBound] = expect;
   1.163 +  UBound++;
   1.164 +}
   1.165 +
   1.166 +
   1.167 +function test()
   1.168 +{
   1.169 +  enterFunc('test');
   1.170 +  printBugNumber(BUGNUMBER);
   1.171 +  printStatus(summary);
   1.172 +
   1.173 +  for (var i=0; i<UBound; i++)
   1.174 +  {
   1.175 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.176 +  }
   1.177 +
   1.178 +  exitFunc ('test');
   1.179 +}

mercurial