js/src/jsapi-tests/testSlowScript.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "jsapi-tests/tests.h"
     7 static bool
     8 InterruptCallback(JSContext *cx)
     9 {
    10     return false;
    11 }
    13 static unsigned sRemain;
    15 static bool
    16 RequestInterruptCallback(JSContext *cx, unsigned argc, jsval *vp)
    17 {
    18     JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    19     if (!sRemain--)
    20         JS_RequestInterruptCallback(JS_GetRuntime(cx));
    21     args.rval().setUndefined();
    22     return true;
    23 }
    25 BEGIN_TEST(testSlowScript)
    26 {
    27     JS_SetInterruptCallback(cx, InterruptCallback);
    28     JS_DefineFunction(cx, global, "requestInterruptCallback", RequestInterruptCallback, 0, 0);
    30     test("while (true)"
    31          "  for (i in [0,0,0,0])"
    32          "    requestInterruptCallback();");
    34     test("while (true)"
    35          "  for (i in [0,0,0,0])"
    36          "    for (j in [0,0,0,0])"
    37          "      requestInterruptCallback();");
    39     test("while (true)"
    40          "  for (i in [0,0,0,0])"
    41          "    for (j in [0,0,0,0])"
    42          "      for (k in [0,0,0,0])"
    43          "        requestInterruptCallback();");
    45     test("function f() { while (true) yield requestInterruptCallback() }"
    46          "for (i in f()) ;");
    48     test("function f() { while (true) yield 1 }"
    49          "for (i in f())"
    50          "  requestInterruptCallback();");
    52     test("(function() {"
    53          "  while (true)"
    54          "    let (x = 1) { eval('requestInterruptCallback()'); }"
    55          "})()");
    57     return true;
    58 }
    60 bool
    61 test(const char *bytes)
    62 {
    63     jsval v;
    65     JS_SetOptions(cx, JS_GetOptions(cx) & ~(JSOPTION_METHODJIT | JSOPTION_METHODJIT_ALWAYS));
    66     sRemain = 0;
    67     CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
    68     CHECK(!JS_IsExceptionPending(cx));
    70     sRemain = 1000;
    71     CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
    72     CHECK(!JS_IsExceptionPending(cx));
    74     JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_METHODJIT | JSOPTION_METHODJIT_ALWAYS);
    76     sRemain = 0;
    77     CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
    78     CHECK(!JS_IsExceptionPending(cx));
    80     sRemain = 1000;
    81     CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
    82     CHECK(!JS_IsExceptionPending(cx));
    84     return true;
    85 }
    86 END_TEST(testSlowScript)

mercurial