js/src/tests/ecma/FunctionObjects/15.3.1.1-2.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/FunctionObjects/15.3.1.1-2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,149 @@
     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 +   File Name:          15.3.1.1-2.js
    1.12 +   ECMA Section:       15.3.1.1 The Function Constructor Called as a Function
    1.13 +   Function(p1, p2, ..., pn, body )
    1.14 +
    1.15 +   Description:
    1.16 +   When the Function function is called with some arguments p1, p2, . . . , pn,
    1.17 +   body (where n might be 0, that is, there are no "p" arguments, and where body
    1.18 +   might also not be provided), the following steps are taken:
    1.19 +
    1.20 +   1.  Create and return a new Function object exactly if the function constructor
    1.21 +   had been called with the same arguments (15.3.2.1).
    1.22 +
    1.23 +   Author:             christine@netscape.com
    1.24 +   Date:               28 october 1997
    1.25 +
    1.26 +*/
    1.27 +var SECTION = "15.3.1.1-2";
    1.28 +var VERSION = "ECMA_1";
    1.29 +startTest();
    1.30 +var TITLE   = "The Function Constructor Called as a Function";
    1.31 +
    1.32 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.33 +
    1.34 +var myfunc1 =  Function("a","b","c", "return a+b+c" );
    1.35 +var myfunc2 =  Function("a, b, c",   "return a+b+c" );
    1.36 +var myfunc3 =  Function("a,b", "c",  "return a+b+c" );
    1.37 +
    1.38 +myfunc1.toString = Object.prototype.toString;
    1.39 +myfunc2.toString = Object.prototype.toString;
    1.40 +myfunc3.toString = Object.prototype.toString;
    1.41 +
    1.42 +new TestCase( SECTION, 
    1.43 +	      "myfunc1 =  Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
    1.44 +	      "[object Function]",
    1.45 +	      myfunc1.toString() );
    1.46 +
    1.47 +new TestCase( SECTION, 
    1.48 +	      "myfunc1.length",                           
    1.49 +	      3,                     
    1.50 +	      myfunc1.length );
    1.51 +
    1.52 +new TestCase( SECTION, 
    1.53 +	      "myfunc1.prototype.toString()",             
    1.54 +	      "[object Object]",     
    1.55 +	      myfunc1.prototype.toString() );
    1.56 +
    1.57 +new TestCase( SECTION, 
    1.58 +	      "myfunc1.prototype.constructor",            
    1.59 +	      myfunc1,               
    1.60 +	      myfunc1.prototype.constructor );
    1.61 +
    1.62 +new TestCase( SECTION, 
    1.63 +	      "myfunc1.arguments",                        
    1.64 +	      null,                  
    1.65 +	      myfunc1.arguments );
    1.66 +
    1.67 +new TestCase( SECTION, 
    1.68 +	      "myfunc1(1,2,3)",                           
    1.69 +	      6,                     
    1.70 +	      myfunc1(1,2,3) );
    1.71 +
    1.72 +new TestCase( SECTION, 
    1.73 +	      "var MYPROPS = ''; for ( var p in myfunc1.prototype ) { MYPROPS += p; }; MYPROPS",
    1.74 +	      "",
    1.75 +	      eval("var MYPROPS = ''; for ( var p in myfunc1.prototype ) { MYPROPS += p; }; MYPROPS") );
    1.76 +
    1.77 +new TestCase( SECTION, 
    1.78 +	      "myfunc2 =  Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
    1.79 +	      "[object Function]",
    1.80 +	      myfunc2.toString() );
    1.81 +
    1.82 +new TestCase( SECTION, 
    1.83 +	      "myfunc2.length",                           
    1.84 +	      3,                     
    1.85 +	      myfunc2.length );
    1.86 +
    1.87 +new TestCase( SECTION, 
    1.88 +	      "myfunc2.prototype.toString()",             
    1.89 +	      "[object Object]",     
    1.90 +	      myfunc2.prototype.toString() );
    1.91 +
    1.92 +new TestCase( SECTION, 
    1.93 +	      "myfunc2.prototype.constructor",            
    1.94 +	      myfunc2,                
    1.95 +	      myfunc2.prototype.constructor );
    1.96 +
    1.97 +new TestCase( SECTION, 
    1.98 +	      "myfunc2.arguments",                        
    1.99 +	      null,                  
   1.100 +	      myfunc2.arguments );
   1.101 +
   1.102 +new TestCase( SECTION, 
   1.103 +	      "myfunc2( 1000, 200, 30 )",                
   1.104 +	      1230,                   
   1.105 +	      myfunc2(1000,200,30) );
   1.106 +
   1.107 +new TestCase( SECTION, 
   1.108 +	      "var MYPROPS = ''; for ( var p in myfunc2.prototype ) { MYPROPS += p; }; MYPROPS",
   1.109 +	      "",
   1.110 +	      eval("var MYPROPS = ''; for ( var p in myfunc2.prototype ) { MYPROPS += p; }; MYPROPS") );
   1.111 +
   1.112 +new TestCase( SECTION, 
   1.113 +	      "myfunc3 =  Function('a','b','c'); myfunc.toString = Object.prototype.toString; myfunc.toString()",
   1.114 +	      "[object Function]",
   1.115 +	      myfunc3.toString() );
   1.116 +
   1.117 +new TestCase( SECTION, 
   1.118 +	      "myfunc3.length",                           
   1.119 +	      3,                     
   1.120 +	      myfunc3.length );
   1.121 +
   1.122 +new TestCase( SECTION, 
   1.123 +	      "myfunc3.prototype.toString()",             
   1.124 +	      "[object Object]",     
   1.125 +	      myfunc3.prototype.toString() );
   1.126 +
   1.127 +new TestCase( SECTION, 
   1.128 +	      "myfunc3.prototype.valueOf() +''",          
   1.129 +	      "[object Object]",     
   1.130 +	      myfunc3.prototype.valueOf() +'' );
   1.131 +
   1.132 +new TestCase( SECTION, 
   1.133 +	      "myfunc3.prototype.constructor",            
   1.134 +	      myfunc3,                
   1.135 +	      myfunc3.prototype.constructor );
   1.136 +
   1.137 +new TestCase( SECTION, 
   1.138 +	      "myfunc3.arguments",                        
   1.139 +	      null,                  
   1.140 +	      myfunc3.arguments );
   1.141 +
   1.142 +new TestCase( SECTION, 
   1.143 +	      "myfunc3(-100,100,NaN)",                   
   1.144 +	      Number.NaN,             
   1.145 +	      myfunc3(-100,100,NaN) );
   1.146 +
   1.147 +new TestCase( SECTION, 
   1.148 +	      "var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS",
   1.149 +	      "",
   1.150 +	      eval("var MYPROPS = ''; for ( var p in myfunc3.prototype ) { MYPROPS += p; }; MYPROPS") );
   1.151 +
   1.152 +test();

mercurial