static JSBool IndexToValue(JSContext *cx, jsuint length, jsval *vp) { if (length <= JSVAL_INT_MAX) { *vp = INT_TO_JSVAL(length); return JS_TRUE; } return js_NewDoubleValue(cx, (jsdouble)length, vp); }
JSAtom * js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags) { jsdouble *dp; JSHashNumber keyHash; jsval key; JSAtomState *state; JSHashTable *table; JSHashEntry *he, **hep; JSAtom *atom; char buf[2 * ALIGNMENT(double)]; dp = ALIGN(buf, double); *dp = d; keyHash = HASH_DOUBLE(dp); key = DOUBLE_TO_JSVAL(dp); state = &cx->runtime->atomState; JS_LOCK(&state->lock, cx); table = state->table; hep = JS_HashTableRawLookup(table, keyHash, (void *)key); if ((he = *hep) == NULL) { #ifdef JS_THREADSAFE uint32 gen = state->tablegen; #endif JS_UNLOCK(&state->lock,cx); if (!js_NewDoubleValue(cx, d, &key)) return NULL; JS_LOCK(&state->lock, cx); #ifdef JS_THREADSAFE if (state->tablegen != gen) { hep = JS_HashTableRawLookup(table, keyHash, (void *)key); if ((he = *hep) != NULL) { atom = (JSAtom *)he; goto out; } } #endif he = JS_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL); if (!he) { JS_ReportOutOfMemory(cx); atom = NULL; goto out; } } atom = (JSAtom *)he; atom->flags |= flags; cx->lastAtom = atom; out: JS_UNLOCK(&state->lock,cx); return 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); }