forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This CL adds a simple shell program for Gin to make edit/test/debug cycle faster. The shell excutes a list of scripts from the command line and loads any requested AMD modules relative to the current working directory. This CL will also let us remove the ugly code in https://codereview.chromium.org/69843003/diff/240001/mojo/public/bindings/js/test/run_js_tests.cc because we now know how to file modules via the file system. Eventually for Mojo, we'll want to use a net_module_provider (instead of the file_module_provider included in this CL) to load additional AMD modules off the network. BUG=317398 R=jochen@chromium.org Review URL: https://codereview.chromium.org/74753002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235750 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
abarth@chromium.org
committed
Nov 18, 2013
1 parent
a29e465
commit 855ab43
Showing
24 changed files
with
568 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
include_rules = [ | ||
"+v8", | ||
|
||
# Use of base is allowed in tests. We can also use base in production code | ||
# as long as we don't introduce a link-time dependency. | ||
"+base", | ||
"+v8", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "gin/modules/file_module_provider.h" | ||
|
||
#include "base/bind.h" | ||
#include "base/file_util.h" | ||
#include "base/message_loop/message_loop.h" | ||
#include "base/strings/string_split.h" | ||
#include "gin/converter.h" | ||
|
||
namespace gin { | ||
|
||
namespace { | ||
|
||
void AttempToLoadModule(const base::WeakPtr<Runner>& runner, | ||
const base::FilePath& base, | ||
const std::string& id) { | ||
if (!runner) | ||
return; | ||
|
||
std::vector<std::string> components; | ||
base::SplitString(id, '/', &components); | ||
base::FilePath path = base; | ||
for (size_t i = 0; i < components.size(); ++i) { | ||
// TODO(abarth): Technically the path components can be UTF-8. We don't | ||
// handle that case correctly yet. | ||
path = path.AppendASCII(components[i]); | ||
} | ||
path = path.AddExtension(FILE_PATH_LITERAL("js")); | ||
|
||
std::string source; | ||
if (!ReadFileToString(path, &source)) | ||
return; | ||
|
||
Runner::Scope scope(runner.get()); | ||
v8::Handle<v8::Script> script = v8::Script::New( | ||
StringToV8(runner->isolate(), source), | ||
StringToV8(runner->isolate(), id)); | ||
runner->Run(script); | ||
} | ||
|
||
} // namespace | ||
|
||
FileModuleProvider::FileModuleProvider(const base::FilePath& base) | ||
: base_(base) { | ||
} | ||
|
||
FileModuleProvider::~FileModuleProvider() { | ||
} | ||
|
||
void FileModuleProvider::AttempToLoadModules( | ||
Runner* runner, const std::set<std::string>& ids) { | ||
std::set<std::string> modules = ids; | ||
for (std::set<std::string>::const_iterator it = modules.begin(); | ||
it != modules.end(); ++it) { | ||
const std::string& id = *it; | ||
if (attempted_ids_.count(id)) | ||
continue; | ||
attempted_ids_.insert(id); | ||
base::MessageLoop::current()->PostTask(FROM_HERE, | ||
base::Bind(AttempToLoadModule, runner->GetWeakPtr(), base_, id)); | ||
} | ||
} | ||
|
||
} // namespace gin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef GIN_MODULES_FILE_MODULE_PROVIDER_H_ | ||
#define GIN_MODULES_FILE_MODULE_PROVIDER_H_ | ||
|
||
#include <set> | ||
#include <string> | ||
|
||
#include "base/files/file_path.h" | ||
#include "gin/runner.h" | ||
|
||
namespace gin { | ||
|
||
class FileModuleProvider { | ||
public: | ||
explicit FileModuleProvider(const base::FilePath& base); | ||
~FileModuleProvider(); | ||
|
||
void AttempToLoadModules(Runner* runner, const std::set<std::string>& ids); | ||
|
||
private: | ||
base::FilePath base_; | ||
std::set<std::string> attempted_ids_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(FileModuleProvider); | ||
}; | ||
|
||
} // namespace gin | ||
|
||
#endif // GIN_MODULES_FILE_MODULE_PROVIDER_H_ |
Oops, something went wrong.