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

Side by Side Diff: samples/shell.cc

Issue 275463002: Unbreak samples and tools. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/process.cc ('k') | src/d8.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 void Load(const v8::FunctionCallbackInfo<v8::Value>& args); 58 void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
59 void Quit(const v8::FunctionCallbackInfo<v8::Value>& args); 59 void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
60 void Version(const v8::FunctionCallbackInfo<v8::Value>& args); 60 void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
61 v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name); 61 v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name);
62 void ReportException(v8::Isolate* isolate, v8::TryCatch* handler); 62 void ReportException(v8::Isolate* isolate, v8::TryCatch* handler);
63 63
64 64
65 static bool run_shell; 65 static bool run_shell;
66 66
67 67
68 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
69 public:
70 virtual void* Allocate(size_t length) {
71 return memset(AllocateUninitialized(length), 0, length);
72 }
73 virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
74 virtual void Free(void* data, size_t) { free(data); }
75 };
76
77
68 int main(int argc, char* argv[]) { 78 int main(int argc, char* argv[]) {
69 v8::V8::InitializeICU(); 79 v8::V8::InitializeICU();
70 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 80 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
71 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 81 ShellArrayBufferAllocator array_buffer_allocator;
82 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
83 v8::Isolate* isolate = v8::Isolate::New();
72 run_shell = (argc == 1); 84 run_shell = (argc == 1);
73 int result; 85 int result;
74 { 86 {
87 v8::Isolate::Scope isolate_scope(isolate);
75 v8::HandleScope handle_scope(isolate); 88 v8::HandleScope handle_scope(isolate);
76 v8::Handle<v8::Context> context = CreateShellContext(isolate); 89 v8::Handle<v8::Context> context = CreateShellContext(isolate);
77 if (context.IsEmpty()) { 90 if (context.IsEmpty()) {
78 fprintf(stderr, "Error creating context\n"); 91 fprintf(stderr, "Error creating context\n");
79 return 1; 92 return 1;
80 } 93 }
81 context->Enter(); 94 v8::Context::Scope context_scope(context);
82 result = RunMain(isolate, argc, argv); 95 result = RunMain(isolate, argc, argv);
83 if (run_shell) RunShell(context); 96 if (run_shell) RunShell(context);
84 context->Exit();
85 } 97 }
86 v8::V8::Dispose(); 98 v8::V8::Dispose();
87 return result; 99 return result;
88 } 100 }
89 101
90 102
91 // Extracts a C string from a V8 Utf8Value. 103 // Extracts a C string from a V8 Utf8Value.
92 const char* ToCString(const v8::String::Utf8Value& value) { 104 const char* ToCString(const v8::String::Utf8Value& value) {
93 return *value ? *value : "<string conversion failed>"; 105 return *value ? *value : "<string conversion failed>";
94 } 106 }
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 fprintf(stderr, "^"); 375 fprintf(stderr, "^");
364 } 376 }
365 fprintf(stderr, "\n"); 377 fprintf(stderr, "\n");
366 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); 378 v8::String::Utf8Value stack_trace(try_catch->StackTrace());
367 if (stack_trace.length() > 0) { 379 if (stack_trace.length() > 0) {
368 const char* stack_trace_string = ToCString(stack_trace); 380 const char* stack_trace_string = ToCString(stack_trace);
369 fprintf(stderr, "%s\n", stack_trace_string); 381 fprintf(stderr, "%s\n", stack_trace_string);
370 } 382 }
371 } 383 }
372 } 384 }
OLDNEW
« no previous file with comments | « samples/process.cc ('k') | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698