|
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/. */ |
|
4 |
|
5 #include "jsapi-tests/tests.h" |
|
6 |
|
7 static bool |
|
8 InterruptCallback(JSContext *cx) |
|
9 { |
|
10 return false; |
|
11 } |
|
12 |
|
13 static unsigned sRemain; |
|
14 |
|
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 } |
|
24 |
|
25 BEGIN_TEST(testSlowScript) |
|
26 { |
|
27 JS_SetInterruptCallback(cx, InterruptCallback); |
|
28 JS_DefineFunction(cx, global, "requestInterruptCallback", RequestInterruptCallback, 0, 0); |
|
29 |
|
30 test("while (true)" |
|
31 " for (i in [0,0,0,0])" |
|
32 " requestInterruptCallback();"); |
|
33 |
|
34 test("while (true)" |
|
35 " for (i in [0,0,0,0])" |
|
36 " for (j in [0,0,0,0])" |
|
37 " requestInterruptCallback();"); |
|
38 |
|
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();"); |
|
44 |
|
45 test("function f() { while (true) yield requestInterruptCallback() }" |
|
46 "for (i in f()) ;"); |
|
47 |
|
48 test("function f() { while (true) yield 1 }" |
|
49 "for (i in f())" |
|
50 " requestInterruptCallback();"); |
|
51 |
|
52 test("(function() {" |
|
53 " while (true)" |
|
54 " let (x = 1) { eval('requestInterruptCallback()'); }" |
|
55 "})()"); |
|
56 |
|
57 return true; |
|
58 } |
|
59 |
|
60 bool |
|
61 test(const char *bytes) |
|
62 { |
|
63 jsval v; |
|
64 |
|
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)); |
|
69 |
|
70 sRemain = 1000; |
|
71 CHECK(!evaluate(bytes, __FILE__, __LINE__, &v)); |
|
72 CHECK(!JS_IsExceptionPending(cx)); |
|
73 |
|
74 JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_METHODJIT | JSOPTION_METHODJIT_ALWAYS); |
|
75 |
|
76 sRemain = 0; |
|
77 CHECK(!evaluate(bytes, __FILE__, __LINE__, &v)); |
|
78 CHECK(!JS_IsExceptionPending(cx)); |
|
79 |
|
80 sRemain = 1000; |
|
81 CHECK(!evaluate(bytes, __FILE__, __LINE__, &v)); |
|
82 CHECK(!JS_IsExceptionPending(cx)); |
|
83 |
|
84 return true; |
|
85 } |
|
86 END_TEST(testSlowScript) |