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); }
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_hash_scope_add(JSContext *cx, JSScope *scope, jsval id, JSProperty *prop) { PRHashTable *table = scope->data; const void *key; PRHashNumber keyHash; PRHashEntry **hep; JSSymbol *sym, **sp; PR_ASSERT(JS_IS_LOCKED(cx)); table->allocPriv = cx; key = (const void *)id; keyHash = js_hash_id(key); hep = PR_HashTableRawLookup(table, keyHash, key); sym = (JSSymbol *) *hep; SCOPE_ADD( sym = (JSSymbol *) PR_HashTableRawAdd(table, hep, keyHash, key, NULL); if (!sym) return NULL; );
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); }
js_hash_scope_add(JSContext *cx, JSScope *scope, jsid id, JSScopeProperty *sprop) { PRHashTable *table = scope->data; const void *key; prhashcode keyHash; PRHashEntry **hep; JSSymbol *sym, **sp; JSScopePrivate *priv; PR_ASSERT(JS_IS_SCOPE_LOCKED(scope)); priv = table->allocPriv; priv->context = cx; key = (const void *)id; keyHash = js_hash_id(key); hep = PR_HashTableRawLookup(table, keyHash, key); sym = (JSSymbol *) *hep; SCOPE_ADD(priv, sym = (JSSymbol *) PR_HashTableRawAdd(table, hep, keyHash, key, NULL); if (!sym) return NULL; );
static PRHashEntry * MarkSharpObjects(JSContext *cx, JSObject *obj) { JSSharpObjectMap *map; PRHashTable *table; PRHashNumber hash; PRHashEntry **hep, *he; jsatomid sharpid; JSProperty *prop; jsval val; map = &cx->sharpObjectMap; table = map->table; hash = js_hash_object(obj); hep = PR_HashTableRawLookup(table, hash, obj); he = *hep; if (!he) { sharpid = 0; he = PR_HashTableRawAdd(table, hep, hash, obj, (void *)sharpid); if (!he) { JS_ReportOutOfMemory(cx); return NULL; } for (prop = obj->map->props; prop; prop = prop->next) { if (!prop->symbols || !(prop->flags & JSPROP_ENUMERATE)) continue; val = prop->object->slots[prop->slot]; if (JSVAL_IS_OBJECT(val) && val != JSVAL_NULL) (void) MarkSharpObjects(cx, JSVAL_TO_OBJECT(val)); } } else { sharpid = (jsatomid) he->value; if (sharpid == 0) { sharpid = ++map->sharpgen << 1; he->value = (void *) sharpid; } } return he; }