1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/Function/15.3.4.4-1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,162 @@ 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.call 1.13 + * 1.14 + * Function.prototype.call(thisArg [,arg1 [,arg2, ...]]) 1.15 + * 1.16 + * See ECMA-262 Edition 3 Final, Section 15.3.4.4 1.17 + */ 1.18 +//----------------------------------------------------------------------------- 1.19 +var UBound = 0; 1.20 +var BUGNUMBER = 145791; 1.21 +var summary = 'Testing ECMA conformance of Function.prototype.call'; 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.call.length should return 1 1.49 + */ 1.50 +status = inSection(1); 1.51 +actual = Function.prototype.call.length; 1.52 +expect = 1; 1.53 +addThis(); 1.54 + 1.55 + 1.56 +/* 1.57 + * When |thisArg| is not provided to the call() 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.call(); 1.62 +expect = "" + this + 0; 1.63 +addThis(); 1.64 + 1.65 + 1.66 +/* 1.67 + * If [,arg1 [,arg2, ...]] are not provided to the call() method, 1.68 + * the called function should be invoked with an empty argument list 1.69 + */ 1.70 +status = inSection(3); 1.71 +actual = F0.call(""); 1.72 +expect = "" + "" + 0; 1.73 +addThis(); 1.74 + 1.75 +status = inSection(4); 1.76 +actual = F0.call(true); 1.77 +expect = "" + true + 0; 1.78 +addThis(); 1.79 + 1.80 + 1.81 +/* 1.82 + * Function.prototype.call(x) and 1.83 + * Function.prototype.call(x, undefined) should return the same result 1.84 + */ 1.85 +status = inSection(5); 1.86 +actual = F1.call(0, undefined); 1.87 +expect = F1.call(0); 1.88 +addThis(); 1.89 + 1.90 +status = inSection(6); 1.91 +actual = F1.call("", undefined); 1.92 +expect = F1.call(""); 1.93 +addThis(); 1.94 + 1.95 +status = inSection(7); 1.96 +actual = F1.call(null, undefined); 1.97 +expect = F1.call(null); 1.98 +addThis(); 1.99 + 1.100 +status = inSection(8); 1.101 +actual = F1.call(undefined, undefined); 1.102 +expect = F1.call(undefined); 1.103 +addThis(); 1.104 + 1.105 + 1.106 +/* 1.107 + * Function.prototype.call() and 1.108 + * Function.prototype.call(undefined) should return the same result 1.109 + */ 1.110 +status = inSection(9); 1.111 +actual = F2.call(undefined); 1.112 +expect = F2.call(); 1.113 +addThis(); 1.114 + 1.115 + 1.116 +/* 1.117 + * Function.prototype.call() and 1.118 + * Function.prototype.call(null) should return the same result 1.119 + */ 1.120 +status = inSection(10); 1.121 +actual = F2.call(null); 1.122 +expect = F2.call(); 1.123 +addThis(); 1.124 + 1.125 +if (typeof newGlobal === "function") 1.126 +{ 1.127 + /* 1.128 + * Function.prototype.call gets lexical globals, not caller globals 1.129 + */ 1.130 + status = inSection(11); 1.131 + actual = g2 = newGlobal(); 1.132 + g2.eval("boundMethod = Function('return this');"); 1.133 + expect = g2.boundMethod.call(); 1.134 + addThis(); 1.135 +} 1.136 + 1.137 + 1.138 +//----------------------------------------------------------------------------- 1.139 +test(); 1.140 +//----------------------------------------------------------------------------- 1.141 + 1.142 + 1.143 + 1.144 +function addThis() 1.145 +{ 1.146 + statusitems[UBound] = status; 1.147 + actualvalues[UBound] = actual; 1.148 + expectedvalues[UBound] = expect; 1.149 + UBound++; 1.150 +} 1.151 + 1.152 + 1.153 +function test() 1.154 +{ 1.155 + enterFunc('test'); 1.156 + printBugNumber(BUGNUMBER); 1.157 + printStatus(summary); 1.158 + 1.159 + for (var i=0; i<UBound; i++) 1.160 + { 1.161 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.162 + } 1.163 + 1.164 + exitFunc ('test'); 1.165 +}