summaryrefslogtreecommitdiffstats
path: root/webkit/port/bindings/v8
diff options
context:
space:
mode:
authorojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-20 21:58:28 +0000
committerojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-20 21:58:28 +0000
commitb38b3a0232a7f35cb89730ff08650adb3b12f430 (patch)
tree29586e879cc51b157a797b0af5527ff1d1eda4b3 /webkit/port/bindings/v8
parent8b29bcad34e03a319993dc38fc50a33d10a7da9d (diff)
downloadchromium_src-b38b3a0232a7f35cb89730ff08650adb3b12f430.zip
chromium_src-b38b3a0232a7f35cb89730ff08650adb3b12f430.tar.gz
chromium_src-b38b3a0232a7f35cb89730ff08650adb3b12f430.tar.bz2
Resubmit r3612 and r3613 this time with mac fixes (thanks mark!).
Review URL: http://codereview.chromium.org/7675 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3633 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/port/bindings/v8')
-rw-r--r--webkit/port/bindings/v8/v8_collection.h106
-rw-r--r--webkit/port/bindings/v8/v8_custom.cpp13
-rw-r--r--webkit/port/bindings/v8/v8_custom.h6
-rw-r--r--webkit/port/bindings/v8/v8_proxy.cpp44
4 files changed, 83 insertions, 86 deletions
diff --git a/webkit/port/bindings/v8/v8_collection.h b/webkit/port/bindings/v8/v8_collection.h
index c468a0e..ef0b3c5 100644
--- a/webkit/port/bindings/v8/v8_collection.h
+++ b/webkit/port/bindings/v8/v8_collection.h
@@ -11,8 +11,26 @@
namespace WebCore {
+static v8::Handle<v8::Value> GetV8Object(
+ void * result,
+ v8::Local<v8::Value> data) {
+ if (!result) return v8::Handle<v8::Value>();
+ V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(data);
+ if (type == V8ClassIndex::NODE)
+ return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
+ else
+ return V8Proxy::ToV8Object(type, result);
+}
+
+template <class D>
+static v8::Handle<v8::Value> GetV8Object(
+ PassRefPtr<D> result,
+ v8::Local<v8::Value> data) {
+ return GetV8Object(result.get(), data);
+}
+
// Returns named property of a collection.
-template <class C>
+template <class C, class D>
static v8::Handle<v8::Value> GetNamedPropertyOfCollection(
v8::Local<v8::String> name,
v8::Local<v8::Object> object,
@@ -23,20 +41,14 @@ static v8::Handle<v8::Value> GetNamedPropertyOfCollection(
ASSERT(t != V8ClassIndex::NODE);
C* collection = V8Proxy::ToNativeObject<C>(t, object);
String prop_name = ToWebCoreString(name);
- void* result = collection->namedItem(prop_name);
- if (!result) return v8::Handle<v8::Value>();
- V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(data);
- if (type == V8ClassIndex::NODE)
- return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
- else
- return V8Proxy::ToV8Object(type, result);
+ return GetV8Object<D>(collection->namedItem(prop_name), data);
}
// A template of named property accessor of collections.
-template <class C>
+template <class C, class D>
static v8::Handle<v8::Value> CollectionNamedPropertyGetter(
v8::Local<v8::String> name, const v8::AccessorInfo& info) {
- return GetNamedPropertyOfCollection<C>(name, info.Holder(), info.Data());
+ return GetNamedPropertyOfCollection<C, D>(name, info.Holder(), info.Data());
}
@@ -50,34 +62,12 @@ static v8::Handle<v8::Value> NodeCollectionNamedPropertyGetter(
C* collection = V8Proxy::DOMWrapperToNode<C>(info.Holder());
String prop_name = ToWebCoreString(name);
void* result = collection->namedItem(prop_name);
- if (!result) return v8::Handle<v8::Value>();
- V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(info.Data());
- if (type == V8ClassIndex::NODE)
- return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
- else
- return V8Proxy::ToV8Object(type, result);
-}
-
-
-// A template returns whether a collection has a named property.
-// This function does not cause JS heap allocation.
-template <class C>
-static bool HasNamedPropertyOfCollection(v8::Local<v8::String> name,
- v8::Local<v8::Object> object,
- v8::Local<v8::Value> data) {
- // TODO: assert object is a collection type
- ASSERT(V8Proxy::MaybeDOMWrapper(object));
-
- V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
- C* collection = V8Proxy::ToNativeObject<C>(t, object);
- String prop_name = ToWebCoreString(name);
- void* result = collection->namedItem(prop_name);
- return result != NULL;
+ return GetV8Object(result, info.Data());
}
// Returns the property at the index of a collection.
-template <class C>
+template <class C, class D>
static v8::Handle<v8::Value> GetIndexedPropertyOfCollection(
uint32_t index, v8::Local<v8::Object> object, v8::Local<v8::Value> data) {
// TODO, assert that object must be a collection type
@@ -85,21 +75,15 @@ static v8::Handle<v8::Value> GetIndexedPropertyOfCollection(
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
ASSERT(t != V8ClassIndex::NODE);
C* collection = V8Proxy::ToNativeObject<C>(t, object);
- void* result = collection->item(index);
- if (!result) return v8::Handle<v8::Value>();
- V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(data);
- if (type == V8ClassIndex::NODE)
- return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
- else
- return V8Proxy::ToV8Object(type, result);
+ return GetV8Object<D>(collection->item(index), data);
}
// A template of index interceptor of collections.
-template <class C>
+template <class C, class D>
static v8::Handle<v8::Value> CollectionIndexedPropertyGetter(
uint32_t index, const v8::AccessorInfo& info) {
- return GetIndexedPropertyOfCollection<C>(index, info.Holder(), info.Data());
+ return GetIndexedPropertyOfCollection<C, D>(index, info.Holder(), info.Data());
}
@@ -111,12 +95,7 @@ static v8::Handle<v8::Value> NodeCollectionIndexedPropertyGetter(
ASSERT(V8Proxy::GetDOMWrapperType(info.Holder()) == V8ClassIndex::NODE);
C* collection = V8Proxy::DOMWrapperToNode<C>(info.Holder());
void* result = collection->item(index);
- if (!result) return v8::Handle<v8::Value>();
- V8ClassIndex::V8WrapperType type = V8ClassIndex::ToWrapperType(info.Data());
- if (type == V8ClassIndex::NODE)
- return V8Proxy::NodeToV8Object(static_cast<Node*>(result));
- else
- return V8Proxy::ToV8Object(type, result);
+ return GetV8Object(result, info.Data());
}
@@ -158,21 +137,6 @@ static v8::Handle<v8::Array> CollectionIndexedPropertyEnumerator(
}
-// Returns whether a collection has a property at a given index.
-// This function does not cause JS heap allocation.
-template <class C>
-static bool HasIndexedPropertyOfCollection(uint32_t index,
- v8::Local<v8::Object> object,
- v8::Local<v8::Value> data) {
- // TODO, assert that object must be a collection type
- ASSERT(V8Proxy::MaybeDOMWrapper(object));
- V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
- C* collection = V8Proxy::ToNativeObject<C>(t, object);
- void* result = collection->item(index);
- return result != NULL;
-}
-
-
// A template for indexed getters on collections of strings that should return
// null if the resulting string is a null string.
template <class C>
@@ -188,11 +152,11 @@ static v8::Handle<v8::Value> CollectionStringOrNullIndexedPropertyGetter(
// Add indexed getter to the function template for a collection.
-template <class T>
+template <class T, class D>
static void SetCollectionIndexedGetter(v8::Handle<v8::FunctionTemplate> desc,
V8ClassIndex::V8WrapperType type) {
desc->InstanceTemplate()->SetIndexedPropertyHandler(
- CollectionIndexedPropertyGetter<T>,
+ CollectionIndexedPropertyGetter<T, D>,
0,
0,
0,
@@ -202,11 +166,11 @@ static void SetCollectionIndexedGetter(v8::Handle<v8::FunctionTemplate> desc,
// Add named getter to the function template for a collection.
-template <class T>
+template <class T, class D>
static void SetCollectionNamedGetter(v8::Handle<v8::FunctionTemplate> desc,
V8ClassIndex::V8WrapperType type) {
desc->InstanceTemplate()->SetNamedPropertyHandler(
- CollectionNamedPropertyGetter<T>,
+ CollectionNamedPropertyGetter<T, D>,
0,
0,
0,
@@ -216,21 +180,21 @@ static void SetCollectionNamedGetter(v8::Handle<v8::FunctionTemplate> desc,
// Add named and indexed getters to the function template for a collection.
-template <class T>
+template <class T, class D>
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<T>,
+ CollectionNamedPropertyGetter<T, D>,
0,
0,
0,
0,
v8::External::New(reinterpret_cast<void*>(type)));
desc->InstanceTemplate()->SetIndexedPropertyHandler(
- CollectionIndexedPropertyGetter<T>,
+ CollectionIndexedPropertyGetter<T, D>,
0,
0,
0,
diff --git a/webkit/port/bindings/v8/v8_custom.cpp b/webkit/port/bindings/v8/v8_custom.cpp
index 1d36ccc..0904839 100644
--- a/webkit/port/bindings/v8/v8_custom.cpp
+++ b/webkit/port/bindings/v8/v8_custom.cpp
@@ -114,6 +114,8 @@
#include "SVGPathSeg.h"
#endif
+#include "Navigator.h"
+
#undef LOG
#include "webkit/glue/webplugin_impl.h"
@@ -3145,6 +3147,17 @@ CALLBACK_FUNC_DECL(EventTargetNodeRemoveEventListener) {
}
+// Navigator ------------------------------------------------------------------
+ACCESSOR_GETTER(NavigatorAppVersion) {
+ INC_STATS(L"DOM.Navigator.appVersion");
+ v8::Handle<v8::Object> holder = info.Holder();
+ Navigator* imp = V8Proxy::ToNativeObject<Navigator>(V8ClassIndex::NAVIGATOR,
+ holder);
+ String v = ToString(imp->appVersion());
+ return v8StringOrUndefined(v);
+}
+
+
// TreeWalker ------------------------------------------------------------------
CALLBACK_FUNC_DECL(TreeWalkerParentNode) {
diff --git a/webkit/port/bindings/v8/v8_custom.h b/webkit/port/bindings/v8/v8_custom.h
index 101a1a5..302b80a 100644
--- a/webkit/port/bindings/v8/v8_custom.h
+++ b/webkit/port/bindings/v8/v8_custom.h
@@ -279,6 +279,12 @@ DECLARE_CALLBACK(ElementSetAttributeNodeNS)
DECLARE_CALLBACK(EventTargetNodeAddEventListener)
DECLARE_CALLBACK(EventTargetNodeRemoveEventListener)
+// Custom implementation is Navigator properties.
+// We actually only need this because WebKit has
+// navigator.appVersion as custom. Our version just
+// passes through.
+DECLARE_PROPERTY_ACCESSOR(NavigatorAppVersion)
+
// Custom implementation of XMLHttpRequest properties
DECLARE_PROPERTY_ACCESSOR(XMLHttpRequestOnabort)
DECLARE_PROPERTY_ACCESSOR(XMLHttpRequestOnerror)
diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp
index bc8f183..81df91f 100644
--- a/webkit/port/bindings/v8/v8_proxy.cpp
+++ b/webkit/port/bindings/v8/v8_proxy.cpp
@@ -73,20 +73,24 @@
#include "EventTarget.h"
#include "Event.h"
#include "HTMLInputElement.h"
-#include "XMLHttpRequest.h"
-#include "StyleSheet.h"
-#include "StyleSheetList.h"
#include "CSSRule.h"
#include "CSSRuleList.h"
#include "CSSValueList.h"
#include "CSSVariablesDeclaration.h"
#include "FrameLoader.h"
#include "FrameTree.h"
+#include "MimeTypeArray.h"
+#include "NodeFilter.h"
+#include "Plugin.h"
+#include "PluginArray.h"
#include "RangeException.h"
#include "ScriptController.h"
-#include "NodeFilter.h"
#include "SecurityOrigin.h"
+#include "Settings.h"
+#include "StyleSheet.h"
+#include "StyleSheetList.h"
#include "WebKitCSSTransformValue.h"
+#include "XMLHttpRequest.h"
#include "XMLHttpRequestException.h"
#include "XPathException.h"
@@ -1123,10 +1127,13 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate(
SetCollectionStringOrNullIndexedGetter<CSSStyleDeclaration>(desc);
break;
case V8ClassIndex::CSSRULELIST:
- SetCollectionIndexedGetter<CSSRuleList>(desc, V8ClassIndex::CSSRULE);
+ SetCollectionIndexedGetter<CSSRuleList, CSSRule>(desc,
+ V8ClassIndex::CSSRULE);
break;
case V8ClassIndex::CSSVALUELIST:
- SetCollectionIndexedGetter<CSSValueList>(desc, V8ClassIndex::CSSVALUE);
+ SetCollectionIndexedGetter<CSSValueList, CSSValue>(
+ desc,
+ V8ClassIndex::CSSVALUE);
break;
case V8ClassIndex::CSSVARIABLESDECLARATION:
SetCollectionStringOrNullIndexedGetter<CSSVariablesDeclaration>(desc);
@@ -1138,10 +1145,13 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate(
USE_NAMED_PROPERTY_GETTER(HTMLCollection));
desc->InstanceTemplate()->SetCallAsFunctionHandler(
USE_CALLBACK(HTMLCollectionCallAsFunction));
- SetCollectionIndexedGetter<HTMLCollection>(desc, V8ClassIndex::NODE);
+ SetCollectionIndexedGetter<HTMLCollection, Node>(desc,
+ V8ClassIndex::NODE);
break;
case V8ClassIndex::HTMLOPTIONSCOLLECTION:
- SetCollectionNamedGetter<HTMLOptionsCollection>(desc, V8ClassIndex::NODE);
+ SetCollectionNamedGetter<HTMLOptionsCollection, Node>(
+ desc,
+ V8ClassIndex::NODE);
desc->InstanceTemplate()->SetIndexedPropertyHandler(
USE_INDEXED_PROPERTY_GETTER(HTMLOptionsCollection),
USE_INDEXED_PROPERTY_SETTER(HTMLOptionsCollection));
@@ -1251,7 +1261,7 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate(
SetCollectionStringOrNullIndexedGetter<MediaList>(desc);
break;
case V8ClassIndex::MIMETYPEARRAY:
- SetCollectionIndexedAndNamedGetters<MimeTypeArray>(
+ SetCollectionIndexedAndNamedGetters<MimeTypeArray, MimeType>(
desc,
V8ClassIndex::MIMETYPE);
break;
@@ -1267,22 +1277,26 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate(
v8::External::New(reinterpret_cast<void*>(V8ClassIndex::NODE)));
break;
case V8ClassIndex::NODELIST:
- SetCollectionIndexedGetter<NodeList>(desc, V8ClassIndex::NODE);
+ SetCollectionIndexedGetter<NodeList, Node>(desc, V8ClassIndex::NODE);
desc->InstanceTemplate()->SetNamedPropertyHandler(
USE_NAMED_PROPERTY_GETTER(NodeList));
break;
case V8ClassIndex::PLUGIN:
- SetCollectionIndexedAndNamedGetters<Plugin>(desc, V8ClassIndex::MIMETYPE);
+ SetCollectionIndexedAndNamedGetters<Plugin, MimeType>(
+ desc,
+ V8ClassIndex::MIMETYPE);
break;
case V8ClassIndex::PLUGINARRAY:
- SetCollectionIndexedAndNamedGetters<PluginArray>(desc,
- V8ClassIndex::PLUGIN);
+ SetCollectionIndexedAndNamedGetters<PluginArray, Plugin>(
+ desc,
+ V8ClassIndex::PLUGIN);
break;
case V8ClassIndex::STYLESHEETLIST:
desc->InstanceTemplate()->SetNamedPropertyHandler(
USE_NAMED_PROPERTY_GETTER(StyleSheetList));
- SetCollectionIndexedGetter<StyleSheetList>(desc,
- V8ClassIndex::STYLESHEET);
+ SetCollectionIndexedGetter<StyleSheetList, StyleSheet>(
+ desc,
+ V8ClassIndex::STYLESHEET);
break;
case V8ClassIndex::DOMWINDOW: {
v8::Local<v8::Signature> default_signature = v8::Signature::New(desc);