标签:
概述: [CustomEnumerateProperty] 当给定的接口被枚举时,允许你为指定接口的属性获取函数编写自己的实现. 同样,当接口的属性被删除时,[CustomDeleteProperty]允许你编写自己的实现.
customEnumerateProperty](i), [CustomDeleteProperty](i)
用法: 这两个修饰可作用在interface,用法如下:
[
CustomEnumerateProperty,
CustomDeleteProperty
] interface DataTransferItemList {
};
void JSDataTransferItemList::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
JSDataTransferItemList* thisObject = jsCast<JSDataTransferItemList*>(object);
ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
for (unsigned i = 0; i < static_cast<DataTransferItemList*>(thisObject->impl())->length(); ++i)
propertyNames.add(Identifier::from(exec, i));
Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
}
[
CustomDeleteProperty
] interface Storage {
};
bool JSStorage::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
{
JSStorage* thisObject = jsCast<JSStorage*>(cell);
// Only perform the custom delete if the object doesn‘t have a native property by this name.
// Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check
// the native property slots manually.
PropertySlot slot;
if (getStaticValueSlot<JSStorage, Base>(exec, s_info.propHashTable(exec), thisObject, propertyName, slot))
return false;
JSValue prototype = thisObject->prototype();
if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName))
return false;
thisObject->m_impl->removeItem(propertyNameToString(propertyName));
return true;
}
标签:
原文地址:http://blog.csdn.net/lichwei1983/article/details/43889383