summaryrefslogtreecommitdiff
path: root/js/src/jsapi-tests/testSlowScript.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/jsapi-tests/testSlowScript.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloaduxp-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jsapi-tests/testSlowScript.cpp')
-rw-r--r--js/src/jsapi-tests/testSlowScript.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testSlowScript.cpp b/js/src/jsapi-tests/testSlowScript.cpp
new file mode 100644
index 0000000000..f4a706a6c1
--- /dev/null
+++ b/js/src/jsapi-tests/testSlowScript.cpp
@@ -0,0 +1,86 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "jsapi-tests/tests.h"
+
+static bool
+InterruptCallback(JSContext* cx)
+{
+ return false;
+}
+
+static unsigned sRemain;
+
+static bool
+RequestInterruptCallback(JSContext* cx, unsigned argc, jsval* vp)
+{
+ JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
+ if (!sRemain--)
+ JS_RequestInterruptCallback(cx);
+ args.rval().setUndefined();
+ return true;
+}
+
+BEGIN_TEST(testSlowScript)
+{
+ JS_AddInterruptCallback(cx, InterruptCallback);
+ JS_DefineFunction(cx, global, "requestInterruptCallback", RequestInterruptCallback, 0, 0);
+
+ test("while (true)"
+ " for (i in [0,0,0,0])"
+ " requestInterruptCallback();");
+
+ test("while (true)"
+ " for (i in [0,0,0,0])"
+ " for (j in [0,0,0,0])"
+ " requestInterruptCallback();");
+
+ test("while (true)"
+ " for (i in [0,0,0,0])"
+ " for (j in [0,0,0,0])"
+ " for (k in [0,0,0,0])"
+ " requestInterruptCallback();");
+
+ test("function f() { while (true) yield requestInterruptCallback() }"
+ "for (i in f()) ;");
+
+ test("function f() { while (true) yield 1 }"
+ "for (i in f())"
+ " requestInterruptCallback();");
+
+ test("(function() {"
+ " while (true)"
+ " let (x = 1) { eval('requestInterruptCallback()'); }"
+ "})()");
+
+ return true;
+}
+
+bool
+test(const char* bytes)
+{
+ jsval v;
+
+ JS_SetOptions(cx, JS_GetOptions(cx) & ~(JSOPTION_METHODJIT | JSOPTION_METHODJIT_ALWAYS));
+ sRemain = 0;
+ CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
+ CHECK(!JS_IsExceptionPending(cx));
+
+ sRemain = 1000;
+ CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
+ CHECK(!JS_IsExceptionPending(cx));
+
+ JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_METHODJIT | JSOPTION_METHODJIT_ALWAYS);
+
+ sRemain = 0;
+ CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
+ CHECK(!JS_IsExceptionPending(cx));
+
+ sRemain = 1000;
+ CHECK(!evaluate(bytes, __FILE__, __LINE__, &v));
+ CHECK(!JS_IsExceptionPending(cx));
+
+ return true;
+}
+END_TEST(testSlowScript)