Skip to content

Commit f9e8942

Browse files
jdmsagudev
andauthored
Expose function to obtain a PropertyKey from a JSString. (#578)
* Expose function to obtain a PropertyKey from a JSString. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Add doc link. Co-authored-by: sagudev <16504129+sagudev@users.noreply.github.com> Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net> Co-authored-by: sagudev <16504129+sagudev@users.noreply.github.com>
1 parent 861c091 commit f9e8942

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

mozjs-sys/src/jsid.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ pub fn SymbolId(symbol: *mut Symbol) -> jsid {
4444
AsPropertyKey((symbol as usize) | (PropertyKeyTag::Symbol as usize))
4545
}
4646

47+
#[inline(always)]
48+
/// <https://searchfox.org/mozilla-central/rev/1f65969e57c757146e3e548614b49d3a4168eeb8/js/public/Id.h#183>
49+
pub fn StringId(s: *mut JSString) -> jsid {
50+
assert!(!s.is_null());
51+
assert_eq!((s as usize) & JSID_TYPE_MASK, 0);
52+
AsPropertyKey((s as usize) | (PropertyKeyTag::String as usize))
53+
}
54+
4755
impl jsid {
4856
#[inline(always)]
4957
fn asBits(&self) -> usize {

0 commit comments

Comments
 (0)