LCOV - code coverage report
Current view: directory - js/src/jsapi-tests - testOps.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 19 18 94.7 %
Date: 2012-06-02 Functions: 10 8 80.0 %

       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 for operators and implicit type conversion.
       5                 :  */
       6                 : 
       7                 : #include "tests.h"
       8                 : 
       9                 : static JSBool
      10               9 : my_convert(JSContext* context, JSObject* obj, JSType type, jsval* rval)
      11                 : {
      12               9 :     if (type == JSTYPE_VOID || type == JSTYPE_STRING || type == JSTYPE_NUMBER || type == JSTYPE_BOOLEAN)
      13               9 :         return JS_NewNumberValue(context, 123, rval);
      14               0 :     return JS_FALSE;
      15                 : }
      16                 : 
      17                 : static JSClass myClass = {
      18                 :     "MyClass",
      19                 :     0,
      20                 :     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
      21                 :     JS_EnumerateStub, JS_ResolveStub, my_convert, JS_FinalizeStub,
      22                 :     JSCLASS_NO_OPTIONAL_MEMBERS
      23                 : };
      24                 : 
      25                 : static JSBool
      26               9 : createMyObject(JSContext* context, unsigned argc, jsval *vp)
      27                 : {
      28               9 :     JS_BeginRequest(context);
      29                 : 
      30                 :     //JS_GC(context); //<- if we make GC here, all is ok
      31                 : 
      32               9 :     JSObject* myObject = JS_NewObject(context, &myClass, NULL, NULL);
      33               9 :     *vp = OBJECT_TO_JSVAL(myObject);
      34                 : 
      35               9 :     JS_EndRequest(context);
      36                 : 
      37               9 :     return JS_TRUE;
      38                 : }
      39                 : 
      40                 : static JSFunctionSpec s_functions[] =
      41                 : {
      42                 :     { "createMyObject", createMyObject, 0 },
      43                 :     { 0,0,0,0 }
      44                 : };
      45                 : 
      46               4 : BEGIN_TEST(testOps_bug559006)
      47                 : {
      48               1 :     CHECK(JS_DefineFunctions(cx, global, s_functions));
      49                 : 
      50               1 :     EXEC("function main() { while(1) return 0 + createMyObject(); }");
      51                 : 
      52              10 :     for (int i = 0; i < 9; i++) {
      53              18 :         jsvalRoot rval(cx);
      54               9 :         CHECK(JS_CallFunctionName(cx, global, "main", 0, NULL, rval.addr()));
      55               9 :         CHECK_SAME(rval, INT_TO_JSVAL(123));
      56                 :     }
      57               1 :     return true;
      58                 : }
      59               2 : END_TEST(testOps_bug559006)
      60                 : 

Generated by: LCOV version 1.7