uint32_t GetIndexFromString(JSString *str) { // Masks the return value UINT32_MAX as failure to get the index. // I.e. it is impossible to distinguish between failing to get the index // or the actual index UINT32_MAX. if (!str->isAtom()) return UINT32_MAX; uint32_t index; JSAtom *atom = &str->asAtom(); if (!atom->isIndex(&index)) return UINT32_MAX; return index; }
const StructField * StructTypeRepresentation::fieldNamed(jsid id) const { if (!JSID_IS_ATOM(id)) return nullptr; uint32_t unused; JSAtom *atom = JSID_TO_ATOM(id); if (atom->isIndex(&unused)) return nullptr; PropertyName *name = atom->asPropertyName(); for (size_t i = 0; i < fieldCount(); i++) { if (field(i).propertyName.get() == name) return &field(i); } return nullptr; }