static JSAtom * js_AtomizeHashedKey(JSContext *cx, jsval key, PRHashNumber keyHash, uintN flags) { PRHashTable *table; PRHashEntry *he, **hep; JSAtom *atom; PR_ASSERT(JS_IS_LOCKED(cx)); table = cx->runtime->atomState.table; hep = PR_HashTableRawLookup(table, keyHash, (void *)key); if ((he = *hep) == NULL) { he = PR_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL); if (!he) { JS_ReportOutOfMemory(cx); return NULL; } } atom = (JSAtom *)he; #ifdef DEBUG_DUPLICATE_ATOMS hep = PR_HashTableRawLookup(table, keyHash, (void *)key); he = *hep; PR_ASSERT(atom == (JSAtom *)he); #endif if (flags & ATOM_NOHOLD) return atom; return js_HoldAtom(cx, atom); }
jsatomid js_IndexAtom(JSContext *cx, JSAtom *atom, JSAtomList *al) { if (!(atom->flags & ATOM_INDEXED)) { atom->flags |= ATOM_INDEXED; atom->index = (jsatomid) al->count++; ATOM_SET_NEXT(atom, al->list); al->list = js_HoldAtom(cx, atom); } return atom->index; }
JSAtom * js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags) { jsdouble *dp; PRHashTable *table; PRHashNumber keyHash; jsval key; PRHashEntry *he, **hep; JSAtom *atom; #if PR_ALIGN_OF_DOUBLE == 8 dp = &d; #else char alignbuf[16]; dp = (jsdouble *)&alignbuf[8 - ((pruword)&alignbuf & 7)]; *dp = d; #endif PR_ASSERT(JS_IS_LOCKED(cx)); table = cx->runtime->atomState.table; keyHash = HASH_DOUBLE(dp); key = DOUBLE_TO_JSVAL(dp); hep = PR_HashTableRawLookup(table, keyHash, (void *)key); if ((he = *hep) == NULL) { if (!js_NewDoubleValue(cx, d, &key)) return NULL; he = PR_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL); if (!he) { JS_ReportOutOfMemory(cx); return NULL; } } atom = (JSAtom *)he; #ifdef DEBUG_DUPLICATE_ATOMS hep = PR_HashTableRawLookup(table, keyHash, (void *)key); he = *hep; PR_ASSERT(atom == (JSAtom *)he); #endif if (flags & ATOM_NOHOLD) return atom; return js_HoldAtom(cx, atom); }
js_alloc_symbol(void *priv, const void *key) { JSContext *cx; JSSymbol *sym; JSAtom *atom; cx = priv; PR_ASSERT(JS_IS_LOCKED(cx)); sym = JS_malloc(cx, sizeof(JSSymbol)); if (!sym) return NULL; sym->entry.key = key; if (!JSVAL_IS_INT((jsval)key)) { atom = (JSAtom *)key; js_HoldAtom(cx, atom); } return &sym->entry; }
JSAtom * js_AtomizeString(JSContext *cx, JSString *str, uintN flags) { PRHashTable *table; PRHashNumber keyHash; jsval key; PRHashEntry *he, **hep; JSAtom *atom; PR_ASSERT(JS_IS_LOCKED(cx)); table = cx->runtime->atomState.table; keyHash = js_HashString(str); key = STRING_TO_JSVAL(str); hep = PR_HashTableRawLookup(table, keyHash, (void *)key); if ((he = *hep) == NULL) { if (flags & ATOM_TMPSTR) { if (flags & ATOM_NOCOPY) str = js_NewString(cx, str->chars, str->length, 0); else str = js_NewStringCopyN(cx, str->chars, str->length, 0); if (!str) return NULL; key = STRING_TO_JSVAL(str); } he = PR_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL); if (!he) { JS_ReportOutOfMemory(cx); return NULL; } } atom = (JSAtom *)he; #ifdef DEBUG_DUPLICATE_ATOMS hep = PR_HashTableRawLookup(table, keyHash, (void *)key); he = *hep; PR_ASSERT(atom == (JSAtom *)he); #endif if (flags & ATOM_NOHOLD) return atom; return js_HoldAtom(cx, atom); }