1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsapi-tests/testSlowScript.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "jsapi-tests/tests.h" 1.9 + 1.10 +static bool 1.11 +InterruptCallback(JSContext *cx) 1.12 +{ 1.13 + return false; 1.14 +} 1.15 + 1.16 +static unsigned sRemain; 1.17 + 1.18 +static bool 1.19 +RequestInterruptCallback(JSContext *cx, unsigned argc, jsval *vp) 1.20 +{ 1.21 + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); 1.22 + if (!sRemain--) 1.23 + JS_RequestInterruptCallback(JS_GetRuntime(cx)); 1.24 + args.rval().setUndefined(); 1.25 + return true; 1.26 +} 1.27 + 1.28 +BEGIN_TEST(testSlowScript) 1.29 +{ 1.30 + JS_SetInterruptCallback(cx, InterruptCallback); 1.31 + JS_DefineFunction(cx, global, "requestInterruptCallback", RequestInterruptCallback, 0, 0); 1.32 + 1.33 + test("while (true)" 1.34 + " for (i in [0,0,0,0])" 1.35 + " requestInterruptCallback();"); 1.36 + 1.37 + test("while (true)" 1.38 + " for (i in [0,0,0,0])" 1.39 + " for (j in [0,0,0,0])" 1.40 + " requestInterruptCallback();"); 1.41 + 1.42 + test("while (true)" 1.43 + " for (i in [0,0,0,0])" 1.44 + " for (j in [0,0,0,0])" 1.45 + " for (k in [0,0,0,0])" 1.46 + " requestInterruptCallback();"); 1.47 + 1.48 + test("function f() { while (true) yield requestInterruptCallback() }" 1.49 + "for (i in f()) ;"); 1.50 + 1.51 + test("function f() { while (true) yield 1 }" 1.52 + "for (i in f())" 1.53 + " requestInterruptCallback();"); 1.54 + 1.55 + test("(function() {" 1.56 + " while (true)" 1.57 + " let (x = 1) { eval('requestInterruptCallback()'); }" 1.58 + "})()"); 1.59 + 1.60 + return true; 1.61 +} 1.62 + 1.63 +bool 1.64 +test(const char *bytes) 1.65 +{ 1.66 + jsval v; 1.67 + 1.68 + JS_SetOptions(cx, JS_GetOptions(cx) & ~(JSOPTION_METHODJIT | JSOPTION_METHODJIT_ALWAYS)); 1.69 + sRemain = 0; 1.70 + CHECK(!evaluate(bytes, __FILE__, __LINE__, &v)); 1.71 + CHECK(!JS_IsExceptionPending(cx)); 1.72 + 1.73 + sRemain = 1000; 1.74 + CHECK(!evaluate(bytes, __FILE__, __LINE__, &v)); 1.75 + CHECK(!JS_IsExceptionPending(cx)); 1.76 + 1.77 + JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_METHODJIT | JSOPTION_METHODJIT_ALWAYS); 1.78 + 1.79 + sRemain = 0; 1.80 + CHECK(!evaluate(bytes, __FILE__, __LINE__, &v)); 1.81 + CHECK(!JS_IsExceptionPending(cx)); 1.82 + 1.83 + sRemain = 1000; 1.84 + CHECK(!evaluate(bytes, __FILE__, __LINE__, &v)); 1.85 + CHECK(!JS_IsExceptionPending(cx)); 1.86 + 1.87 + return true; 1.88 +} 1.89 +END_TEST(testSlowScript)