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

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
Index: gin/wrappable.cc
diff --git a/gin/wrappable.cc b/gin/wrappable.cc
index 4a9ef0e1935d32e0b7a5213ab6ec47a230d093db..68b84eca4875d57a513c3f50014f2cf30cbdbb29 100644
--- a/gin/wrappable.cc
+++ b/gin/wrappable.cc
@@ -17,9 +17,9 @@ WrappableBase::~WrappableBase() {
}
v8::Handle<v8::Object> WrappableBase::GetWrapperImpl(
- v8::Isolate* isolate, WrapperInfo* wrapper_info) {
+ v8::Isolate* isolate, WrapperInfo* wrapper_info, TemplateBuilder builder) {
if (wrapper_.IsEmpty())
- CreateWrapper(isolate, wrapper_info);
+ CreateWrapper(isolate, wrapper_info, builder);
return v8::Local<v8::Object>::New(isolate, wrapper_);
}
@@ -31,10 +31,15 @@ void WrappableBase::WeakCallback(
}
v8::Handle<v8::Object> WrappableBase::CreateWrapper(v8::Isolate* isolate,
- WrapperInfo* info) {
+ WrapperInfo* info,
+ TemplateBuilder builder) {
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 = builder(isolate);
+ CHECK(!templ.IsEmpty());
+ data->SetObjectTemplate(info, templ);
+ }
CHECK_EQ(kNumberOfInternalFields, templ->InternalFieldCount());
v8::Handle<v8::Object> wrapper = templ->NewInstance();
wrapper->SetAlignedPointerInInternalField(kWrapperInfoIndex, info);

Powered by Google App Engine
This is Rietveld 408576698