File indexing completed on 2024-04-28 15:28:37

0001 // check value of arguments inside recursion
0002 
0003 var expected = [null,99,1,2,3,3,2,1,99,null];
0004 var expno = 0;
0005 
0006 var x = 0;
0007 shouldBe("mf.arguments", "expected[expno++]");
0008 function mf(a,b) {
0009   shouldBe("mf.arguments[0]", "expected[expno++]");
0010   x++;
0011   if (x < 4)
0012     mf(x,1);
0013   shouldBe("mf.arguments[0]", "expected[expno++]");
0014   return b;
0015 }
0016 mf(99);
0017 shouldBe("mf.arguments", "expected[expno++]");
0018 
0019 
0020 // check internal properties of arguments
0021 
0022 // Delete
0023 
0024 
0025 // DontEnum
0026 var foundArgs = false;
0027 
0028 var ReadOnlyOK = false;
0029 var DontDeleteOK = false;
0030 var DontEnumOK = false;
0031 function f(a,b,c) {
0032 
0033   // ReadOnly
0034   var newargs = new Object();
0035   var oldargs = f.arguments;
0036   f.arguments = newargs;
0037   ReadOnlyOK = (f.arguments == oldargs);
0038 
0039   // DontDelete
0040   DontDeleteOK = !delete(f.arguments);
0041   if (f.arguments != oldargs)
0042     DontDeleteOK = false;
0043 
0044   // DontEnum
0045   var foundArgs = false;
0046   for (i in f) {
0047     if (f == "arguments")
0048       foundArgs = true;
0049   }
0050   DontEnumOK = !foundArgs;
0051 }
0052 f(1,2,3);
0053 shouldBeTrue("ReadOnlyOK");
0054 shouldBeTrue("DontDeleteOK");
0055 shouldBeTrue("DontEnumOK");
0056 
0057 // Check that parameter variables are bound to the corresponding
0058 // elements in the arguments array
0059 var arg0 = null;
0060 var arg1 = null;
0061 var arg2 = null;
0062 var newarg0 = null;
0063 var newarg1 = null;
0064 var newarg2 = null;
0065 var newx = null;
0066 var arglength = 0;
0067 
0068 function dupargs(x,x,x)
0069 {
0070   arg0 = arguments[0];
0071   arg1 = arguments[1];
0072   arg2 = arguments[2];
0073   arglength = arguments.length;
0074   x = 999;
0075   newarg0 = arguments[0];
0076   newarg1 = arguments[1];
0077   newarg2 = arguments[2];
0078   arguments[2] = 888;
0079   newx = x;
0080 }
0081 
0082 dupargs(1,2,3);
0083 
0084 shouldBe("arg0","1");
0085 shouldBe("arg1","2");
0086 shouldBe("arg2","3");
0087 shouldBe("arglength","3");
0088 shouldBe("newarg0","1");
0089 shouldBe("newarg1","2");
0090 shouldBe("newarg2","999");
0091 shouldBe("newx","888");
0092 
0093 
0094 // Make sure we pass the right 'this'..
0095 x = 1;
0096 
0097 function f1() {
0098   function f2() {
0099     v = this.x; // Can't use local stuff directly in eval
0100     shouldBe("v", "1");
0101   }
0102 
0103   var x = 3;
0104   f2();
0105 }
0106 
0107 f1();
0108 
0109 // Checks for arguments array symbol resolution
0110 function funnyArgUse(x) {
0111     arguments.__proto__["0x0"] = 50;
0112 
0113     argBlank = arguments[""];
0114     argHex   = arguments["0x0"];
0115     argSpace = arguments[" "];
0116     argTrail = arguments["0 "];
0117     argOK    = arguments["0"];
0118 }
0119 
0120 funnyArgUse(42);
0121 shouldBe('argBlank', 'undefined');
0122 shouldBe('argHex', '50');
0123 shouldBe('argSpace', 'undefined');
0124 shouldBe('argTrail', 'undefined');
0125 shouldBe('argOK', '42');
0126 
0127 debug("DONE");