Bug 1032726 part 2 - Make GetArrayIndexFromId work with Latin1 strings. r=bz,terrence

--HG--
extra : rebase_source : b6f8fe3df3946dfe05f5467c22c4fb157b6dcbf2
This commit is contained in:
Jan de Mooij 2014-07-02 15:45:02 +02:00
parent 4f5617c4c2
commit 7ee62a47c5
3 changed files with 42 additions and 15 deletions

View File

@ -9375,7 +9375,9 @@ class CGProxyNamedOperation(CGProxySpecialOperation):
unwrapString = fill(
"""
if (MOZ_LIKELY(JSID_IS_ATOM(${idName}))) {
${argName}.Rebind(js::GetAtomChars(JSID_TO_ATOM(${idName})), js::GetAtomLength(JSID_TO_ATOM(${idName})));
JS::AutoCheckCannotGC nogc;
JSAtom* atom = JSID_TO_ATOM(${idName});
${argName}.Rebind(js::GetTwoByteAtomChars(nogc, atom), js::GetAtomLength(atom));
} else {
nameVal = js::IdToValue(${idName});
$*{unwrapString}

View File

@ -155,7 +155,15 @@ GetArrayIndexFromId(JSContext* cx, JS::Handle<jsid> id)
}
if (MOZ_LIKELY(JSID_IS_ATOM(id))) {
JSAtom* atom = JSID_TO_ATOM(id);
jschar s = *js::GetAtomChars(atom);
jschar s;
{
JS::AutoCheckCannotGC nogc;
if (js::AtomHasLatin1Chars(atom)) {
s = *js::GetLatin1AtomChars(nogc, atom);
} else {
s = *js::GetTwoByteAtomChars(nogc, atom);
}
}
if (MOZ_LIKELY((unsigned)s >= 'a' && (unsigned)s <= 'z'))
return -1;

View File

@ -761,25 +761,42 @@ GetObjectSlot(JSObject *obj, size_t slot)
return reinterpret_cast<const shadow::Object *>(obj)->slotRef(slot);
}
inline const jschar *
GetAtomChars(JSAtom *atom)
{
using shadow::Atom;
Atom *atom_ = reinterpret_cast<Atom *>(atom);
JS_ASSERT(!(atom_->flags & Atom::LATIN1_CHARS_BIT));
if (atom_->flags & Atom::INLINE_CHARS_BIT) {
char *p = reinterpret_cast<char *>(atom);
return reinterpret_cast<const jschar *>(p + offsetof(Atom, inlineStorageTwoByte));
}
return atom_->nonInlineCharsTwoByte;
}
inline size_t
GetAtomLength(JSAtom *atom)
{
return reinterpret_cast<shadow::Atom*>(atom)->length;
}
inline bool
AtomHasLatin1Chars(JSAtom *atom)
{
return reinterpret_cast<shadow::Atom *>(atom)->flags & shadow::Atom::LATIN1_CHARS_BIT;
}
inline const JS::Latin1Char *
GetLatin1AtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom)
{
MOZ_ASSERT(AtomHasLatin1Chars(atom));
using shadow::Atom;
Atom *atom_ = reinterpret_cast<Atom *>(atom);
if (atom_->flags & Atom::INLINE_CHARS_BIT)
return atom_->inlineStorageLatin1;
return atom_->nonInlineCharsLatin1;
}
inline const jschar *
GetTwoByteAtomChars(const JS::AutoCheckCannotGC &nogc, JSAtom *atom)
{
MOZ_ASSERT(!AtomHasLatin1Chars(atom));
using shadow::Atom;
Atom *atom_ = reinterpret_cast<Atom *>(atom);
if (atom_->flags & Atom::INLINE_CHARS_BIT)
return atom_->inlineStorageTwoByte;
return atom_->nonInlineCharsTwoByte;
}
inline JSLinearString *
AtomToLinearString(JSAtom *atom)
{