| Index: chrome/renderer/module_system.cc
|
| diff --git a/chrome/renderer/module_system.cc b/chrome/renderer/module_system.cc
|
| index 6c685f3b888badf51fe9aa789329176e9150b840..64f0c98355ec3f206fe3f5c62869ab0a9dc85d80 100644
|
| --- a/chrome/renderer/module_system.cc
|
| +++ b/chrome/renderer/module_system.cc
|
| @@ -5,21 +5,15 @@
|
| #include "chrome/renderer/module_system.h"
|
|
|
| #include "base/bind.h"
|
| -#include "chrome/renderer/static_v8_external_string_resource.h"
|
| #include "grit/renderer_resources.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
|
|
| namespace {
|
|
|
| -v8::Handle<v8::String> GetResource(int resourceId) {
|
| - const ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance();
|
| - return v8::String::NewExternal(new StaticV8ExternalAsciiStringResource(
|
| - resource_bundle.GetRawDataResource(resourceId)));
|
| -}
|
| -
|
| } // namespace
|
|
|
| -ModuleSystem::ModuleSystem(const std::map<std::string, std::string>* source_map)
|
| +ModuleSystem::ModuleSystem(
|
| + const std::map<std::string, base::StringPiece>* source_map)
|
| : source_map_(source_map) {
|
| RouteFunction("Run",
|
| base::Bind(&ModuleSystem::Run, base::Unretained(this)));
|
| @@ -73,19 +67,20 @@ v8::Handle<v8::Value> ModuleSystem::RunString(v8::Handle<v8::String> code) {
|
| }
|
|
|
| v8::Handle<v8::Value> ModuleSystem::Run(const v8::Arguments& args) {
|
| - CHECK_EQ(1, args.Length());
|
| + CHECK_EQ(2, args.Length());
|
| v8::HandleScope handle_scope;
|
| - return handle_scope.Close(v8::Script::New(args[0]->ToString())->Run());
|
| + return handle_scope.Close(
|
| + v8::Script::New(args[0]->ToString(), args[1])->Run());
|
| }
|
|
|
| v8::Handle<v8::Value> ModuleSystem::GetSource(const v8::Arguments& args) {
|
| CHECK_EQ(1, args.Length());
|
| std::string module_name = *v8::String::AsciiValue(args[0]->ToString());
|
| - std::map<std::string, std::string>::const_iterator p =
|
| + std::map<std::string, base::StringPiece>::const_iterator p =
|
| source_map_->find(module_name);
|
| if (p == source_map_->end())
|
| return v8::Undefined();
|
| - return v8::String::New(p->second.c_str());
|
| + return ConvertString(p->second);
|
| }
|
|
|
| v8::Handle<v8::Value> ModuleSystem::GetNative(const v8::Arguments& args) {
|
| @@ -96,3 +91,17 @@ v8::Handle<v8::Value> ModuleSystem::GetNative(const v8::Arguments& args) {
|
| return v8::Undefined();
|
| return i->second->NewInstance();
|
| }
|
| +
|
| +v8::Handle<v8::String> ModuleSystem::ConvertString(
|
| + const base::StringPiece& string) {
|
| + linked_ptr<StaticV8ExternalAsciiStringResource> external_string(
|
| + new StaticV8ExternalAsciiStringResource(string));
|
| + external_strings_.push_back(external_string);
|
| + return v8::String::NewExternal(external_string.get());
|
| +}
|
| +
|
| +v8::Handle<v8::String> ModuleSystem::GetResource(int resourceId) {
|
| + const ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance();
|
| + return ConvertString(resource_bundle.GetRawDataResource(resourceId));
|
| +}
|
| +
|
|
|