Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / js / src / jsapi-tests / testSlowScript.cpp
blob154120eed154be16c5ababfd68409dba9a1e96d5
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,
13 JS::Value* vp) {
14 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
15 if (!sRemain--) {
16 JS_RequestInterruptCallback(cx);
18 args.rval().setUndefined();
19 return true;
22 BEGIN_TEST(testSlowScript) {
23 JS_AddInterruptCallback(cx, InterruptCallback);
24 JS_DefineFunction(cx, global, "requestInterruptCallback",
25 RequestInterruptCallback, 0, 0);
27 CHECK(
28 test("while (true)"
29 " for (i in [0,0,0,0])"
30 " requestInterruptCallback();"));
32 CHECK(
33 test("while (true)"
34 " for (i in [0,0,0,0])"
35 " for (j in [0,0,0,0])"
36 " requestInterruptCallback();"));
38 CHECK(
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 CHECK(
46 test("function* f() { while (true) yield requestInterruptCallback() }"
47 "for (i of f()) ;"));
49 CHECK(
50 test("function* f() { while (true) yield 1 }"
51 "for (i of f())"
52 " requestInterruptCallback();"));
54 return true;
57 bool test(const char* bytes) {
58 JS::RootedValue v(cx);
60 sRemain = 0;
61 CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
62 CHECK(!JS_IsExceptionPending(cx));
63 JS_ClearPendingException(cx);
65 sRemain = 1000;
66 CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
67 CHECK(!JS_IsExceptionPending(cx));
68 JS_ClearPendingException(cx);
70 return true;
72 END_TEST(testSlowScript)