From 4b6af4f75e9ad65588f01d9e980a0cc427695d91 Mon Sep 17 00:00:00 2001 From: "deanm@google.com" Date: Wed, 27 Aug 2008 12:41:22 +0000 Subject: Move a bunch of code-driven binding template configuration to a data-driven approach. This reduces the code size, and the overall binary size. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1435 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/port/bindings/v8/v8_proxy.cpp | 35 ++++++++++++++++++++++++++++++++++- webkit/port/bindings/v8/v8_proxy.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) (limited to 'webkit/port/bindings/v8') diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp index b5398a1..5cfcd62 100644 --- a/webkit/port/bindings/v8/v8_proxy.cpp +++ b/webkit/port/bindings/v8/v8_proxy.cpp @@ -183,7 +183,40 @@ void V8Proxy::UnregisterGlobalHandle(void* host, ASSERT(info->host_ == host); delete info; } -#endif +#endif // ifndef NDEBUG + +void BatchConfigureAttributes(v8::Handle inst, + v8::Handle proto, + const BatchedAttribute* attrs, + size_t num_attrs) { + for (size_t i = 0; i < num_attrs; ++i) { + const BatchedAttribute* a = &attrs[i]; + (a->on_proto ? proto : inst)->SetAccessor( + v8::String::New(a->name), + a->getter, + a->setter, + a->data == V8ClassIndex::INVALID_CLASS_INDEX + ? v8::Handle() + : v8::Integer::New(V8ClassIndex::ToInt(a->data)), + a->settings, + a->attribute); + } +} + +void BatchConfigureConstants(v8::Handle desc, + v8::Handle proto, + const BatchedConstant* consts, + size_t num_consts) { + for (size_t i = 0; i < num_consts; ++i) { + const BatchedConstant* c = &consts[i]; + desc->Set(v8::String::New(c->name), + v8::Integer::New(c->value), + v8::ReadOnly); + proto->Set(v8::String::New(c->name), + v8::Integer::New(c->value), + v8::ReadOnly); + } +} typedef HashMap NodeMap; diff --git a/webkit/port/bindings/v8/v8_proxy.h b/webkit/port/bindings/v8/v8_proxy.h index 40909c0..23d1f95 100644 --- a/webkit/port/bindings/v8/v8_proxy.h +++ b/webkit/port/bindings/v8/v8_proxy.h @@ -103,6 +103,41 @@ class GlobalHandleInfo { #endif // NDEBUG +// The following Batch structs and methods are used for setting multiple +// properties on an ObjectTemplate, used from the generated bindings +// initialization (ConfigureXXXTemplate). This greatly reduces the binary +// size by moving from code driven setup to data table driven setup. + +// BatchedAttribute translates into calls to SetAccessor() on either the +// instance or the prototype ObjectTemplate, based on |on_proto|. +struct BatchedAttribute { + const char* const name; + v8::AccessorGetter getter; + v8::AccessorSetter setter; + V8ClassIndex::V8WrapperType data; + v8::AccessControl settings; + v8::PropertyAttribute attribute; + bool on_proto; +}; + +void BatchConfigureAttributes(v8::Handle inst, + v8::Handle proto, + const BatchedAttribute* attrs, + size_t num_attrs); + +// BhatchedConstant translates into calls to Set() for setting up an object's +// constants. It sets the constant on both the FunctionTemplate |desc| and the +// ObjectTemplate |proto|. PropertyAttributes is always ReadOnly. +struct BatchedConstant { + const char* const name; + int value; +}; + +void BatchConfigureConstants(v8::Handle desc, + v8::Handle proto, + const BatchedConstant* consts, + size_t num_consts); + class V8Proxy { public: // The types of javascript errors that can be thrown. -- cgit v1.1