summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorfqian@google.com <fqian@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-10 02:41:18 +0000
committerfqian@google.com <fqian@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-10 02:41:18 +0000
commitefecec54fc5177976a766d94b4e8be2e444078c1 (patch)
treeba569b1061a9a050ebf5ca9d9e5d9b31da6dd1e0 /webkit
parent65b8ff3488f6ea34f3b03c062a2a2c4ba211046b (diff)
downloadchromium_src-efecec54fc5177976a766d94b4e8be2e444078c1.zip
chromium_src-efecec54fc5177976a766d94b4e8be2e444078c1.tar.gz
chromium_src-efecec54fc5177976a766d94b4e8be2e444078c1.tar.bz2
Cleanup some constants in the binding code.
Review URL: http://codereview.chromium.org/1879 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1966 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/port/bindings/v8/v8_custom.cpp32
-rw-r--r--webkit/port/bindings/v8/v8_custom.h30
-rw-r--r--webkit/port/bindings/v8/v8_proxy.cpp20
3 files changed, 40 insertions, 42 deletions
diff --git a/webkit/port/bindings/v8/v8_custom.cpp b/webkit/port/bindings/v8/v8_custom.cpp
index e993749..205b6c3 100644
--- a/webkit/port/bindings/v8/v8_custom.cpp
+++ b/webkit/port/bindings/v8/v8_custom.cpp
@@ -531,28 +531,6 @@ ACCESSOR_SETTER(DocumentLocation) {
}
-ACCESSOR_GETTER(DOMWindowLocation) {
- v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper(
- V8ClassIndex::DOMWINDOW, info.This());
- if (holder.IsEmpty())
- return v8::Undefined();
-
- DOMWindow* imp = V8Proxy::FastToNativeObject<DOMWindow>(
- V8ClassIndex::DOMWINDOW, holder);
-
- // Give subframes precedence.
- if (imp->frame()) {
- Frame* child = imp->frame()->tree()->child("location");
- if (child)
- return V8Proxy::ToV8Object(V8ClassIndex::DOMWINDOW, child->domWindow());
- }
-
- // Normal getter or real 'location' property.
- Location* v = imp->location();
- return V8Proxy::ToV8Object(V8ClassIndex::LOCATION, static_cast<Peerable*>(v));
-}
-
-
ACCESSOR_SETTER(DOMWindowLocation) {
v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper(
V8ClassIndex::DOMWINDOW, info.This());
@@ -2734,11 +2712,11 @@ CALLBACK_FUNC_DECL(EventTargetNodeRemoveEventListener) {
static void CreateHiddenXHRDependency(v8::Local<v8::Object> xhr,
v8::Local<v8::Value> value) {
ASSERT(V8Proxy::GetDOMWrapperType(xhr) == V8ClassIndex::XMLHTTPREQUEST);
- int last_internal_field_index = xhr->InternalFieldCount() - 1;
- v8::Local<v8::Value> cache = xhr->GetInternalField(last_internal_field_index);
+ v8::Local<v8::Value> cache =
+ xhr->GetInternalField(V8Custom::kXMLHttpRequestCacheIndex);
if (cache->IsNull() || cache->IsUndefined()) {
cache = v8::Array::New();
- xhr->SetInternalField(last_internal_field_index, cache);
+ xhr->SetInternalField(V8Custom::kXMLHttpRequestCacheIndex, cache);
}
v8::Local<v8::Array> cache_array = v8::Local<v8::Array>::Cast(cache);
@@ -2749,8 +2727,8 @@ static void CreateHiddenXHRDependency(v8::Local<v8::Object> xhr,
static void RemoveHiddenXHRDependency(v8::Local<v8::Object> xhr,
v8::Local<v8::Value> value) {
ASSERT(V8Proxy::GetDOMWrapperType(xhr) == V8ClassIndex::XMLHTTPREQUEST);
- int last_internal_field_index = xhr->InternalFieldCount() - 1;
- v8::Local<v8::Value> cache = xhr->GetInternalField(last_internal_field_index);
+ v8::Local<v8::Value> cache =
+ xhr->GetInternalField(V8Custom::kXMLHttpRequestCacheIndex);
ASSERT(cache->IsArray());
v8::Local<v8::Array> cache_array = v8::Local<v8::Array>::Cast(cache);
for (int i = cache_array->Length() - 1; i >= 0; i--) {
diff --git a/webkit/port/bindings/v8/v8_custom.h b/webkit/port/bindings/v8/v8_custom.h
index 16c26d3..b22854f 100644
--- a/webkit/port/bindings/v8/v8_custom.h
+++ b/webkit/port/bindings/v8/v8_custom.h
@@ -20,12 +20,28 @@ class V8Custom {
public:
// Constants.
- static const int kDefaultWrapperInternalFieldCount = 2;
- static const int kDocumentMinimumInternalFieldCount = 3;
- static const int kDocumentImplementationIndex = 2;
- static const int kHTMLDocumentInternalFieldCount = 5;
- static const int kHTMLDocumentMarkerIndex = 3;
- static const int kHTMLDocumentShadowIndex = 4;
+ static const int kDOMWrapperObjectIndex = 0;
+ static const int kDOMWrapperTypeIndex = 1;
+ static const int kDefaultWrapperInternalFieldCount =
+ kDOMWrapperTypeIndex + 1;
+
+ static const int kDocumentMinimumInternalFieldCount =
+ kDefaultWrapperInternalFieldCount + 1;
+ static const int kDocumentImplementationIndex =
+ kDefaultWrapperInternalFieldCount + 0;
+
+ static const int kHTMLDocumentInternalFieldCount =
+ kDocumentMinimumInternalFieldCount + 2;
+ static const int kHTMLDocumentMarkerIndex =
+ kDocumentMinimumInternalFieldCount + 0;
+ static const int kHTMLDocumentShadowIndex =
+ kDocumentMinimumInternalFieldCount + 1;
+
+ static const int kXMLHttpRequestInternalFieldCount =
+ kDefaultWrapperInternalFieldCount + 1;
+ static const int kXMLHttpRequestCacheIndex =
+ kDefaultWrapperInternalFieldCount + 0;
+
#define DECLARE_PROPERTY_ACCESSOR_GETTER(NAME) \
static v8::Handle<v8::Value> v8##NAME##AccessorGetter(\
@@ -106,7 +122,7 @@ static bool v8##NAME##IndexedSecurityCheck(v8::Local<v8::Object> host, \
DECLARE_PROPERTY_ACCESSOR(CanvasRenderingContext2DStrokeStyle)
DECLARE_PROPERTY_ACCESSOR(CanvasRenderingContext2DFillStyle)
// Customized getter&setter of DOMWindow.location
-DECLARE_PROPERTY_ACCESSOR(DOMWindowLocation)
+DECLARE_PROPERTY_ACCESSOR_SETTER(DOMWindowLocation)
// Customized setter of DOMWindow.opener
DECLARE_PROPERTY_ACCESSOR_SETTER(DOMWindowOpener)
diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp
index 5ce4607..d9152ed 100644
--- a/webkit/port/bindings/v8/v8_proxy.cpp
+++ b/webkit/port/bindings/v8/v8_proxy.cpp
@@ -1245,6 +1245,7 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate(
default_signature),
v8::None);
desc->SetHiddenPrototype(true);
+
break;
}
case V8ClassIndex::LOCATION: {
@@ -1266,9 +1267,9 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate(
case V8ClassIndex::XMLHTTPREQUEST: {
// Reserve one more internal field for keeping event listeners.
v8::Local<v8::ObjectTemplate> instance_template =
- desc->InstanceTemplate();
- int internal_field_count = instance_template->InternalFieldCount() + 1;
- instance_template->SetInternalFieldCount(internal_field_count);
+ desc->InstanceTemplate();
+ instance_template->SetInternalFieldCount(
+ V8Custom::kXMLHttpRequestInternalFieldCount);
desc->SetCallHandler(USE_CALLBACK(XMLHttpRequestConstructor));
break;
}
@@ -2011,8 +2012,8 @@ void* V8Proxy::ExtractCPointerImpl(v8::Handle<v8::Value> obj) {
bool V8Proxy::SetDOMWrapper(v8::Handle<v8::Object> obj, int type, void* cptr) {
ASSERT(obj->InternalFieldCount() >= 2);
- obj->SetInternalField(0, WrapCPointer(cptr));
- obj->SetInternalField(1, v8::Integer::New(type));
+ obj->SetInternalField(V8Custom::kDOMWrapperObjectIndex, WrapCPointer(cptr));
+ obj->SetInternalField(V8Custom::kDOMWrapperTypeIndex, v8::Integer::New(type));
return true;
}
@@ -2021,12 +2022,15 @@ bool V8Proxy::MaybeDOMWrapper(v8::Handle<v8::Value> value) {
if (value.IsEmpty() || !value->IsObject()) return false;
v8::Handle<v8::Object> obj = v8::Handle<v8::Object>::Cast(value);
- if (obj->InternalFieldCount() < 2) return false;
+ if (obj->InternalFieldCount() < V8Custom::kDefaultWrapperInternalFieldCount)
+ return false;
- v8::Handle<v8::Value> wrapper = obj->GetInternalField(0);
+ v8::Handle<v8::Value> wrapper =
+ obj->GetInternalField(V8Custom::kDOMWrapperObjectIndex);
if (!wrapper->IsNumber() && !wrapper->IsExternal()) return false;
- v8::Handle<v8::Value> type = obj->GetInternalField(1);
+ v8::Handle<v8::Value> type =
+ obj->GetInternalField(V8Custom::kDOMWrapperTypeIndex);
if (!type->IsNumber()) return false;
return true;