|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
3 * |
|
4 * Any copyright is dedicated to the Public Domain. |
|
5 * http://creativecommons.org/licenses/publicdomain/ |
|
6 * Contributor: Igor Bukanov |
|
7 */ |
|
8 |
|
9 #include "jsapi-tests/tests.h" |
|
10 |
|
11 static unsigned errorCount = 0; |
|
12 |
|
13 static void |
|
14 ErrorCounter(JSContext *cx, const char *message, JSErrorReport *report) |
|
15 { |
|
16 ++errorCount; |
|
17 } |
|
18 |
|
19 BEGIN_TEST(testGCOutOfMemory) |
|
20 { |
|
21 JS_SetErrorReporter(cx, ErrorCounter); |
|
22 |
|
23 JS::RootedValue root(cx); |
|
24 |
|
25 static const char source[] = |
|
26 "var max = 0; (function() {" |
|
27 " var array = [];" |
|
28 " for (; ; ++max)" |
|
29 " array.push({});" |
|
30 " array = []; array.push(0);" |
|
31 "})();"; |
|
32 bool ok = JS_EvaluateScript(cx, global, source, strlen(source), "", 1, &root); |
|
33 |
|
34 /* Check that we get OOM. */ |
|
35 CHECK(!ok); |
|
36 CHECK(!JS_IsExceptionPending(cx)); |
|
37 CHECK_EQUAL(errorCount, 1); |
|
38 JS_GC(rt); |
|
39 |
|
40 // Temporarily disabled to reopen the tree. Bug 847579. |
|
41 return true; |
|
42 |
|
43 EVAL("(function() {" |
|
44 " var array = [];" |
|
45 " for (var i = max >> 2; i != 0;) {" |
|
46 " --i;" |
|
47 " array.push({});" |
|
48 " }" |
|
49 "})();", &root); |
|
50 CHECK_EQUAL(errorCount, 1); |
|
51 return true; |
|
52 } |
|
53 |
|
54 virtual JSRuntime * createRuntime() { |
|
55 JSRuntime *rt = JS_NewRuntime(768 * 1024, JS_USE_HELPER_THREADS); |
|
56 if (!rt) |
|
57 return nullptr; |
|
58 setNativeStackQuota(rt); |
|
59 return rt; |
|
60 } |
|
61 |
|
62 virtual void destroyRuntime() { |
|
63 JS_DestroyRuntime(rt); |
|
64 } |
|
65 |
|
66 END_TEST(testGCOutOfMemory) |