bool JSRuntime::initializeAtoms(JSContext *cx) { atoms_ = cx->new_<AtomSet>(); if (!atoms_ || !atoms_->init(JS_STRING_HASH_COUNT)) return false; if (parentRuntime) { staticStrings = parentRuntime->staticStrings; commonNames = parentRuntime->commonNames; emptyString = parentRuntime->emptyString; permanentAtoms = parentRuntime->permanentAtoms; return true; } permanentAtoms = cx->new_<AtomSet>(); if (!permanentAtoms || !permanentAtoms->init(JS_STRING_HASH_COUNT)) return false; staticStrings = cx->new_<StaticStrings>(); if (!staticStrings || !staticStrings->init(cx)) return false; static const CommonNameInfo cachedNames[] = { #define COMMON_NAME_INFO(idpart, id, text) { js_##idpart##_str, sizeof(text) - 1 }, FOR_EACH_COMMON_PROPERTYNAME(COMMON_NAME_INFO) #undef COMMON_NAME_INFO #define COMMON_NAME_INFO(name, code, init, clasp) { js_##name##_str, sizeof(#name) - 1 }, JS_FOR_EACH_PROTOTYPE(COMMON_NAME_INFO) #undef COMMON_NAME_INFO }; commonNames = cx->new_<JSAtomState>(); if (!commonNames) return false; FixedHeapPtr<PropertyName> *names = reinterpret_cast<FixedHeapPtr<PropertyName> *>(commonNames); for (size_t i = 0; i < ArrayLength(cachedNames); i++, names++) { JSAtom *atom = Atomize(cx, cachedNames[i].str, cachedNames[i].length, InternAtom); if (!atom) return false; names->init(atom->asPropertyName()); } JS_ASSERT(uintptr_t(names) == uintptr_t(commonNames + 1)); emptyString = commonNames->empty; return true; }
bool js::InitCommonNames(JSContext *cx) { static const CommonNameInfo cachedNames[] = { #define COMMON_NAME_INFO(idpart, id, text) { js_##idpart##_str, sizeof(text) - 1 }, FOR_EACH_COMMON_PROPERTYNAME(COMMON_NAME_INFO) #undef COMMON_NAME_INFO #define COMMON_NAME_INFO(name, code, init) { js_##name##_str, sizeof(#name) - 1 }, JS_FOR_EACH_PROTOTYPE(COMMON_NAME_INFO) #undef COMMON_NAME_INFO }; FixedHeapPtr<PropertyName> *names = &cx->runtime->firstCachedName; for (size_t i = 0; i < ArrayLength(cachedNames); i++, names++) { JSAtom *atom = Atomize(cx, cachedNames[i].str, cachedNames[i].length, InternAtom); if (!atom) return false; names->init(atom->asPropertyName()); } JS_ASSERT(uintptr_t(names) == uintptr_t(&cx->runtime->atomState + 1)); cx->runtime->emptyString = cx->names().empty; return true; }