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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /*
     7  *
     8  * Date:    21 May 2002
     9  * SUMMARY: ECMA conformance of Function.prototype.apply
    10  *
    11  *   Function.prototype.apply(thisArg, argArray)
    12  *
    13  * See ECMA-262 Edition 3 Final, Section 15.3.4.3
    14  */
    15 //-----------------------------------------------------------------------------
    16 var UBound = 0;
    17 var BUGNUMBER = 145791;
    18 var summary = 'Testing ECMA conformance of Function.prototype.apply';
    19 var status = '';
    20 var statusitems = [];
    21 var actual = '';
    22 var actualvalues = [];
    23 var expect= '';
    24 var expectedvalues = [];
    27 function F0(a)
    28 {
    29   return "" + this + arguments.length;
    30 }
    32 function F1(a)
    33 {
    34   return "" + this + a;
    35 }
    37 function F2()
    38 {
    39   return "" + this;
    40 }
    44 /*
    45  * Function.prototype.apply.length should return 2
    46  */
    47 status = inSection(1);
    48 actual = Function.prototype.apply.length;
    49 expect = 2;
    50 addThis();
    53 /*
    54  * When |thisArg| is not provided to the apply() method, the
    55  * called function must be passed the global object as |this|
    56  */
    57 status = inSection(2);
    58 actual = F0.apply();
    59 expect = "" + this + 0;
    60 addThis();
    63 /*
    64  * If |argArray| is not provided to the apply() method, the
    65  * called function should be invoked with an empty argument list
    66  */
    67 status = inSection(3);
    68 actual = F0.apply("");
    69 expect = "" + "" + 0;
    70 addThis();
    72 status = inSection(4);
    73 actual = F0.apply(true);
    74 expect = "" + true + 0;
    75 addThis();
    78 /*
    79  * Function.prototype.apply(x) and
    80  * Function.prototype.apply(x, undefined) should return the same result
    81  */
    82 status = inSection(5);
    83 actual = F1.apply(0, undefined);
    84 expect = F1.apply(0);
    85 addThis();
    87 status = inSection(6);
    88 actual = F1.apply("", undefined);
    89 expect = F1.apply("");
    90 addThis();
    92 status = inSection(7);
    93 actual = F1.apply(null, undefined);
    94 expect = F1.apply(null);
    95 addThis();
    97 status = inSection(8);
    98 actual = F1.apply(undefined, undefined);
    99 expect = F1.apply(undefined);
   100 addThis();
   103 /*
   104  * Function.prototype.apply(x) and
   105  * Function.prototype.apply(x, null) should return the same result
   106  */
   107 status = inSection(9);
   108 actual = F1.apply(0, null);
   109 expect = F1.apply(0);
   110 addThis();
   112 status = inSection(10);
   113 actual = F1.apply("", null);
   114 expect = F1.apply("");
   115 addThis();
   117 status = inSection(11);
   118 actual = F1.apply(null, null);
   119 expect = F1.apply(null);
   120 addThis();
   122 status = inSection(12);
   123 actual = F1.apply(undefined, null);
   124 expect = F1.apply(undefined);
   125 addThis();
   128 /*
   129  * Function.prototype.apply() and
   130  * Function.prototype.apply(undefined) should return the same result
   131  */
   132 status = inSection(13);
   133 actual = F2.apply(undefined);
   134 expect = F2.apply();
   135 addThis();
   138 /*
   139  * Function.prototype.apply() and
   140  * Function.prototype.apply(null) should return the same result
   141  */
   142 status = inSection(14);
   143 actual = F2.apply(null);
   144 expect = F2.apply();
   145 addThis();
   149 //-----------------------------------------------------------------------------
   150 test();
   151 //-----------------------------------------------------------------------------
   155 function addThis()
   156 {
   157   statusitems[UBound] = status;
   158   actualvalues[UBound] = actual;
   159   expectedvalues[UBound] = expect;
   160   UBound++;
   161 }
   164 function test()
   165 {
   166   enterFunc('test');
   167   printBugNumber(BUGNUMBER);
   168   printStatus(summary);
   170   for (var i=0; i<UBound; i++)
   171   {
   172     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   173   }
   175   exitFunc ('test');
   176 }

mercurial