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

Unified Diff: chrome/renderer/extensions/v8_schema_registry.cc

Issue 12693008: Prevent ObjectBackedNativeHandler from calling itself once invalid. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/extensions/v8_schema_registry.cc
diff --git a/chrome/renderer/extensions/v8_schema_registry.cc b/chrome/renderer/extensions/v8_schema_registry.cc
index d379b4cc2f837e94b7008fdc006e792695d7d7ab..ec059fbde9d8bcd878c336d620e4b290e49fed96 100644
--- a/chrome/renderer/extensions/v8_schema_registry.cc
+++ b/chrome/renderer/extensions/v8_schema_registry.cc
@@ -17,6 +17,7 @@ V8SchemaRegistry::V8SchemaRegistry() {}
V8SchemaRegistry::~V8SchemaRegistry() {
v8::HandleScope handle_scope;
+
for (SchemaCache::iterator i = schema_cache_.begin();
i != schema_cache_.end(); ++i) {
i->second.Dispose(i->second->CreationContext()->GetIsolate());
@@ -27,28 +28,29 @@ v8::Handle<v8::Array> V8SchemaRegistry::GetSchemas(
const std::set<std::string>& apis) {
v8::HandleScope handle_scope;
v8::Context::Scope context_scope(GetOrCreateContext());
+
v8::Handle<v8::Array> v8_apis(v8::Array::New(apis.size()));
size_t api_index = 0;
for (std::set<std::string>::const_iterator i = apis.begin(); i != apis.end();
++i) {
v8_apis->Set(api_index++, GetSchema(*i));
}
- return v8_apis;
+ return handle_scope.Close(v8_apis);
}
v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) {
v8::HandleScope handle_scope;
+
SchemaCache::iterator maybe_schema = schema_cache_.find(api);
if (maybe_schema != schema_cache_.end())
- return maybe_schema->second;
-
- const base::DictionaryValue* schema =
- ExtensionAPI::GetSharedInstance()->GetSchema(api);
- CHECK(schema) << api;
+ return handle_scope.Close(maybe_schema->second);
v8::Persistent<v8::Context> context = GetOrCreateContext();
v8::Context::Scope context_scope(context);
+ const base::DictionaryValue* schema =
+ ExtensionAPI::GetSharedInstance()->GetSchema(api);
+ CHECK(schema) << api;
scoped_ptr<V8ValueConverter> v8_value_converter(V8ValueConverter::create());
v8::Handle<v8::Value> value = v8_value_converter->ToV8Value(schema, context);
CHECK(!value.IsEmpty());
@@ -56,7 +58,7 @@ v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) {
v8::Persistent<v8::Object> v8_schema = v8::Persistent<v8::Object>::New(
context->GetIsolate(), v8::Handle<v8::Object>::Cast(value));
schema_cache_[api] = v8_schema;
- return v8_schema;
+ return handle_scope.Close(v8_schema);
}
v8::Persistent<v8::Context> V8SchemaRegistry::GetOrCreateContext() {

Powered by Google App Engine
This is Rietveld 408576698