LCOV - code coverage report
Current view: directory - js/src/jsapi-tests - testGCOutOfMemory.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 20 20 100.0 %
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                 :  * Any copyright is dedicated to the Public Domain.
       5                 :  * http://creativecommons.org/licenses/publicdomain/
       6                 :  * Contributor: Igor Bukanov
       7                 :  */
       8                 : 
       9                 : #include "tests.h"
      10                 : #include "jscntxt.h"
      11                 : 
      12                 : static unsigned errorCount = 0;
      13                 : 
      14                 : static void
      15               1 : ErrorCounter(JSContext *cx, const char *message, JSErrorReport *report)
      16                 : {
      17               1 :     ++errorCount;
      18               1 : }
      19                 : 
      20               4 : BEGIN_TEST(testGCOutOfMemory)
      21                 : {
      22               1 :     JS_SetErrorReporter(cx, ErrorCounter);
      23                 : 
      24               2 :     jsvalRoot root(cx);
      25                 : 
      26                 :     static const char source[] =
      27                 :         "var max = 0; (function() {"
      28                 :         "    var array = [];"
      29                 :         "    for (; ; ++max)"
      30                 :         "        array.push({});"
      31                 :         "    array = []; array.push(0);"
      32                 :         "})();";
      33                 :     JSBool ok = JS_EvaluateScript(cx, global, source, strlen(source), "", 1,
      34               1 :                                   root.addr());
      35                 : 
      36                 :     /* Check that we get OOM. */
      37               1 :     CHECK(!ok);
      38               1 :     CHECK(!JS_IsExceptionPending(cx));
      39               1 :     CHECK_EQUAL(errorCount, 1);
      40               1 :     JS_GC(cx);
      41               1 :     EVAL("(function() {"
      42                 :          "    var array = [];"
      43                 :          "    for (var i = max >> 2; i != 0;) {"
      44                 :          "        --i;"
      45                 :          "        array.push({});"
      46                 :          "    }"
      47                 :          "})();", root.addr());
      48               1 :     CHECK_EQUAL(errorCount, 1);
      49               1 :     return true;
      50                 : }
      51                 : 
      52               1 : virtual JSRuntime * createRuntime() {
      53               1 :     return JS_NewRuntime(512 * 1024);
      54                 : }
      55                 : 
      56               1 : virtual void destroyRuntime() {
      57               1 :     JS_DestroyRuntime(rt);
      58               1 : }
      59                 : 
      60               2 : END_TEST(testGCOutOfMemory)

Generated by: LCOV version 1.7