LCOV - app.info - js/src/jsapi-tests/testConservativeGC.cpp

LCOV - code coverage report
| Current view: | directory - js/src/jsapi-tests - testConservativeGC.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 41 | 41 | 100.0 %
| Date: | 2012-04-07 | Functions: | 14 | 11 | 78.6 %

           1                 : #include "tests.h"
           2                 : #include "jsobj.h"
           3                 : #include "vm/String.h"
           4                 :
           5               4 : BEGIN_TEST(testConservativeGC)
           6                 : {
           7                 :     jsval v2;
           8               1 :     EVAL("({foo: 'bar'});", &v2);
           9               1 :     CHECK(JSVAL_IS_OBJECT(v2));
          10                 :     char objCopy[sizeof(JSObject)];
          11               1 :     js_memcpy(&objCopy, JSVAL_TO_OBJECT(v2), sizeof(JSObject));
          12                 :
          13                 :     jsval v3;
          14               1 :     EVAL("String(Math.PI);", &v3);
          15               1 :     CHECK(JSVAL_IS_STRING(v3));
          16               1 :     JSString strCopy = *JSVAL_TO_STRING(v3);
          17                 :
          18                 :     jsval tmp;
          19               1 :     EVAL("({foo2: 'bar2'});", &tmp);
          20               1 :     CHECK(JSVAL_IS_OBJECT(tmp));
          21               1 :     JSObject *obj2 = JSVAL_TO_OBJECT(tmp);
          22                 :     char obj2Copy[sizeof(JSObject)];
          23               1 :     js_memcpy(&obj2Copy, obj2, sizeof(JSObject));
          24                 :
          25               1 :     EVAL("String(Math.sqrt(3));", &tmp);
          26               1 :     CHECK(JSVAL_IS_STRING(tmp));
          27               1 :     JSString *str2 = JSVAL_TO_STRING(tmp);
          28               1 :     JSString str2Copy = *str2;
          29                 :
          30               1 :     tmp = JSVAL_NULL;
          31                 :
          32               1 :     JS_GC(cx);
          33                 :
          34               1 :     EVAL("var a = [];\n"
          35                 :          "for (var i = 0; i != 10000; ++i) {\n"
          36                 :          "a.push(i + 0.1, [1, 2], String(Math.sqrt(i)), {a: i});\n"
          37                 :          "}", &tmp);
          38                 :
          39               1 :     JS_GC(cx);
          40                 :
          41               1 :     checkObjectFields((JSObject *)objCopy, JSVAL_TO_OBJECT(v2));
          42               1 :     CHECK(!memcmp(&strCopy, JSVAL_TO_STRING(v3), sizeof(strCopy)));
          43                 :
          44               1 :     checkObjectFields((JSObject *)obj2Copy, obj2);
          45               1 :     CHECK(!memcmp(&str2Copy, str2, sizeof(str2Copy)));
          46                 :
          47               1 :     return true;
          48                 : }
          49                 :
          50               2 : bool checkObjectFields(JSObject *savedCopy, JSObject *obj)
          51                 : {
          52                 :     /* Ignore fields which are unstable across GCs. */
          53               2 :     CHECK(savedCopy->lastProperty() == obj->lastProperty());
          54               2 :     CHECK(savedCopy->getProto() == obj->getProto());
          55               2 :     return true;
          56                 : }
          57                 :
          58               1 : END_TEST(testConservativeGC)
          59                 :
          60               4 : BEGIN_TEST(testDerivedValues)
          61                 : {
          62               1 :   JSString *str = JS_NewStringCopyZ(cx, "once upon a midnight dreary");
          63               2 :   JS::Anchor<JSString *> str_anchor(str);
          64                 :   static const jschar expected[] = { 'o', 'n', 'c', 'e' };
          65               1 :   const jschar *ch = JS_GetStringCharsZ(cx, str);
          66               1 :   str = NULL;
          67                 :
          68                 :   /* Do a lot of allocation and collection. */
          69               4 :   for (int i = 0; i < 3; i++) {
          70            3003 :     for (int j = 0; j < 1000; j++)
          71            3000 :       JS_NewStringCopyZ(cx, "as I pondered weak and weary");
          72               3 :     JS_GC(cx);
          73                 :   }
          74                 :
          75               1 :   CHECK(!memcmp(ch, expected, sizeof(expected)));
          76               1 :   return true;
          77                 : }
          78               3 : END_TEST(testDerivedValues)

Generated by: LCOV version 1.7