📄 jsobject.cpp
字号:
// Must call toString first for Date objects. if ((hint == PreferString) || (hint != PreferNumber && prototype() == exec->lexicalGlobalObject()->datePrototype())) { JSValuePtr value = callDefaultValueFunction(exec, this, exec->propertyNames().toString); if (value) return value; value = callDefaultValueFunction(exec, this, exec->propertyNames().valueOf); if (value) return value; } else { JSValuePtr value = callDefaultValueFunction(exec, this, exec->propertyNames().valueOf); if (value) return value; value = callDefaultValueFunction(exec, this, exec->propertyNames().toString); if (value) return value; } ASSERT(!exec->hadException()); return throwError(exec, TypeError, "No default value");}const HashEntry* JSObject::findPropertyHashEntry(ExecState* exec, const Identifier& propertyName) const{ for (const ClassInfo* info = classInfo(); info; info = info->parentClass) { if (const HashTable* propHashTable = info->propHashTable(exec)) { if (const HashEntry* entry = propHashTable->entry(exec, propertyName)) return entry; } } return 0;}void JSObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction){ JSValuePtr object = getDirect(propertyName); if (object && object.isGetterSetter()) { ASSERT(m_structure->hasGetterSetterProperties()); asGetterSetter(object)->setGetter(getterFunction); return; } PutPropertySlot slot; GetterSetter* getterSetter = new (exec) GetterSetter; putDirect(propertyName, getterSetter, None, true, slot); // putDirect will change our Structure if we add a new property. For // getters and setters, though, we also need to change our Structure // if we override an existing non-getter or non-setter. if (slot.type() != PutPropertySlot::NewProperty) { if (!m_structure->isDictionary()) { RefPtr<Structure> structure = Structure::getterSetterTransition(m_structure); setStructure(structure.release()); } } m_structure->setHasGetterSetterProperties(true); getterSetter->setGetter(getterFunction);}void JSObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunction){ JSValuePtr object = getDirect(propertyName); if (object && object.isGetterSetter()) { ASSERT(m_structure->hasGetterSetterProperties()); asGetterSetter(object)->setSetter(setterFunction); return; } PutPropertySlot slot; GetterSetter* getterSetter = new (exec) GetterSetter; putDirect(propertyName, getterSetter, None, true, slot); // putDirect will change our Structure if we add a new property. For // getters and setters, though, we also need to change our Structure // if we override an existing non-getter or non-setter. if (slot.type() != PutPropertySlot::NewProperty) { if (!m_structure->isDictionary()) { RefPtr<Structure> structure = Structure::getterSetterTransition(m_structure); setStructure(structure.release()); } } m_structure->setHasGetterSetterProperties(true); getterSetter->setSetter(setterFunction);}JSValuePtr JSObject::lookupGetter(ExecState*, const Identifier& propertyName){ JSObject* object = this; while (true) { if (JSValuePtr value = object->getDirect(propertyName)) { if (!value.isGetterSetter()) return jsUndefined(); JSObject* functionObject = asGetterSetter(value)->getter(); if (!functionObject) return jsUndefined(); return functionObject; } if (!object->prototype() || !object->prototype().isObject()) return jsUndefined(); object = asObject(object->prototype()); }}JSValuePtr JSObject::lookupSetter(ExecState*, const Identifier& propertyName){ JSObject* object = this; while (true) { if (JSValuePtr value = object->getDirect(propertyName)) { if (!value.isGetterSetter()) return jsUndefined(); JSObject* functionObject = asGetterSetter(value)->setter(); if (!functionObject) return jsUndefined(); return functionObject; } if (!object->prototype() || !object->prototype().isObject()) return jsUndefined(); object = asObject(object->prototype()); }}bool JSObject::hasInstance(ExecState* exec, JSValuePtr value, JSValuePtr proto){ if (!proto.isObject()) { throwError(exec, TypeError, "instanceof called on an object with an invalid prototype property."); return false; } if (!value.isObject()) return false; JSObject* object = asObject(value); while ((object = object->prototype().getObject())) { if (proto == object) return true; } return false;}bool JSObject::propertyIsEnumerable(ExecState* exec, const Identifier& propertyName) const{ unsigned attributes; if (!getPropertyAttributes(exec, propertyName, attributes)) return false; return !(attributes & DontEnum);}bool JSObject::getPropertyAttributes(ExecState* exec, const Identifier& propertyName, unsigned& attributes) const{ if (m_structure->get(propertyName, attributes) != WTF::notFound) return true; // Look in the static hashtable of properties const HashEntry* entry = findPropertyHashEntry(exec, propertyName); if (entry) { attributes = entry->attributes(); return true; } return false;}void JSObject::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames){ m_structure->getEnumerablePropertyNames(exec, propertyNames, this);}bool JSObject::toBoolean(ExecState*) const{ return true;}double JSObject::toNumber(ExecState* exec) const{ JSValuePtr primitive = toPrimitive(exec, PreferNumber); if (exec->hadException()) // should be picked up soon in Nodes.cpp return 0.0; return primitive.toNumber(exec);}UString JSObject::toString(ExecState* exec) const{ JSValuePtr primitive = toPrimitive(exec, PreferString); if (exec->hadException()) return ""; return primitive.toString(exec);}JSObject* JSObject::toObject(ExecState*) const{ return const_cast<JSObject*>(this);}JSObject* JSObject::toThisObject(ExecState*) const{ return const_cast<JSObject*>(this);}JSObject* JSObject::unwrappedObject(){ return this;}void JSObject::removeDirect(const Identifier& propertyName){ size_t offset; if (m_structure->isDictionary()) { offset = m_structure->removePropertyWithoutTransition(propertyName); if (offset != WTF::notFound) m_propertyStorage[offset] = jsUndefined(); return; } RefPtr<Structure> structure = Structure::removePropertyTransition(m_structure, propertyName, offset); if (offset != WTF::notFound) m_propertyStorage[offset] = jsUndefined(); setStructure(structure.release());}void JSObject::putDirectFunction(ExecState* exec, InternalFunction* function, unsigned attr){ putDirect(Identifier(exec, function->name(&exec->globalData())), function, attr);}void JSObject::putDirectFunctionWithoutTransition(ExecState* exec, InternalFunction* function, unsigned attr){ putDirectWithoutTransition(Identifier(exec, function->name(&exec->globalData())), function, attr);}NEVER_INLINE void JSObject::fillGetterPropertySlot(PropertySlot& slot, JSValuePtr* location){ if (JSObject* getterFunction = asGetterSetter(*location)->getter()) slot.setGetterSlot(getterFunction); else slot.setUndefined();}Structure* JSObject::createInheritorID(){ m_inheritorID = JSObject::createStructure(this); return m_inheritorID.get();}void JSObject::allocatePropertyStorage(size_t oldSize, size_t newSize){ allocatePropertyStorageInline(oldSize, newSize);}JSObject* constructEmptyObject(ExecState* exec){ return new (exec) JSObject(exec->lexicalGlobalObject()->emptyObjectStructure());}} // namespace JSC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -