Bug 1364816 part 4. Add a JS friend API for getting an jsid from a known-atom JSString*. r=jandem

This commit is contained in:
Boris Zbarsky 2017-06-06 21:21:44 -04:00
parent 60d80c3c4e
commit d6c61dbb66
2 changed files with 16 additions and 0 deletions

View File

@ -1302,6 +1302,12 @@ js::detail::IdMatchesAtom(jsid id, JSAtom* atom)
return id == INTERNED_STRING_TO_JSID(nullptr, atom);
}
bool
js::detail::IdMatchesAtom(jsid id, JSString* atom)
{
return id == INTERNED_STRING_TO_JSID(nullptr, atom);
}
JS_FRIEND_API(void)
js::PrepareScriptEnvironmentAndInvoke(JSContext* cx, HandleObject scope, ScriptEnvironmentPreparer::Closure& closure)
{

View File

@ -2602,6 +2602,7 @@ JSID_FROM_BITS(size_t bits)
namespace js {
namespace detail {
bool IdMatchesAtom(jsid id, JSAtom* atom);
bool IdMatchesAtom(jsid id, JSString* atom);
} // namespace detail
} // namespace js
@ -2635,6 +2636,15 @@ NON_INTEGER_ATOM_TO_JSID(JSAtom* atom)
return id;
}
static MOZ_ALWAYS_INLINE jsid
NON_INTEGER_ATOM_TO_JSID(JSString* atom)
{
MOZ_ASSERT(((size_t)atom & 0x7) == 0);
jsid id = JSID_FROM_BITS((size_t)atom);
MOZ_ASSERT(js::detail::IdMatchesAtom(id, atom));
return id;
}
/* All strings stored in jsids are atomized, but are not necessarily property names. */
static MOZ_ALWAYS_INLINE bool
JSID_IS_ATOM(jsid id)