summaryrefslogtreecommitdiffstats
path: root/WebCore/bindings/v8/V8Collection.h
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/bindings/v8/V8Collection.h')
-rw-r--r--WebCore/bindings/v8/V8Collection.h69
1 files changed, 14 insertions, 55 deletions
diff --git a/WebCore/bindings/v8/V8Collection.h b/WebCore/bindings/v8/V8Collection.h
index 0a4134e..84150d8 100644
--- a/WebCore/bindings/v8/V8Collection.h
+++ b/WebCore/bindings/v8/V8Collection.h
@@ -51,6 +51,11 @@ namespace WebCore {
return V8DOMWrapper::convertToV8Object(type, implementation);
}
+ template<class Collection> static Collection* toNativeCollection(v8::Local<v8::Object> object)
+ {
+ return reinterpret_cast<Collection*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex));
+ }
+
template<class T> static v8::Handle<v8::Value> getV8Object(PassRefPtr<T> implementation, v8::Local<v8::Value> implementationType)
{
return getV8Object(implementation.get(), implementationType);
@@ -62,10 +67,9 @@ namespace WebCore {
{
// FIXME: assert object is a collection type
ASSERT(V8DOMWrapper::maybeDOMWrapper(object));
- V8ClassIndex::V8WrapperType wrapperType = V8DOMWrapper::domWrapperType(object);
- ASSERT(wrapperType != V8ClassIndex::NODE);
- Collection* collection = V8DOMWrapper::convertToNativeObject<Collection>(wrapperType, object);
- String propertyName = toWebCoreString(name);
+ ASSERT(V8DOMWrapper::domWrapperType(object) != V8ClassIndex::NODE);
+ Collection* collection = toNativeCollection<Collection>(object);
+ AtomicString propertyName = toAtomicWebCoreStringWithNullCheck(name);
return getV8Object<ItemType>(collection->namedItem(propertyName), implementationType);
}
@@ -84,35 +88,14 @@ namespace WebCore {
return getNamedPropertyOfCollection<Collection, ItemType>(name, info.Holder(), info.Data());
}
- // A template of named property accessor of HTMLSelectElement and HTMLFormElement.
- template<class Collection> static v8::Handle<v8::Value> nodeCollectionNamedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
- {
- ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder()));
- ASSERT(V8DOMWrapper::domWrapperType(info.Holder()) == V8ClassIndex::NODE);
- v8::Handle<v8::Value> value = info.Holder()->GetRealNamedPropertyInPrototypeChain(name);
-
- if (!value.IsEmpty())
- return value;
-
- // Search local callback properties next to find IDL defined
- // properties.
- if (info.Holder()->HasRealNamedCallbackProperty(name))
- return notHandledByInterceptor();
- Collection* collection = V8DOMWrapper::convertDOMWrapperToNode<Collection>(info.Holder());
- String propertyName = toWebCoreString(name);
- void* implementation = collection->namedItem(propertyName);
- return getV8Object(implementation, info.Data());
- }
-
// Returns the property at the index of a collection.
template<class Collection, class ItemType> static v8::Handle<v8::Value> getIndexedPropertyOfCollection(uint32_t index, v8::Local<v8::Object> object,
v8::Local<v8::Value> implementationType)
{
// FIXME: Assert that object must be a collection type.
ASSERT(V8DOMWrapper::maybeDOMWrapper(object));
- V8ClassIndex::V8WrapperType wrapperType = V8DOMWrapper::domWrapperType(object);
- ASSERT(wrapperType != V8ClassIndex::NODE);
- Collection* collection = V8DOMWrapper::convertToNativeObject<Collection>(wrapperType, object);
+ ASSERT(V8DOMWrapper::domWrapperType(object) != V8ClassIndex::NODE);
+ Collection* collection = toNativeCollection<Collection>(object);
return getV8Object<ItemType>(collection->item(index), implementationType);
}
@@ -122,22 +105,12 @@ namespace WebCore {
return getIndexedPropertyOfCollection<Collection, ItemType>(index, info.Holder(), info.Data());
}
- // A template of index interceptor of HTMLSelectElement and HTMLFormElement.
- template<class Collection> static v8::Handle<v8::Value> nodeCollectionIndexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info)
- {
- ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder()));
- ASSERT(V8DOMWrapper::domWrapperType(info.Holder()) == V8ClassIndex::NODE);
- Collection* collection = V8DOMWrapper::convertDOMWrapperToNode<Collection>(info.Holder());
- void* implementation = collection->item(index);
- return getV8Object(implementation, info.Data());
- }
-
// Get an array containing the names of indexed properties of HTMLSelectElement and HTMLFormElement.
template<class Collection> static v8::Handle<v8::Array> nodeCollectionIndexedPropertyEnumerator(const v8::AccessorInfo& info)
{
ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder()));
ASSERT(V8DOMWrapper::domWrapperType(info.Holder()) == V8ClassIndex::NODE);
- Collection* collection = V8DOMWrapper::convertDOMWrapperToNode<Collection>(info.Holder());
+ Collection* collection = toNativeCollection<Collection>(info.Holder());
int length = collection->length();
v8::Handle<v8::Array> properties = v8::Array::New(length);
for (int i = 0; i < length; ++i) {
@@ -152,8 +125,7 @@ namespace WebCore {
template<class Collection> static v8::Handle<v8::Array> collectionIndexedPropertyEnumerator(const v8::AccessorInfo& info)
{
ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder()));
- V8ClassIndex::V8WrapperType wrapperType = V8DOMWrapper::domWrapperType(info.Holder());
- Collection* collection = V8DOMWrapper::convertToNativeObject<Collection>(wrapperType, info.Holder());
+ Collection* collection = toNativeCollection<Collection>(info.Holder());
int length = collection->length();
v8::Handle<v8::Array> properties = v8::Array::New(length);
for (int i = 0; i < length; ++i) {
@@ -170,8 +142,7 @@ namespace WebCore {
{
// FIXME: assert that object must be a collection type
ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder()));
- V8ClassIndex::V8WrapperType wrapperType = V8DOMWrapper::domWrapperType(info.Holder());
- Collection* collection = V8DOMWrapper::convertToNativeObject<Collection>(wrapperType, info.Holder());
+ Collection* collection = toNativeCollection<Collection>(info.Holder());
String result = collection->item(index);
return v8StringOrNull(result);
}
@@ -182,8 +153,7 @@ namespace WebCore {
{
// FIXME: assert that object must be a collection type
ASSERT(V8DOMWrapper::maybeDOMWrapper(info.Holder()));
- V8ClassIndex::V8WrapperType wrapperType = V8DOMWrapper::domWrapperType(info.Holder());
- Collection* collection = V8DOMWrapper::convertToNativeObject<Collection>(wrapperType, info.Holder());
+ Collection* collection = toNativeCollection<Collection>(info.Holder());
String result = collection->item(index);
return v8String(result);
}
@@ -203,17 +173,6 @@ namespace WebCore {
desc->InstanceTemplate()->SetNamedPropertyHandler(collectionNamedPropertyGetter<Collection, ItemType>, 0, 0, 0, 0, v8::Integer::New(V8ClassIndex::ToInt(type)));
}
-
- // Add named and indexed getters to the function template for a collection.
- template<class Collection, class ItemType> static void setCollectionIndexedAndNamedGetters(v8::Handle<v8::FunctionTemplate> desc, V8ClassIndex::V8WrapperType type)
- {
- // If we interceptor before object, accessing 'length' can trigger a webkit assertion error (see fast/dom/HTMLDocument/document-special-properties.html).
- desc->InstanceTemplate()->SetNamedPropertyHandler(collectionNamedPropertyGetter<Collection, ItemType>, 0, 0, 0, 0, v8::Integer::New(V8ClassIndex::ToInt(type)));
- desc->InstanceTemplate()->SetIndexedPropertyHandler(collectionIndexedPropertyGetter<Collection, ItemType>, 0, 0, 0, collectionIndexedPropertyEnumerator<Collection>,
- v8::Integer::New(V8ClassIndex::ToInt(type)));
- }
-
-
// Add indexed getter returning a string or null to a function template for a collection.
template<class Collection> static void setCollectionStringOrNullIndexedGetter(v8::Handle<v8::FunctionTemplate> desc)
{