JSBool js_InitAtomState(JSRuntime *rt) { JSAtomState *state = &rt->atomState; /* * The caller must zero the state before calling this function. */ JS_ASSERT(!state->stringAtoms.ops); JS_ASSERT(!state->doubleAtoms.ops); if (!JS_DHashTableInit(&state->stringAtoms, &StringHashOps, NULL, sizeof(JSAtomHashEntry), JS_DHASH_DEFAULT_CAPACITY(JS_STRING_HASH_COUNT))) { state->stringAtoms.ops = NULL; return JS_FALSE; } JS_ASSERT(IS_STRING_TABLE(&state->stringAtoms)); if (!JS_DHashTableInit(&state->doubleAtoms, &DoubleHashOps, NULL, sizeof(JSAtomHashEntry), JS_DHASH_DEFAULT_CAPACITY(JS_DOUBLE_HASH_COUNT))) { state->doubleAtoms.ops = NULL; JS_DHashTableFinish(&state->stringAtoms); state->stringAtoms.ops = NULL; return JS_FALSE; } JS_ASSERT(IS_DOUBLE_TABLE(&state->doubleAtoms)); #ifdef JS_THREADSAFE js_InitLock(&state->lock); #endif JS_ASSERT(IS_INITIALIZED_STATE(state)); return JS_TRUE; }
JSBool js_InitAtomState(JSContext *cx, JSAtomState *state) { state->runtime = cx->runtime; state->table = JS_NewHashTable(JS_ATOM_HASH_SIZE, js_hash_atom_key, js_compare_atom_keys, js_compare_stub, &atom_alloc_ops, state); if (!state->table) { JS_ReportOutOfMemory(cx); return JS_FALSE; } #ifdef JS_THREADSAFE js_InitLock(&state->lock); state->tablegen = 0; #endif if (!js_InitPinnedAtoms(cx, state)) { js_FreeAtomState(cx, state); return JS_FALSE; } return JS_TRUE; }