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 "js/PropertyAndElement.h" // JS_DefineFunction
6 #include "jsapi-tests/tests.h"
8 static bool InterruptCallback(JSContext
* cx
) { return false; }
10 static unsigned sRemain
;
12 static bool RequestInterruptCallback(JSContext
* cx
, unsigned argc
,
14 JS::CallArgs args
= JS::CallArgsFromVp(argc
, vp
);
16 JS_RequestInterruptCallback(cx
);
18 args
.rval().setUndefined();
22 BEGIN_TEST(testSlowScript
) {
23 JS_AddInterruptCallback(cx
, InterruptCallback
);
24 JS_DefineFunction(cx
, global
, "requestInterruptCallback",
25 RequestInterruptCallback
, 0, 0);
29 " for (i in [0,0,0,0])"
30 " requestInterruptCallback();"));
34 " for (i in [0,0,0,0])"
35 " for (j in [0,0,0,0])"
36 " requestInterruptCallback();"));
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();"));
46 test("function* f() { while (true) yield requestInterruptCallback() }"
50 test("function* f() { while (true) yield 1 }"
52 " requestInterruptCallback();"));
57 bool test(const char* bytes
) {
58 JS::RootedValue
v(cx
);
61 CHECK(!evaluate(bytes
, __FILE__
, __LINE__
, &v
));
62 CHECK(!JS_IsExceptionPending(cx
));
63 JS_ClearPendingException(cx
);
66 CHECK(!evaluate(bytes
, __FILE__
, __LINE__
, &v
));
67 CHECK(!JS_IsExceptionPending(cx
));
68 JS_ClearPendingException(cx
);
72 END_TEST(testSlowScript
)