LCOV - code coverage report
Current view: directory - js/src/jsapi-tests - testAddPropertyPropcache.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 24 24 100.0 %
Date: 2012-04-07 Functions: 9 7 77.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                 : 
       5                 : #include "tests.h"
       6                 : 
       7                 : /* Do the test a bunch of times, because sometimes we seem to randomly
       8                 :    miss the propcache */
       9                 : static const int expectedCount = 100;
      10                 : static int callCount = 0;
      11                 : 
      12                 : static JSBool
      13             100 : addProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
      14                 : {
      15             100 :   callCount++;
      16             100 :   return true;
      17                 : }
      18                 : 
      19                 : JSClass addPropertyClass = {
      20                 :     "AddPropertyTester",
      21                 :     0,
      22                 :     addProperty,
      23                 :     JS_PropertyStub,         /* delProperty */
      24                 :     JS_PropertyStub,         /* getProperty */
      25                 :     JS_StrictPropertyStub,   /* setProperty */
      26                 :     JS_EnumerateStub,
      27                 :     JS_ResolveStub,
      28                 :     JS_ConvertStub
      29                 : };
      30                 : 
      31               4 : BEGIN_TEST(testAddPropertyHook)
      32                 : {
      33               2 :     jsvalRoot proto(cx);
      34               1 :     JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
      35               1 :     CHECK(obj);
      36               1 :     proto = OBJECT_TO_JSVAL(obj);
      37                 :     JS_InitClass(cx, global, obj, &addPropertyClass, NULL, 0, NULL, NULL, NULL,
      38               1 :                  NULL);
      39                 : 
      40               2 :     jsvalRoot arr(cx);
      41               1 :     obj = JS_NewArrayObject(cx, 0, NULL);
      42               1 :     CHECK(obj);
      43               1 :     arr = OBJECT_TO_JSVAL(obj);
      44                 :         
      45               1 :     CHECK(JS_DefineProperty(cx, global, "arr", arr,
      46                 :                             JS_PropertyStub, JS_StrictPropertyStub,
      47                 :                             JSPROP_ENUMERATE));
      48                 : 
      49             101 :     for (int i = 0; i < expectedCount; ++i) {
      50             200 :         jsvalRoot vobj(cx);
      51             100 :         obj = JS_NewObject(cx, &addPropertyClass, NULL, NULL);
      52             100 :         CHECK(obj);
      53             100 :         vobj = OBJECT_TO_JSVAL(obj);
      54             100 :         CHECK(JS_DefineElement(cx, JSVAL_TO_OBJECT(arr), i, vobj,
      55                 :                                JS_PropertyStub, JS_StrictPropertyStub,
      56                 :                                JSPROP_ENUMERATE));
      57                 :     }
      58                 :     
      59                 :     // Now add a prop to each of the objects, but make sure to do
      60                 :     // so at the same bytecode location so we can hit the propcache.
      61               1 :     EXEC("'use strict';                                     \n"
      62                 :          "for (var i = 0; i < arr.length; ++i)              \n"
      63                 :          "  arr[i].prop = 42;                               \n"
      64                 :          );
      65                 : 
      66               1 :     CHECK(callCount == expectedCount);
      67                 : 
      68               1 :     return true;
      69                 : }
      70               2 : END_TEST(testAddPropertyHook)
      71                 : 

Generated by: LCOV version 1.7