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

Unified Diff: samples/shell.cc

Issue 435003: Patch for allowing several V8 instances in process:... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years 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
« no previous file with comments | « include/v8.h ('k') | src/SConscript » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/shell.cc
===================================================================
--- samples/shell.cc (revision 3427)
+++ samples/shell.cc (working copy)
@@ -24,14 +24,20 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#define V8_TEST
+#ifdef V8_TEST
+#define WIN32
+#include <../src/v8.h>
+#include <../src/v8-global-context.h>
+#else
#include <v8.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#endif
-
void RunShell(v8::Handle<v8::Context> context);
bool ExecuteString(v8::Handle<v8::String> source,
v8::Handle<v8::Value> name,
@@ -47,7 +53,6 @@
int RunMain(int argc, char* argv[]) {
- v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
v8::HandleScope handle_scope;
// Create a template for the global object.
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
@@ -102,11 +107,56 @@
return 0;
}
+#ifdef V8_TEST
+v8::AllowSeveralV8InstancesInProcess v8_please;
+class V8Runner: public v8::internal::Thread {
+ public:
+ V8Runner(int argc, char* argv[])
+ :argc_(argc), argv_(argv) {
+ }
+
+ int result() const { return result_; }
+ private:
+ int argc_;
+ char** const argv_;
+ int result_;
+
+ virtual void Run() {
+ v8::V8ContextProvider v8_context_provider;
+ v8::V8ContextBinder v8_context_binder(v8_context_provider);
+ result_ = RunMain(argc_, argv_);
+ v8::V8::Dispose();
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(V8Runner);
+};
+#endif
+
int main(int argc, char* argv[]) {
+ v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
+#ifdef V8_TEST
+ const int kAdditionalParallelThreads = 0;
+ V8Runner** runners = new V8Runner*[kAdditionalParallelThreads];
+ for (int i = 0; i < kAdditionalParallelThreads; ++i) {
+ runners[i] = new V8Runner(argc, argv);
+ runners[i]->Start();
+ }
+#endif
+
int result = RunMain(argc, argv);
v8::V8::Dispose();
- return result;
+
+ bool allResultsTheSame = true;
+#ifdef V8_TEST
+ for (int i = 0; i < kAdditionalParallelThreads; ++i) {
+ runners[i]->Join();
+ if (result != runners[i]->result()) {
+ allResultsTheSame = false;
+ }
+ }
+#endif
+ return allResultsTheSame ? result : -1;
}
« no previous file with comments | « include/v8.h ('k') | src/SConscript » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698