Bug 609440, part 4 - make JSString::chars() fallible (r=waldo,dvander,igor,dwitte,njn)
This commit is contained in:
@@ -457,17 +457,20 @@ js_SweepAtomState(JSContext *cx)
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
|
||||
js_AtomizeString(JSContext *cx, JSString *strArg, uintN flags)
|
||||
{
|
||||
JS_ASSERT(!(flags & ~(ATOM_PINNED|ATOM_INTERNED|ATOM_TMPSTR|ATOM_NOCOPY)));
|
||||
JS_ASSERT_IF(flags & ATOM_NOCOPY, flags & ATOM_TMPSTR);
|
||||
|
||||
if (str->isAtomized())
|
||||
return STRING_TO_ATOM(str);
|
||||
if (strArg->isAtomized())
|
||||
return STRING_TO_ATOM(strArg);
|
||||
|
||||
const jschar *chars;
|
||||
size_t length;
|
||||
str->getCharsAndLength(chars, length);
|
||||
JSLinearString *str = strArg->ensureLinear(cx);
|
||||
if (!str)
|
||||
return NULL;
|
||||
|
||||
const jschar *chars = str->chars();
|
||||
size_t length = str->length();
|
||||
|
||||
JSString *staticStr = JSString::lookupStaticString(chars, length);
|
||||
if (staticStr)
|
||||
@@ -482,7 +485,7 @@ js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
|
||||
/* Hashing the string should have flattened it if it was a rope. */
|
||||
JS_ASSERT(str->isFlat() || str->isDependent());
|
||||
|
||||
JSString *key;
|
||||
JSLinearString *key;
|
||||
if (p) {
|
||||
key = AtomEntryToKey(*p);
|
||||
} else {
|
||||
@@ -506,9 +509,8 @@ js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
|
||||
} else {
|
||||
if (needNewString) {
|
||||
SwitchToCompartment sc(cx, cx->runtime->defaultCompartment);
|
||||
jschar *chars = str->chars();
|
||||
if (flags & ATOM_NOCOPY) {
|
||||
key = js_NewString(cx, chars, length);
|
||||
key = js_NewString(cx, const_cast<jschar *>(str->flatChars()), length);
|
||||
if (!key)
|
||||
return NULL;
|
||||
|
||||
@@ -537,7 +539,6 @@ js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
|
||||
|
||||
AddAtomEntryFlags(*p, flags & (ATOM_PINNED | ATOM_INTERNED));
|
||||
|
||||
JS_ASSERT(key->isAtomized());
|
||||
JSAtom *atom = STRING_TO_ATOM(key);
|
||||
return atom;
|
||||
}
|
||||
@@ -607,7 +608,7 @@ js_GetExistingStringAtom(JSContext *cx, const jschar *chars, size_t length)
|
||||
state = &cx->runtime->atomState;
|
||||
|
||||
JS_LOCK(cx, &state->lock);
|
||||
AtomSet::Ptr p = state->atoms.lookup(&str);
|
||||
AtomSet::Ptr p = state->atoms.lookup(str.assertIsFlat());
|
||||
str2 = p ? AtomEntryToKey(*p) : NULL;
|
||||
JS_UNLOCK(cx, &state->lock);
|
||||
|
||||
@@ -628,7 +629,7 @@ js_DumpAtoms(JSContext *cx, FILE *fp)
|
||||
if (entry == 0) {
|
||||
fputs("<uninitialized>", fp);
|
||||
} else {
|
||||
JSString *key = AtomEntryToKey(entry);
|
||||
JSAtom *key = AtomEntryToKey(entry);
|
||||
FileEscapedString(fp, key, '"');
|
||||
uintN flags = AtomEntryFlags(entry);
|
||||
if (flags != 0) {
|
||||
|
||||
Reference in New Issue
Block a user