LCOV - code coverage report
Current view: directory - js/src/jsapi-tests - testArgumentsObject.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 57 57 100.0 %
Date: 2012-06-02 Functions: 15 13 86.7 %

       1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  * vim: set ts=8 sw=4 et tw=99:
       3                 :  */
       4                 : 
       5                 : #include "tests.h"
       6                 : 
       7                 : #include "vm/Stack-inl.h"
       8                 : 
       9                 : using namespace js;
      10                 : 
      11                 : static const char NORMAL_ZERO[] =
      12                 :     "function f() { return arguments; }";
      13                 : static const char NORMAL_ONE[] =
      14                 :     "function f(a) { return arguments; }";
      15                 : static const char NORMAL_TWO[] =
      16                 :     "function f(a, b) { return arguments; }";
      17                 : static const char NORMAL_THREE[] =
      18                 :     "function f(a, b, c) { return arguments; }";
      19                 : 
      20                 : static const char STRICT_ZERO[] =
      21                 :     "function f() { 'use strict'; return arguments; }";
      22                 : static const char STRICT_ONE[] =
      23                 :     "function f() { 'use strict'; return arguments; }";
      24                 : static const char STRICT_TWO[] =
      25                 :     "function f() { 'use strict'; return arguments; }";
      26                 : static const char STRICT_THREE[] =
      27                 :     "function f() { 'use strict'; return arguments; }";
      28                 : 
      29                 : static const char *CALL_CODES[] =
      30                 :     { "f()", "f(0)", "f(0, 1)", "f(0, 1, 2)", "f(0, 1, 2, 3)", "f(0, 1, 2, 3, 4)" };
      31                 : 
      32                 : static const size_t MAX_ELEMS = 6;
      33                 : 
      34                 : static void
      35             242 : ClearElements(Value elems[MAX_ELEMS])
      36                 : {
      37            1452 :     for (size_t i = 0; i < MAX_ELEMS - 1; i++)
      38            1210 :         elems[i] = NullValue();
      39             242 :     elems[MAX_ELEMS - 1] = Int32Value(42);
      40             242 : }
      41                 : 
      42               4 : BEGIN_TEST(testArgumentsObject)
      43                 : {
      44               1 :     return ExhaustiveTest<0>(NORMAL_ZERO) &&
      45               1 :            ExhaustiveTest<1>(NORMAL_ZERO) &&
      46               1 :            ExhaustiveTest<2>(NORMAL_ZERO) &&
      47               1 :            ExhaustiveTest<0>(NORMAL_ONE) &&
      48               1 :            ExhaustiveTest<1>(NORMAL_ONE) &&
      49               1 :            ExhaustiveTest<2>(NORMAL_ONE) &&
      50               1 :            ExhaustiveTest<3>(NORMAL_ONE) &&
      51               1 :            ExhaustiveTest<0>(NORMAL_TWO) &&
      52               1 :            ExhaustiveTest<1>(NORMAL_TWO) &&
      53               1 :            ExhaustiveTest<2>(NORMAL_TWO) &&
      54               1 :            ExhaustiveTest<3>(NORMAL_TWO) &&
      55               1 :            ExhaustiveTest<4>(NORMAL_TWO) &&
      56               1 :            ExhaustiveTest<0>(NORMAL_THREE) &&
      57               1 :            ExhaustiveTest<1>(NORMAL_THREE) &&
      58               1 :            ExhaustiveTest<2>(NORMAL_THREE) &&
      59               1 :            ExhaustiveTest<3>(NORMAL_THREE) &&
      60               1 :            ExhaustiveTest<4>(NORMAL_THREE) &&
      61               1 :            ExhaustiveTest<5>(NORMAL_THREE) &&
      62               1 :            ExhaustiveTest<0>(STRICT_ZERO) &&
      63               1 :            ExhaustiveTest<1>(STRICT_ZERO) &&
      64               1 :            ExhaustiveTest<2>(STRICT_ZERO) &&
      65               1 :            ExhaustiveTest<0>(STRICT_ONE) &&
      66               1 :            ExhaustiveTest<1>(STRICT_ONE) &&
      67               1 :            ExhaustiveTest<2>(STRICT_ONE) &&
      68               1 :            ExhaustiveTest<3>(STRICT_ONE) &&
      69               1 :            ExhaustiveTest<0>(STRICT_TWO) &&
      70               1 :            ExhaustiveTest<1>(STRICT_TWO) &&
      71               1 :            ExhaustiveTest<2>(STRICT_TWO) &&
      72               1 :            ExhaustiveTest<3>(STRICT_TWO) &&
      73               1 :            ExhaustiveTest<4>(STRICT_TWO) &&
      74               1 :            ExhaustiveTest<0>(STRICT_THREE) &&
      75               1 :            ExhaustiveTest<1>(STRICT_THREE) &&
      76               1 :            ExhaustiveTest<2>(STRICT_THREE) &&
      77               1 :            ExhaustiveTest<3>(STRICT_THREE) &&
      78               1 :            ExhaustiveTest<4>(STRICT_THREE) &&
      79              35 :            ExhaustiveTest<5>(STRICT_THREE);
      80                 : }
      81                 : 
      82                 : template<size_t ArgCount> bool
      83              36 : ExhaustiveTest(const char funcode[])
      84                 : {
      85                 :     jsval v;
      86              36 :     EVAL(funcode, &v);
      87                 : 
      88              36 :     EVAL(CALL_CODES[ArgCount], &v);
      89              36 :     ArgumentsObject &argsobj = JSVAL_TO_OBJECT(v)->asArguments();
      90                 : 
      91                 :     Value elems[MAX_ELEMS];
      92                 : 
      93             140 :     for (size_t i = 0; i <= ArgCount; i++) {
      94             346 :         for (size_t j = 0; j <= ArgCount - i; j++) {
      95             242 :             ClearElements(elems);
      96             242 :             CHECK(argsobj.getElements(i, j, elems));
      97             492 :             for (size_t k = 0; k < j; k++)
      98             250 :                 CHECK_SAME(elems[k], INT_TO_JSVAL(i + k));
      99            1202 :             for (size_t k = j; k < MAX_ELEMS - 1; k++)
     100             960 :                 CHECK_SAME(elems[k], JSVAL_NULL);
     101             242 :             CHECK_SAME(elems[MAX_ELEMS - 1], INT_TO_JSVAL(42));
     102                 :         }
     103                 :     }
     104                 : 
     105              36 :     return true;
     106                 : }
     107               2 : END_TEST(testArgumentsObject)

Generated by: LCOV version 1.7