標籤:
概述: [CustomEnumerateProperty] 當給定的介面被枚舉時,允許你為指定介面的屬性擷取函數編寫自己的實現. 同樣,當介面的屬性被刪除時,[CustomDeleteProperty]允許你編寫自己的實現.
customEnumerateProperty](i), [CustomDeleteProperty](i)
用法: 這兩個修飾可作用在interface,用法如下:
[ CustomEnumerateProperty, CustomDeleteProperty ] interface DataTransferItemList { };
- [CustomEnumerateProperty] in JavaScriptCore: 你能編寫DataTransferItemList的屬性擷取函數,具體來說,你可以編寫這個函數JSXXX::getOwnPropertyNames(...), 它來自於WebCore/bindings/js/JSDataTransferItemListCustom.cpp:
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 { };
- [CustomDeleteProperty] : 當Storage的屬性被刪除時,我們可以編寫自己的屬性刪除函數,具體點說,就是像這樣子編寫JSStorage::deleteProperty(...) 函數,它位於WebCore/bindings/js/JSStorageCustom.cpp:
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;}參考:1 http://trac.webkit.org/wiki/WebKitIDL#CustomEnumerateProperty2 souce code of webkit
Webkit的自訂屬性擷取函數以及屬性刪除函數實現