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

Side by Side Diff: gin/wrappable.cc

Issue 184253004: gin: Bug fix: Fix CreateHandle to return an emtpy handle in some extreme cases (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bug fix: remove an extra include Created 6 years, 9 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gin/handle.h ('k') | gin/wrappable_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gin/wrappable.h" 5 #include "gin/wrappable.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "gin/object_template_builder.h" 8 #include "gin/object_template_builder.h"
9 #include "gin/per_isolate_data.h" 9 #include "gin/per_isolate_data.h"
10 10
(...skipping 26 matching lines...) Expand all
37 37
38 PerIsolateData* data = PerIsolateData::From(isolate); 38 PerIsolateData* data = PerIsolateData::From(isolate);
39 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(info); 39 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(info);
40 if (templ.IsEmpty()) { 40 if (templ.IsEmpty()) {
41 templ = GetObjectTemplateBuilder(isolate).Build(); 41 templ = GetObjectTemplateBuilder(isolate).Build();
42 CHECK(!templ.IsEmpty()); 42 CHECK(!templ.IsEmpty());
43 data->SetObjectTemplate(info, templ); 43 data->SetObjectTemplate(info, templ);
44 } 44 }
45 CHECK_EQ(kNumberOfInternalFields, templ->InternalFieldCount()); 45 CHECK_EQ(kNumberOfInternalFields, templ->InternalFieldCount());
46 v8::Handle<v8::Object> wrapper = templ->NewInstance(); 46 v8::Handle<v8::Object> wrapper = templ->NewInstance();
47 // |wrapper| may be empty in some extreme cases, e.g., when
48 // Object.prototype.constructor is overwritten.
49 if (wrapper.IsEmpty()) {
50 // The current wrappable object will be no longer managed by V8. Delete this
51 // now.
52 delete this;
53 return wrapper;
54 }
47 wrapper->SetAlignedPointerInInternalField(kWrapperInfoIndex, info); 55 wrapper->SetAlignedPointerInInternalField(kWrapperInfoIndex, info);
48 wrapper->SetAlignedPointerInInternalField(kEncodedValueIndex, this); 56 wrapper->SetAlignedPointerInInternalField(kEncodedValueIndex, this);
49 wrapper_.Reset(isolate, wrapper); 57 wrapper_.Reset(isolate, wrapper);
50 wrapper_.SetWeak(this, WeakCallback); 58 wrapper_.SetWeak(this, WeakCallback);
51 return wrapper; 59 return wrapper;
52 } 60 }
53 61
54 namespace internal { 62 namespace internal {
55 63
56 void* FromV8Impl(v8::Isolate* isolate, v8::Handle<v8::Value> val, 64 void* FromV8Impl(v8::Isolate* isolate, v8::Handle<v8::Value> val,
(...skipping 13 matching lines...) Expand all
70 // instance of the C++ class associated with wrapper_info. 78 // instance of the C++ class associated with wrapper_info.
71 if (info != wrapper_info) 79 if (info != wrapper_info)
72 return NULL; 80 return NULL;
73 81
74 return obj->GetAlignedPointerFromInternalField(kEncodedValueIndex); 82 return obj->GetAlignedPointerFromInternalField(kEncodedValueIndex);
75 } 83 }
76 84
77 } // namespace internal 85 } // namespace internal
78 86
79 } // namespace gin 87 } // namespace gin
OLDNEW
« no previous file with comments | « gin/handle.h ('k') | gin/wrappable_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698