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

Unified Diff: chrome/renderer/module_system.cc

Issue 9835039: Make app_custom_bindings.js lazily evaluated so it doesn't execute on every page load. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to comments Created 8 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/module_system.cc
diff --git a/chrome/renderer/module_system.cc b/chrome/renderer/module_system.cc
index 8d45dfe1f45c7c186b7b61ecfcce588e9265a698..de37918c5ed645fd5108a76c80a76a9c83313f00 100644
--- a/chrome/renderer/module_system.cc
+++ b/chrome/renderer/module_system.cc
@@ -16,7 +16,7 @@ const char* kModuleField = "module_field";
ModuleSystem::ModuleSystem(SourceMap* source_map)
: source_map_(source_map),
- natives_enabled_(true) {
+ natives_enabled_(0) {
RouteFunction("require",
base::Bind(&ModuleSystem::RequireForJs, base::Unretained(this)));
RouteFunction("requireNative",
@@ -29,6 +29,17 @@ ModuleSystem::ModuleSystem(SourceMap* source_map)
ModuleSystem::~ModuleSystem() {
}
+ModuleSystem::NativesEnabledScope::NativesEnabledScope(
+ ModuleSystem* module_system)
+ : module_system_(module_system) {
+ module_system_->natives_enabled_++;
+}
+
+ModuleSystem::NativesEnabledScope::~NativesEnabledScope() {
+ module_system_->natives_enabled_--;
+ CHECK(module_system_->natives_enabled_ >= 0);
not at google - send to devlin 2012/03/26 02:29:49 CHECK_GE(natives_enabled, 0) would give better log
koz (OOO until 15th September) 2012/03/26 03:58:59 Done.
+}
+
void ModuleSystem::Require(const std::string& module_name) {
v8::HandleScope handle_scope;
RequireForJsInner(v8::String::New(module_name.c_str()));
@@ -80,7 +91,7 @@ void ModuleSystem::RunString(const std::string& code, const std::string& name) {
}
// static
-v8::Handle<v8::Value> ModuleSystem::GetterRouter(
+v8::Handle<v8::Value> ModuleSystem::LazyFieldGetter(
v8::Local<v8::String> property, const v8::AccessorInfo& info) {
CHECK(!info.Data().IsEmpty());
CHECK(info.Data()->IsObject());
@@ -91,8 +102,12 @@ v8::Handle<v8::Value> ModuleSystem::GetterRouter(
ModuleSystem* module_system = static_cast<ModuleSystem*>(
v8::Handle<v8::External>::Cast(module_system_value)->Value());
- v8::Handle<v8::Object> module = module_system->RequireForJsInner(
- parameters->Get(v8::String::New(kModuleName))->ToString())->ToObject();
+ v8::Handle<v8::Object> module;
+ {
+ NativesEnabledScope scope(module_system);
+ module = module_system->RequireForJsInner(
+ parameters->Get(v8::String::New(kModuleName))->ToString())->ToObject();
+ }
v8::Handle<v8::String> field =
parameters->Get(v8::String::New(kModuleField))->ToString();
@@ -113,7 +128,7 @@ void ModuleSystem::SetLazyField(v8::Handle<v8::Object> object,
parameters->Set(v8::String::New(kModuleSystem), v8::External::New(this));
object->SetAccessor(v8::String::New(field.c_str()),
- &ModuleSystem::GetterRouter,
+ &ModuleSystem::LazyFieldGetter,
NULL,
parameters);
}
@@ -135,7 +150,7 @@ v8::Handle<v8::Value> ModuleSystem::GetSource(
v8::Handle<v8::Value> ModuleSystem::GetNative(const v8::Arguments& args) {
CHECK_EQ(1, args.Length());
- if (!natives_enabled_)
+ if (natives_enabled_ == 0)
return ThrowException("Natives disabled");
std::string native_name = *v8::String::AsciiValue(args[0]->ToString());
NativeHandlerMap::iterator i = native_handler_map_.find(native_name);

Powered by Google App Engine
This is Rietveld 408576698