Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / js / src / vm / Id.cpp
blobfd56084e23435ebf381cb39b0f137a19e1e90e84
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "js/Id.h"
8 #include "js/RootingAPI.h"
10 #include "vm/JSContext.h"
11 #include "vm/SymbolType.h"
13 #include "vm/JSAtomUtils-inl.h" // AtomToId
15 using namespace js;
17 static const JS::PropertyKey voidKeyValue = JS::PropertyKey::Void();
19 const JS::HandleId JS::VoidHandlePropertyKey =
20 JS::HandleId::fromMarkedLocation(&voidKeyValue);
22 bool JS::PropertyKey::isPrivateName() const {
23 return isSymbol() && toSymbol()->isPrivateName();
26 bool JS::PropertyKey::isWellKnownSymbol(JS::SymbolCode code) const {
27 MOZ_ASSERT(uint32_t(code) < WellKnownSymbolLimit);
28 if (!isSymbol()) {
29 return false;
31 return toSymbol()->code() == code;
34 /* static */ JS::PropertyKey JS::PropertyKey::fromPinnedString(JSString* str) {
35 MOZ_ASSERT(AtomIsPinned(TlsContext.get(), &str->asAtom()));
36 return js::AtomToId(&str->asAtom());
39 /* static */ bool JS::PropertyKey::isNonIntAtom(JSAtom* atom) {
40 uint32_t index;
41 if (!atom->isIndex(&index)) {
42 return true;
44 static_assert(PropertyKey::IntMin == 0);
45 return index > PropertyKey::IntMax;
48 /* static */ bool JS::PropertyKey::isNonIntAtom(JSString* str) {
49 return JS::PropertyKey::isNonIntAtom(&str->asAtom());