Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 29ec75b

Browse files
author
Mihai Alexandru Michis
committed
Backed out changeset 52f41e8893b6 (bug 1669306) for causing failures in RootingAPI.h
CLOSED TREE
1 parent 109e8c7 commit 29ec75b

4 files changed

Lines changed: 22 additions & 74 deletions

File tree

js/src/jsapi-tests/testGCOutOfMemory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,6 @@ virtual JSContext* createContext() override {
7373
return cx;
7474
}
7575

76+
virtual void destroyContext() override { JS_DestroyContext(cx); }
77+
7678
END_TEST(testGCOutOfMemory)

js/src/jsapi-tests/testOOM.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,10 @@ BEGIN_TEST(testHelperThreadOOM) {
101101
}
102102

103103
bool init() override {
104-
JSAPITest::uninit(); // Discard the just-created JSContext.
105-
js::DestroyHelperThreadsState(); // The test creates this state.
104+
js::DestroyHelperThreadsState();
106105
return true;
107106
}
108-
void uninit() override {
109-
// Leave things initialized after this test finishes.
110-
js::CreateHelperThreadsState();
111-
}
107+
void uninit() override { js::CreateHelperThreadsState(); }
112108

113109
END_TEST(testHelperThreadOOM)
114110

js/src/jsapi-tests/tests.cpp

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,7 @@
1717

1818
JSAPITest* JSAPITest::list;
1919

20-
bool JSAPITest::init(JSContext* maybeReusableContext) {
21-
if (maybeReusableContext && reuseGlobal) {
22-
cx = maybeReusableContext;
23-
global.init(cx, cx->global());
24-
return init();
25-
}
26-
27-
MaybeFreeContext(maybeReusableContext);
28-
20+
bool JSAPITest::init() {
2921
cx = createContext();
3022
if (!cx) {
3123
return false;
@@ -40,32 +32,18 @@ bool JSAPITest::init(JSContext* maybeReusableContext) {
4032
return false;
4133
}
4234
JS::EnterRealm(cx, global);
43-
return init();
35+
return true;
4436
}
4537

46-
JSContext* JSAPITest::maybeForgetContext() {
47-
if (!reuseGlobal) {
48-
return nullptr;
38+
void JSAPITest::uninit() {
39+
if (global) {
40+
JS::LeaveRealm(cx, nullptr);
41+
global = nullptr;
4942
}
50-
51-
JSContext* reusableCx = cx;
52-
global.reset();
53-
cx = nullptr;
54-
return reusableCx;
55-
}
56-
57-
/* static */
58-
void JSAPITest::MaybeFreeContext(JSContext* maybeCx) {
59-
if (maybeCx) {
60-
JS::LeaveRealm(maybeCx, nullptr);
61-
JS_DestroyContext(maybeCx);
43+
if (cx) {
44+
destroyContext();
45+
cx = nullptr;
6246
}
63-
}
64-
65-
void JSAPITest::uninit() {
66-
global.reset();
67-
MaybeFreeContext(cx);
68-
cx = nullptr;
6947
msgs.clear();
7048
}
7149

@@ -134,17 +112,6 @@ int main(int argc, char* argv[]) {
134112
return 1;
135113
}
136114

137-
if (filter && strcmp(filter, "--list") == 0) {
138-
for (JSAPITest* test = JSAPITest::list; test; test = test->next) {
139-
printf("%s\n", test->name());
140-
}
141-
return 0;
142-
}
143-
144-
// Reinitializing the global for every test is quite slow, due to having to
145-
// recompile all self-hosted builtins. Allow tests to opt-in to reusing the
146-
// global.
147-
JSContext* maybeReusedContext = nullptr;
148115
for (JSAPITest* test = JSAPITest::list; test; test = test->next) {
149116
const char* name = test->name();
150117
if (filter && strstr(name, filter) == nullptr) {
@@ -154,7 +121,7 @@ int main(int argc, char* argv[]) {
154121
total += 1;
155122

156123
printf("%s\n", name);
157-
if (!test->init(maybeReusedContext)) {
124+
if (!test->init()) {
158125
printf("TEST-UNEXPECTED-FAIL | %s | Failed to initialize.\n", name);
159126
failures++;
160127
test->uninit();
@@ -172,13 +139,8 @@ int main(int argc, char* argv[]) {
172139
failures++;
173140
}
174141
}
175-
176-
// Return a non-nullptr pointer if the context & global can safely be
177-
// reused for the next test.
178-
maybeReusedContext = test->maybeForgetContext();
179142
test->uninit();
180143
}
181-
JSAPITest::MaybeFreeContext(maybeReusedContext);
182144

183145
MOZ_RELEASE_ASSERT(!JSRuntime::hasLiveRuntimes());
184146
JS_ShutDown();

js/src/jsapi-tests/tests.h

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,7 @@ class JSAPITest {
7777
bool knownFail;
7878
JSAPITestString msgs;
7979

80-
// Whether this test is willing to skip its init() and reuse a global (and
81-
// JSContext etc.) from a previous test that also has reuseGlobal=true. It
82-
// also means this test is willing to skip its uninit() if it is followed by
83-
// another reuseGlobal test.
84-
bool reuseGlobal;
85-
86-
JSAPITest() : cx(nullptr), knownFail(false), reuseGlobal(false) {
80+
JSAPITest() : cx(nullptr), knownFail(false) {
8781
next = list;
8882
list = this;
8983
}
@@ -93,19 +87,7 @@ class JSAPITest {
9387
MOZ_RELEASE_ASSERT(!global);
9488
}
9589

96-
// Initialize this test, possibly with the cx from a previously run test.
97-
bool init(JSContext* maybeReusedContext);
98-
99-
// If this test is ok with its cx and global being reused, release this
100-
// test's cx to be reused by another test.
101-
JSContext* maybeForgetContext();
102-
103-
static void MaybeFreeContext(JSContext* maybeCx);
104-
105-
// The real initialization happens in init(JSContext*), above, but this
106-
// method may be overridden to perform additional initialization after the
107-
// JSContext and global have been created.
108-
virtual bool init() { return true; }
90+
virtual bool init();
10991
virtual void uninit();
11092

11193
virtual const char* name() = 0;
@@ -371,6 +353,12 @@ class JSAPITest {
371353
return cx;
372354
}
373355

356+
virtual void destroyContext() {
357+
MOZ_RELEASE_ASSERT(cx);
358+
JS_DestroyContext(cx);
359+
cx = nullptr;
360+
}
361+
374362
static void reportWarning(JSContext* cx, JSErrorReport* report) {
375363
MOZ_RELEASE_ASSERT(report->isWarning());
376364

0 commit comments

Comments
 (0)