Bug 1364816 part 4. Add a JS friend API for getting an jsid from a known-atom JSString*. r=jandem
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 06 Jun 2017 21:21:44 -0400
changeset 410743 79157ef8e455f91349e4bf5c73c13f5ecb9b63cf
parent 410742 ab1e672183ad4d6c44d8d1c8d73b9e6a1e8e3d54
child 410744 2d37f2bce087264116abf04a5133fbd3b031507c
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1364816
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1364816 part 4. Add a JS friend API for getting an jsid from a known-atom JSString*. r=jandem
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -1297,16 +1297,22 @@ js::GetDOMProxyShadowsCheck()
 }
 
 bool
 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)
 {
     MOZ_ASSERT(!cx->isExceptionPending());
 
     MOZ_RELEASE_ASSERT(cx->runtime()->scriptEnvironmentPreparer,
                        "Embedding needs to set a scriptEnvironmentPreparer callback");
 
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -2597,16 +2597,17 @@ JSID_FROM_BITS(size_t bits)
     jsid id;
     JSID_BITS(id) = bits;
     return id;
 }
 
 namespace js {
 namespace detail {
 bool IdMatchesAtom(jsid id, JSAtom* atom);
+bool IdMatchesAtom(jsid id, JSString* atom);
 } // namespace detail
 } // namespace js
 
 /**
  * Must not be used on atoms that are representable as integer jsids.
  * Prefer NameToId or AtomToId over this function:
  *
  * A PropertyName is an atom that does not contain an integer in the range
@@ -2630,16 +2631,25 @@ static MOZ_ALWAYS_INLINE jsid
 NON_INTEGER_ATOM_TO_JSID(JSAtom* 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;
 }
 
+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)
 {
     return JSID_IS_STRING(id);
 }
 
 static MOZ_ALWAYS_INLINE bool