summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorplesner@google.com <plesner@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-05 13:23:48 +0000
committerplesner@google.com <plesner@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-05 13:23:48 +0000
commitb56165e4a87c532449b0f338821580db8b36fa43 (patch)
tree70980c830690cfb3b866a0a3d7a7c0f0ec7b31bd /webkit
parenta360ae62c7b0031753debc07e65c2d8c70dbe6c8 (diff)
downloadchromium_src-b56165e4a87c532449b0f338821580db8b36fa43.zip
chromium_src-b56165e4a87c532449b0f338821580db8b36fa43.tar.gz
chromium_src-b56165e4a87c532449b0f338821580db8b36fa43.tar.bz2
Fixed dom node and constructor instantiation so that dom constructors
now have the object prototype as their implicit prototype, rather than the function prototype. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6428 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/port/bindings/scripts/CodeGeneratorV8.pm5
-rw-r--r--webkit/port/bindings/v8/v8_index.h1
-rw-r--r--webkit/port/bindings/v8/v8_proxy.cpp44
-rw-r--r--webkit/port/bindings/v8/v8_proxy.h5
4 files changed, 46 insertions, 9 deletions
diff --git a/webkit/port/bindings/scripts/CodeGeneratorV8.pm b/webkit/port/bindings/scripts/CodeGeneratorV8.pm
index 44947c8..72d5a80 100644
--- a/webkit/port/bindings/scripts/CodeGeneratorV8.pm
+++ b/webkit/port/bindings/scripts/CodeGeneratorV8.pm
@@ -418,10 +418,7 @@ sub GenerateConstructorGetter
V8ClassIndex::V8WrapperType type = V8ClassIndex::FromInt(data->Int32Value());
- v8::Handle<v8::FunctionTemplate> desc = V8Proxy::GetTemplate(type);
- v8::Handle<v8::Function> func = desc->GetFunction();
- ASSERT(func->IsFunction());
- return func;
+ return V8Proxy::retrieve()->GetConstructor(type);
}
END
diff --git a/webkit/port/bindings/v8/v8_index.h b/webkit/port/bindings/v8/v8_index.h
index fd5849c..2334773 100644
--- a/webkit/port/bindings/v8/v8_index.h
+++ b/webkit/port/bindings/v8/v8_index.h
@@ -443,6 +443,7 @@ class V8ClassIndex {
ALL_WRAPPER_TYPES(DEFINE_ENUM)
#undef DEFINE_ENUM
CLASSINDEX_END,
+ WRAPPER_TYPE_COUNT = CLASSINDEX_END
};
static int ToInt(V8WrapperType type) { return static_cast<int>(type); }
diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp
index 5981ef8b..e76f9de 100644
--- a/webkit/port/bindings/v8/v8_proxy.cpp
+++ b/webkit/port/bindings/v8/v8_proxy.cpp
@@ -984,6 +984,14 @@ V8Proxy::~V8Proxy()
{
clearForClose();
DestroyGlobal();
+ if (!m_constructor_cache.IsEmpty()) {
+ m_constructor_cache.Dispose();
+ m_constructor_cache.Clear();
+ }
+ if (!m_initial_object_prototype.IsEmpty()) {
+ m_initial_object_prototype.Dispose();
+ m_initial_object_prototype.Clear();
+ }
}
void V8Proxy::DestroyGlobal()
@@ -1358,6 +1366,26 @@ v8::Local<v8::Value> V8Proxy::CallFunction(v8::Handle<v8::Function> function,
}
+v8::Local<v8::Function> V8Proxy::GetConstructor(
+ V8ClassIndex::V8WrapperType t) {
+ ASSERT(ContextInitialized());
+ v8::Local<v8::Value> cached = m_constructor_cache->Get(v8::Integer::New(t));
+ if (cached->IsUndefined()) {
+ static v8::Persistent<v8::String> proto;
+ if (proto.IsEmpty()) {
+ proto = v8::Persistent<v8::String>::New(v8::String::New("__proto__"));
+ }
+ v8::Handle<v8::FunctionTemplate> templ = GetTemplate(t);
+ v8::Local<v8::Function> value = templ->GetFunction();
+ m_constructor_cache->Set(v8::Integer::New(t), value);
+ value->Set(proto, m_initial_object_prototype);
+ return value;
+ } else {
+ return v8::Local<v8::Function>::Cast(cached);
+ }
+}
+
+
v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate(
V8ClassIndex::V8WrapperType type)
{
@@ -2101,12 +2129,19 @@ void V8Proxy::initContextIfNeeded()
#endif
}
+ v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(
+ m_global->Get(v8::String::New("Object")));
+ m_initial_object_prototype = v8::Persistent<v8::Value>::New(
+ object->Get(v8::String::New("prototype")));
+ m_constructor_cache = v8::Persistent<v8::Array>::New(
+ v8::Array::New(V8ClassIndex::WRAPPER_TYPE_COUNT));
+
// Create a new JS window object and use it as the prototype for the
// shadow global object.
- v8::Persistent<v8::FunctionTemplate> window_descriptor =
- GetTemplate(V8ClassIndex::DOMWINDOW);
+ v8::Handle<v8::Function> window_constructor =
+ GetConstructor(V8ClassIndex::DOMWINDOW);
v8::Local<v8::Object> js_window =
- SafeAllocation::NewInstance(window_descriptor->GetFunction());
+ SafeAllocation::NewInstance(window_constructor);
if (js_window.IsEmpty())
return;
@@ -2420,8 +2455,7 @@ v8::Local<v8::Object> V8Proxy::InstantiateV8Object(
desc_type = V8ClassIndex::UNDETECTABLEHTMLCOLLECTION;
}
- v8::Persistent<v8::FunctionTemplate> desc = GetTemplate(desc_type);
- v8::Local<v8::Function> function = desc->GetFunction();
+ v8::Local<v8::Function> function = retrieve()->GetConstructor(desc_type);
v8::Local<v8::Object> instance = SafeAllocation::NewInstance(function);
if (!instance.IsEmpty()) {
// Avoid setting the DOM wrapper for failed allocations.
diff --git a/webkit/port/bindings/v8/v8_proxy.h b/webkit/port/bindings/v8/v8_proxy.h
index 4450dcc..912ffe0 100644
--- a/webkit/port/bindings/v8/v8_proxy.h
+++ b/webkit/port/bindings/v8/v8_proxy.h
@@ -238,6 +238,9 @@ class V8Proxy {
int argc,
v8::Handle<v8::Value> argv[]);
+ // Returns the dom constructor function for the given node type.
+ v8::Local<v8::Function> GetConstructor(V8ClassIndex::V8WrapperType type);
+
// Returns the window object of the currently executing context.
static DOMWindow* retrieveWindow();
// Returns the window object associated with a context.
@@ -516,6 +519,8 @@ class V8Proxy {
v8::Persistent<v8::Object> m_global;
v8::Persistent<v8::Value> m_document;
+ v8::Persistent<v8::Array> m_constructor_cache;
+ v8::Persistent<v8::Value> m_initial_object_prototype;
// Utility context holding JavaScript functions used internally.
static v8::Persistent<v8::Context> m_utilityContext;