mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 726429 - Handle GC during string table initialization (r=luke)
This commit is contained in:
parent
e81969c7a7
commit
9a4c1b313e
@ -67,6 +67,7 @@ CPPSRCS = \
|
||||
testFuncCallback.cpp \
|
||||
testFunctionProperties.cpp \
|
||||
testGCOutOfMemory.cpp \
|
||||
testOOM.cpp \
|
||||
testGetPropertyDefault.cpp \
|
||||
testIndexToString.cpp \
|
||||
testIntString.cpp \
|
||||
|
19
js/src/jsapi-tests/testOOM.cpp
Normal file
19
js/src/jsapi-tests/testOOM.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "tests.h"
|
||||
|
||||
BEGIN_TEST(testOOM)
|
||||
{
|
||||
JSString *jsstr = JS_ValueToString(cx, INT_TO_JSVAL(9));
|
||||
jsval tmp = STRING_TO_JSVAL(jsstr);
|
||||
JS_SetProperty(cx, global, "rootme", &tmp);
|
||||
const jschar *s = JS_GetStringCharsZ(cx, jsstr);
|
||||
JS_ASSERT(s[0] == '9' && s[1] == '\0');
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual JSRuntime * createRuntime()
|
||||
{
|
||||
JSRuntime *rt = JS_NewRuntime(0);
|
||||
JS_SetGCParameter(rt, JSGC_MAX_BYTES, (uint32_t)-1);
|
||||
return rt;
|
||||
}
|
||||
END_TEST(testOOM)
|
@ -491,27 +491,29 @@ StaticStrings::init(JSContext *cx)
|
||||
}
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
StaticStrings::trace(JSTracer *trc)
|
||||
{
|
||||
if (!initialized)
|
||||
return;
|
||||
|
||||
/* These strings never change, so barriers are not needed. */
|
||||
|
||||
for (uint32_t i = 0; i < UNIT_STATIC_LIMIT; i++)
|
||||
MarkStringUnbarriered(trc, unitStaticTable[i], "unit-static-string");
|
||||
for (uint32_t i = 0; i < UNIT_STATIC_LIMIT; i++) {
|
||||
if (JSAtom *atom = unitStaticTable[i])
|
||||
MarkStringUnbarriered(trc, atom, "unit-static-string");
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < NUM_SMALL_CHARS * NUM_SMALL_CHARS; i++)
|
||||
MarkStringUnbarriered(trc, length2StaticTable[i], "length2-static-string");
|
||||
for (uint32_t i = 0; i < NUM_SMALL_CHARS * NUM_SMALL_CHARS; i++) {
|
||||
if (JSAtom *atom = length2StaticTable[i])
|
||||
MarkStringUnbarriered(trc, atom, "length2-static-string");
|
||||
}
|
||||
|
||||
/* This may mark some strings more than once, but so be it. */
|
||||
for (uint32_t i = 0; i < INT_STATIC_LIMIT; i++)
|
||||
MarkStringUnbarriered(trc, intStaticTable[i], "int-static-string");
|
||||
for (uint32_t i = 0; i < INT_STATIC_LIMIT; i++) {
|
||||
if (JSAtom *atom = intStaticTable[i])
|
||||
MarkStringUnbarriered(trc, atom, "int-static-string");
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -696,8 +696,6 @@ namespace js {
|
||||
class StaticStrings
|
||||
{
|
||||
private:
|
||||
bool initialized;
|
||||
|
||||
/* Bigger chars cannot be in a length-2 string. */
|
||||
static const size_t SMALL_CHAR_LIMIT = 128U;
|
||||
static const size_t NUM_SMALL_CHARS = 64U;
|
||||
@ -712,7 +710,11 @@ class StaticStrings
|
||||
static const size_t UNIT_STATIC_LIMIT = 256U;
|
||||
JSAtom *unitStaticTable[UNIT_STATIC_LIMIT];
|
||||
|
||||
StaticStrings() : initialized(false) {}
|
||||
StaticStrings() {
|
||||
PodArrayZero(unitStaticTable);
|
||||
PodArrayZero(length2StaticTable);
|
||||
PodArrayZero(intStaticTable);
|
||||
}
|
||||
|
||||
bool init(JSContext *cx);
|
||||
void trace(JSTracer *trc);
|
||||
|
Loading…
Reference in New Issue
Block a user