LCOV - code coverage report
Current view: directory - js/src/jsapi-tests - testClassGetter.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 22 21 95.5 %
Date: 2012-06-02 Functions: 11 9 81.8 %

       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                 :  * Tests the JSClass::getProperty hook
       5                 :  */
       6                 : 
       7                 : #include "tests.h"
       8                 : 
       9                 : int called_test_fn;
      10                 : int called_test_prop_get;
      11                 : 
      12              32 : static JSBool test_prop_get( JSContext *cx, JSObject *obj, jsid id, jsval *vp )
      13                 : {
      14              32 :     called_test_prop_get++;
      15              32 :     return JS_TRUE;
      16                 : }
      17                 : 
      18                 : static JSBool
      19               8 : PTest(JSContext* cx, unsigned argc, jsval *vp)
      20                 : {
      21               8 :     JSObject *obj = JS_NewObjectForConstructor(cx, vp);
      22               8 :     if (!obj)
      23               0 :         return JS_FALSE;
      24               8 :     JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
      25               8 :     return JS_TRUE;
      26                 : }
      27                 : 
      28                 : static JSClass ptestClass = {
      29                 :     "PTest",
      30                 :     JSCLASS_HAS_PRIVATE,
      31                 : 
      32                 :     JS_PropertyStub,       // add
      33                 :     JS_PropertyStub,       // delete
      34                 :     test_prop_get,         // get
      35                 :     JS_StrictPropertyStub, // set
      36                 :     JS_EnumerateStub,
      37                 :     JS_ResolveStub,
      38                 :     JS_ConvertStub,
      39                 :     JS_FinalizeStub,
      40                 :     JSCLASS_NO_OPTIONAL_MEMBERS
      41                 : };
      42                 : 
      43               8 : static JSBool test_fn(JSContext *cx, unsigned argc, jsval *vp)
      44                 : {
      45               8 :     called_test_fn++;
      46               8 :     return JS_TRUE;
      47                 : }
      48                 : 
      49                 : static JSFunctionSpec ptestFunctions[] = {
      50                 :     JS_FS( "test_fn", test_fn, 0, 0 ),
      51                 :     JS_FS_END
      52                 : };
      53                 : 
      54               4 : BEGIN_TEST(testClassGetter_isCalled)
      55                 : {
      56               1 :     CHECK(JS_InitClass(cx, JS_GetGlobalObject(cx), NULL, &ptestClass, PTest, 0,
      57                 :                        NULL, ptestFunctions, NULL, NULL));
      58                 : 
      59               1 :     EXEC("function check() { var o = new PTest(); o.test_fn(); o.test_value1; o.test_value2; o.test_value1; }");
      60                 : 
      61               9 :     for (int i = 1; i < 9; i++) {
      62              16 :         jsvalRoot rval(cx);
      63               8 :         CHECK(JS_CallFunctionName(cx, global, "check", 0, NULL, rval.addr()));
      64               8 :         CHECK_SAME(INT_TO_JSVAL(called_test_fn), INT_TO_JSVAL(i));
      65               8 :         CHECK_SAME(INT_TO_JSVAL(called_test_prop_get), INT_TO_JSVAL(4 * i));
      66                 :     }
      67               1 :     return true;
      68                 : }
      69               2 : END_TEST(testClassGetter_isCalled)

Generated by: LCOV version 1.7