Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1156)

Unified Diff: gin/wrappable.cc

Issue 113893005: [gin] Introduce Wrappable::GetObjectTemplate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gin/wrappable.h ('k') | gin/wrappable_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/wrappable.cc
diff --git a/gin/wrappable.cc b/gin/wrappable.cc
index 4a9ef0e1935d32e0b7a5213ab6ec47a230d093db..3446f4fa1ea928da83da7110332dd0920085c913 100644
--- a/gin/wrappable.cc
+++ b/gin/wrappable.cc
@@ -5,6 +5,7 @@
#include "gin/wrappable.h"
#include "base/logging.h"
+#include "gin/object_template_builder.h"
#include "gin/per_isolate_data.h"
namespace gin {
@@ -17,12 +18,19 @@ WrappableBase::~WrappableBase() {
}
v8::Handle<v8::Object> WrappableBase::GetWrapperImpl(
- v8::Isolate* isolate, WrapperInfo* wrapper_info) {
+ v8::Isolate* isolate,
+ WrapperInfo* wrapper_info,
+ GetObjectTemplateFunction template_getter) {
if (wrapper_.IsEmpty())
- CreateWrapper(isolate, wrapper_info);
+ CreateWrapper(isolate, wrapper_info, template_getter);
return v8::Local<v8::Object>::New(isolate, wrapper_);
}
+v8::Local<v8::ObjectTemplate> WrappableBase::GetObjectTemplate(
+ v8::Isolate* isolate) {
+ return ObjectTemplateBuilder(isolate).Build();
+}
+
void WrappableBase::WeakCallback(
const v8::WeakCallbackData<v8::Object, WrappableBase>& data) {
WrappableBase* wrappable = data.GetParameter();
@@ -30,11 +38,17 @@ void WrappableBase::WeakCallback(
delete wrappable;
}
-v8::Handle<v8::Object> WrappableBase::CreateWrapper(v8::Isolate* isolate,
- WrapperInfo* info) {
+v8::Handle<v8::Object> WrappableBase::CreateWrapper(
+ v8::Isolate* isolate,
+ WrapperInfo* info,
+ GetObjectTemplateFunction template_getter) {
PerIsolateData* data = PerIsolateData::From(isolate);
v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(info);
- CHECK(!templ.IsEmpty()); // Don't forget to register an object template.
+ if (templ.IsEmpty()) {
+ templ = template_getter(isolate);
+ CHECK(!templ.IsEmpty());
+ data->SetObjectTemplate(info, templ);
+ }
CHECK_EQ(kNumberOfInternalFields, templ->InternalFieldCount());
v8::Handle<v8::Object> wrapper = templ->NewInstance();
wrapper->SetAlignedPointerInInternalField(kWrapperInfoIndex, info);
« no previous file with comments | « gin/wrappable.h ('k') | gin/wrappable_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698