summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-02 12:50:50 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-02 12:50:50 +0000
commit6f59d3bfe4e87215a6595e4490ee7272d649cc82 (patch)
tree3d47ed43a9525ac30410af7fe87eba7989163768
parent24c5437b9d7e5a77d00997d356963bedc218b686 (diff)
downloadchromium_src-6f59d3bfe4e87215a6595e4490ee7272d649cc82.zip
chromium_src-6f59d3bfe4e87215a6595e4490ee7272d649cc82.tar.gz
chromium_src-6f59d3bfe4e87215a6595e4490ee7272d649cc82.tar.bz2
Refactor ModuleSystem so it passes an Isolate around
BUG=324225 R=marja@chromium.org Review URL: https://codereview.chromium.org/98623003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238079 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/extensions/module_system.cc2
-rw-r--r--chrome/renderer/extensions/module_system.h3
-rw-r--r--chrome/renderer/resource_bundle_source_map.cc10
-rw-r--r--chrome/renderer/resource_bundle_source_map.h6
-rw-r--r--chrome/test/base/module_system_test.cc18
5 files changed, 23 insertions, 16 deletions
diff --git a/chrome/renderer/extensions/module_system.cc b/chrome/renderer/extensions/module_system.cc
index b77163d..4c19623 100644
--- a/chrome/renderer/extensions/module_system.cc
+++ b/chrome/renderer/extensions/module_system.cc
@@ -507,7 +507,7 @@ v8::Handle<v8::Value> ModuleSystem::GetSource(const std::string& module_name) {
v8::HandleScope handle_scope(GetIsolate());
if (!source_map_->Contains(module_name))
return v8::Undefined();
- return handle_scope.Close(source_map_->GetSource(module_name));
+ return handle_scope.Close(source_map_->GetSource(GetIsolate(), module_name));
}
void ModuleSystem::RequireNative(
diff --git a/chrome/renderer/extensions/module_system.h b/chrome/renderer/extensions/module_system.h
index d2ad8af..3e1b85b 100644
--- a/chrome/renderer/extensions/module_system.h
+++ b/chrome/renderer/extensions/module_system.h
@@ -42,7 +42,8 @@ class ModuleSystem : public ObjectBackedNativeHandler {
class SourceMap {
public:
virtual ~SourceMap() {}
- virtual v8::Handle<v8::Value> GetSource(const std::string& name) = 0;
+ virtual v8::Handle<v8::Value> GetSource(v8::Isolate* isolate,
+ const std::string& name) = 0;
virtual bool Contains(const std::string& name) = 0;
};
diff --git a/chrome/renderer/resource_bundle_source_map.cc b/chrome/renderer/resource_bundle_source_map.cc
index 5fab053..6a7ff02 100644
--- a/chrome/renderer/resource_bundle_source_map.cc
+++ b/chrome/renderer/resource_bundle_source_map.cc
@@ -20,12 +20,13 @@ void ResourceBundleSourceMap::RegisterSource(const std::string& name,
}
v8::Handle<v8::Value> ResourceBundleSourceMap::GetSource(
+ v8::Isolate* isolate,
const std::string& name) {
if (!Contains(name))
- return v8::Undefined();
+ return v8::Undefined(isolate);
int resource_id = resource_id_map_[name];
- return ConvertString(resource_bundle_->GetRawDataResource(
- resource_id));
+ return ConvertString(isolate,
+ resource_bundle_->GetRawDataResource(resource_id));
}
bool ResourceBundleSourceMap::Contains(const std::string& name) {
@@ -33,9 +34,10 @@ bool ResourceBundleSourceMap::Contains(const std::string& name) {
}
v8::Handle<v8::String> ResourceBundleSourceMap::ConvertString(
+ v8::Isolate* isolate,
const base::StringPiece& string) {
// v8 takes ownership of the StaticV8ExternalAsciiStringResource (see
// v8::String::NewExternal()).
return v8::String::NewExternal(
- new StaticV8ExternalAsciiStringResource(string));
+ isolate, new StaticV8ExternalAsciiStringResource(string));
}
diff --git a/chrome/renderer/resource_bundle_source_map.h b/chrome/renderer/resource_bundle_source_map.h
index 056ac04..a88b165 100644
--- a/chrome/renderer/resource_bundle_source_map.h
+++ b/chrome/renderer/resource_bundle_source_map.h
@@ -24,13 +24,15 @@ class ResourceBundleSourceMap : public extensions::ModuleSystem::SourceMap {
explicit ResourceBundleSourceMap(const ui::ResourceBundle* resource_bundle);
virtual ~ResourceBundleSourceMap();
- virtual v8::Handle<v8::Value> GetSource(const std::string& name) OVERRIDE;
+ virtual v8::Handle<v8::Value> GetSource(v8::Isolate* isolate,
+ const std::string& name) OVERRIDE;
virtual bool Contains(const std::string& name) OVERRIDE;
void RegisterSource(const std::string& name, int resource_id);
private:
- v8::Handle<v8::String> ConvertString(const base::StringPiece& string);
+ v8::Handle<v8::String> ConvertString(v8::Isolate* isolate,
+ const base::StringPiece& string);
const ui::ResourceBundle* resource_bundle_;
std::map<std::string, int> resource_id_map_;
diff --git a/chrome/test/base/module_system_test.cc b/chrome/test/base/module_system_test.cc
index f4aa645..dd4ca2a8 100644
--- a/chrome/test/base/module_system_test.cc
+++ b/chrome/test/base/module_system_test.cc
@@ -99,10 +99,11 @@ class ModuleSystemTest::StringSourceMap : public ModuleSystem::SourceMap {
StringSourceMap() {}
virtual ~StringSourceMap() {}
- virtual v8::Handle<v8::Value> GetSource(const std::string& name) OVERRIDE {
+ virtual v8::Handle<v8::Value> GetSource(v8::Isolate* isolate,
+ const std::string& name) OVERRIDE {
if (source_map_.count(name) == 0)
- return v8::Undefined();
- return v8::String::New(source_map_[name].c_str());
+ return v8::Undefined(isolate);
+ return v8::String::NewFromUtf8(isolate, source_map_[name].c_str());
}
virtual bool Contains(const std::string& name) OVERRIDE {
@@ -188,9 +189,10 @@ void ModuleSystemTest::ExpectNoAssertionsMade() {
}
v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) {
- v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
- v8::Handle<v8::Object> object = v8::Object::New();
- v8::Context::GetCurrent()->Global()->Set(v8::String::New(name.c_str()),
- object);
- return handle_scope.Close(object);
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::EscapableHandleScope handle_scope(isolate);
+ v8::Local<v8::Object> object = v8::Object::New(isolate);
+ isolate->GetCurrentContext()->Global()->Set(
+ v8::String::NewFromUtf8(isolate, name.c_str()), object);
+ return handle_scope.Escape(object);
}