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

Side by Side Diff: ppapi/cpp/var.cc

Issue 7511026: Fix some egregious bugs in Var. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 4 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ppapi/cpp/var.h" 5 #include "ppapi/cpp/var.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 needs_release_ = false; 110 needs_release_ = false;
111 } 111 }
112 } 112 }
113 113
114 Var::~Var() { 114 Var::~Var() {
115 if (needs_release_ && has_interface<PPB_Var>()) 115 if (needs_release_ && has_interface<PPB_Var>())
116 get_interface<PPB_Var>()->Release(var_); 116 get_interface<PPB_Var>()->Release(var_);
117 } 117 }
118 118
119 Var& Var::operator=(const Var& other) { 119 Var& Var::operator=(const Var& other) {
120 if (needs_release_ && has_interface<PPB_Var>()) 120 // Be careful to keep the ref alive for cases where we're assigning an
121 get_interface<PPB_Var>()->Release(var_); 121 // object to itself by addrefing the new one before releasing the old one.
122 var_ = other.var_; 122 bool old_needs_release = needs_release_;
123 if (NeedsRefcounting(var_)) { 123 if (NeedsRefcounting(other.var_)) {
124 if (has_interface<PPB_Var>()) { 124 // Assume we already has_interface<PPB_Var> for refcounted vars or else we
125 needs_release_ = true; 125 // couldn't have created them in the first place.
126 get_interface<PPB_Var>()->AddRef(var_); 126 needs_release_ = true;
127 } else { 127 get_interface<PPB_Var>()->AddRef(other.var_);
128 var_.type = PP_VARTYPE_NULL;
129 needs_release_ = false;
130 }
131 } else { 128 } else {
132 needs_release_ = false; 129 needs_release_ = false;
133 } 130 }
131 if (old_needs_release)
132 get_interface<PPB_Var>()->Release(var_);
133
134 var_ = other.var_;
134 return *this; 135 return *this;
135 } 136 }
136 137
137 bool Var::operator==(const Var& other) const { 138 bool Var::operator==(const Var& other) const {
138 if (var_.type != other.var_.type) 139 if (var_.type != other.var_.type)
139 return false; 140 return false;
140 switch (var_.type) { 141 switch (var_.type) {
141 case PP_VARTYPE_UNDEFINED: 142 case PP_VARTYPE_UNDEFINED:
142 case PP_VARTYPE_NULL: 143 case PP_VARTYPE_NULL:
143 return true; 144 return true;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 str.append("..."); 221 str.append("...");
221 } 222 }
222 snprintf(buf, sizeof(buf), format, str.c_str()); 223 snprintf(buf, sizeof(buf), format, str.c_str());
223 } else if (is_object()) { 224 } else if (is_object()) {
224 snprintf(buf, sizeof(buf), "Var<OBJECT>"); 225 snprintf(buf, sizeof(buf), "Var<OBJECT>");
225 } 226 }
226 return buf; 227 return buf;
227 } 228 }
228 229
229 } // namespace pp 230 } // namespace pp
OLDNEW
« ppapi/cpp/var.h ('K') | « ppapi/cpp/var.h ('k') | ppapi/tests/test_var.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698