blob: b66e8f7453d1b38c323b157d5859778f3441b98b [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2012 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
Ben Murdochb8a8cc12014-11-26 15:28:44 +000028#include <include/v8.h>
29
30#include <include/libplatform/libplatform.h>
31
Ben Murdoche0cee9b2011-05-25 10:26:03 +010032#include <assert.h>
Steve Blocka7e24c12009-10-30 11:49:00 +000033#include <fcntl.h>
Steve Blocka7e24c12009-10-30 11:49:00 +000034#include <stdio.h>
35#include <stdlib.h>
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036#include <string.h>
Steve Blocka7e24c12009-10-30 11:49:00 +000037
Ben Murdoch69a99ed2011-11-30 16:03:39 +000038#ifdef COMPRESS_STARTUP_DATA_BZ2
39#error Using compressed startup data is not supported for this sample
Steve Block44f0eee2011-05-26 01:26:41 +010040#endif
41
Ben Murdoch69a99ed2011-11-30 16:03:39 +000042/**
43 * This sample program shows how to implement a simple javascript shell
44 * based on V8. This includes initializing V8 with command line options,
45 * creating global functions, compiling and executing strings.
46 *
47 * For a more sophisticated shell, consider using the debug shell D8.
48 */
49
Steve Block44f0eee2011-05-26 01:26:41 +010050
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051v8::Handle<v8::Context> CreateShellContext(v8::Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +000052void RunShell(v8::Handle<v8::Context> context);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000053int RunMain(v8::Isolate* isolate, int argc, char* argv[]);
54bool ExecuteString(v8::Isolate* isolate,
55 v8::Handle<v8::String> source,
Steve Blocka7e24c12009-10-30 11:49:00 +000056 v8::Handle<v8::Value> name,
57 bool print_result,
58 bool report_exceptions);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
60void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
61void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
62void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
63void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
64v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name);
65void ReportException(v8::Isolate* isolate, v8::TryCatch* handler);
Steve Blocka7e24c12009-10-30 11:49:00 +000066
67
Ben Murdoch69a99ed2011-11-30 16:03:39 +000068static bool run_shell;
Steve Block44f0eee2011-05-26 01:26:41 +010069
70
Ben Murdochb8a8cc12014-11-26 15:28:44 +000071class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
72 public:
73 virtual void* Allocate(size_t length) {
74 void* data = AllocateUninitialized(length);
75 return data == NULL ? data : memset(data, 0, length);
Steve Block44f0eee2011-05-26 01:26:41 +010076 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000077 virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
78 virtual void Free(void* data, size_t) { free(data); }
79};
80
81
82int main(int argc, char* argv[]) {
83 v8::V8::InitializeICU();
84 v8::Platform* platform = v8::platform::CreateDefaultPlatform();
85 v8::V8::InitializePlatform(platform);
86 v8::V8::Initialize();
87 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
88 ShellArrayBufferAllocator array_buffer_allocator;
89 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
90 v8::Isolate* isolate = v8::Isolate::New();
91 run_shell = (argc == 1);
92 int result;
93 {
94 v8::Isolate::Scope isolate_scope(isolate);
95 v8::HandleScope handle_scope(isolate);
96 v8::Handle<v8::Context> context = CreateShellContext(isolate);
97 if (context.IsEmpty()) {
98 fprintf(stderr, "Error creating context\n");
99 return 1;
100 }
101 v8::Context::Scope context_scope(context);
102 result = RunMain(isolate, argc, argv);
103 if (run_shell) RunShell(context);
104 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000105 v8::V8::Dispose();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000106 v8::V8::ShutdownPlatform();
107 delete platform;
Steve Blocka7e24c12009-10-30 11:49:00 +0000108 return result;
109}
110
111
112// Extracts a C string from a V8 Utf8Value.
113const char* ToCString(const v8::String::Utf8Value& value) {
114 return *value ? *value : "<string conversion failed>";
115}
116
117
Steve Block44f0eee2011-05-26 01:26:41 +0100118// Creates a new execution environment containing the built-in
119// functions.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000120v8::Handle<v8::Context> CreateShellContext(v8::Isolate* isolate) {
Steve Block44f0eee2011-05-26 01:26:41 +0100121 // Create a template for the global object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000122 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100123 // Bind the global 'print' function to the C++ Print callback.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000124 global->Set(v8::String::NewFromUtf8(isolate, "print"),
125 v8::FunctionTemplate::New(isolate, Print));
Steve Block44f0eee2011-05-26 01:26:41 +0100126 // Bind the global 'read' function to the C++ Read callback.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000127 global->Set(v8::String::NewFromUtf8(isolate, "read"),
128 v8::FunctionTemplate::New(isolate, Read));
Steve Block44f0eee2011-05-26 01:26:41 +0100129 // Bind the global 'load' function to the C++ Load callback.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000130 global->Set(v8::String::NewFromUtf8(isolate, "load"),
131 v8::FunctionTemplate::New(isolate, Load));
Steve Block44f0eee2011-05-26 01:26:41 +0100132 // Bind the 'quit' function
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000133 global->Set(v8::String::NewFromUtf8(isolate, "quit"),
134 v8::FunctionTemplate::New(isolate, Quit));
Steve Block44f0eee2011-05-26 01:26:41 +0100135 // Bind the 'version' function
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000136 global->Set(v8::String::NewFromUtf8(isolate, "version"),
137 v8::FunctionTemplate::New(isolate, Version));
Ben Murdoch8b112d22011-06-08 16:22:53 +0100138
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000139 return v8::Context::New(isolate, NULL, global);
Steve Block44f0eee2011-05-26 01:26:41 +0100140}
141
142
Steve Blocka7e24c12009-10-30 11:49:00 +0000143// The callback that is invoked by v8 whenever the JavaScript 'print'
144// function is called. Prints its arguments on stdout separated by
145// spaces and ending with a newline.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000146void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000147 bool first = true;
148 for (int i = 0; i < args.Length(); i++) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000149 v8::HandleScope handle_scope(args.GetIsolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000150 if (first) {
151 first = false;
152 } else {
153 printf(" ");
154 }
155 v8::String::Utf8Value str(args[i]);
156 const char* cstr = ToCString(str);
157 printf("%s", cstr);
158 }
159 printf("\n");
160 fflush(stdout);
Steve Blocka7e24c12009-10-30 11:49:00 +0000161}
162
163
164// The callback that is invoked by v8 whenever the JavaScript 'read'
165// function is called. This function loads the content of the file named in
166// the argument into a JavaScript string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000167void Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000168 if (args.Length() != 1) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000169 args.GetIsolate()->ThrowException(
170 v8::String::NewFromUtf8(args.GetIsolate(), "Bad parameters"));
171 return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000172 }
173 v8::String::Utf8Value file(args[0]);
174 if (*file == NULL) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000175 args.GetIsolate()->ThrowException(
176 v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file"));
177 return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000178 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000179 v8::Handle<v8::String> source = ReadFile(args.GetIsolate(), *file);
Steve Blocka7e24c12009-10-30 11:49:00 +0000180 if (source.IsEmpty()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000181 args.GetIsolate()->ThrowException(
182 v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file"));
183 return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000184 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000185 args.GetReturnValue().Set(source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000186}
187
188
189// The callback that is invoked by v8 whenever the JavaScript 'load'
190// function is called. Loads, compiles and executes its argument
191// JavaScript file.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000192void Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000193 for (int i = 0; i < args.Length(); i++) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000194 v8::HandleScope handle_scope(args.GetIsolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000195 v8::String::Utf8Value file(args[i]);
196 if (*file == NULL) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000197 args.GetIsolate()->ThrowException(
198 v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file"));
199 return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000200 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000201 v8::Handle<v8::String> source = ReadFile(args.GetIsolate(), *file);
Steve Blocka7e24c12009-10-30 11:49:00 +0000202 if (source.IsEmpty()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000203 args.GetIsolate()->ThrowException(
204 v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file"));
205 return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000206 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000207 if (!ExecuteString(args.GetIsolate(),
208 source,
209 v8::String::NewFromUtf8(args.GetIsolate(), *file),
210 false,
211 false)) {
212 args.GetIsolate()->ThrowException(
213 v8::String::NewFromUtf8(args.GetIsolate(), "Error executing file"));
214 return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000215 }
216 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000217}
218
219
220// The callback that is invoked by v8 whenever the JavaScript 'quit'
221// function is called. Quits.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000222void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000223 // If not arguments are given args[0] will yield undefined which
224 // converts to the integer value 0.
225 int exit_code = args[0]->Int32Value();
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000226 fflush(stdout);
227 fflush(stderr);
228 exit(exit_code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000229}
230
231
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000232void Version(const v8::FunctionCallbackInfo<v8::Value>& args) {
233 args.GetReturnValue().Set(
234 v8::String::NewFromUtf8(args.GetIsolate(), v8::V8::GetVersion()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000235}
236
237
238// Reads a file into a v8 string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000239v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000240 FILE* file = fopen(name, "rb");
241 if (file == NULL) return v8::Handle<v8::String>();
242
243 fseek(file, 0, SEEK_END);
244 int size = ftell(file);
245 rewind(file);
246
247 char* chars = new char[size + 1];
248 chars[size] = '\0';
249 for (int i = 0; i < size;) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000250 int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
Steve Blocka7e24c12009-10-30 11:49:00 +0000251 i += read;
252 }
253 fclose(file);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000254 v8::Handle<v8::String> result =
255 v8::String::NewFromUtf8(isolate, chars, v8::String::kNormalString, size);
Steve Blocka7e24c12009-10-30 11:49:00 +0000256 delete[] chars;
257 return result;
258}
259
260
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000261// Process remaining command line arguments and execute files
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000262int RunMain(v8::Isolate* isolate, int argc, char* argv[]) {
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000263 for (int i = 1; i < argc; i++) {
264 const char* str = argv[i];
265 if (strcmp(str, "--shell") == 0) {
266 run_shell = true;
267 } else if (strcmp(str, "-f") == 0) {
268 // Ignore any -f flags for compatibility with the other stand-
269 // alone JavaScript engines.
270 continue;
271 } else if (strncmp(str, "--", 2) == 0) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000272 fprintf(stderr,
273 "Warning: unknown flag %s.\nTry --help for options\n", str);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000274 } else if (strcmp(str, "-e") == 0 && i + 1 < argc) {
275 // Execute argument given to -e option directly.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000276 v8::Handle<v8::String> file_name =
277 v8::String::NewFromUtf8(isolate, "unnamed");
278 v8::Handle<v8::String> source =
279 v8::String::NewFromUtf8(isolate, argv[++i]);
280 if (!ExecuteString(isolate, source, file_name, false, true)) return 1;
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000281 } else {
282 // Use all other arguments as names of files to load and run.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000283 v8::Handle<v8::String> file_name = v8::String::NewFromUtf8(isolate, str);
284 v8::Handle<v8::String> source = ReadFile(isolate, str);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000285 if (source.IsEmpty()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000286 fprintf(stderr, "Error reading '%s'\n", str);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000287 continue;
288 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000289 if (!ExecuteString(isolate, source, file_name, false, true)) return 1;
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000290 }
291 }
292 return 0;
293}
294
295
Steve Blocka7e24c12009-10-30 11:49:00 +0000296// The read-eval-execute loop of the shell.
297void RunShell(v8::Handle<v8::Context> context) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000298 fprintf(stderr, "V8 version %s [sample shell]\n", v8::V8::GetVersion());
Steve Blocka7e24c12009-10-30 11:49:00 +0000299 static const int kBufferSize = 256;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100300 // Enter the execution environment before evaluating any code.
301 v8::Context::Scope context_scope(context);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000302 v8::Local<v8::String> name(
303 v8::String::NewFromUtf8(context->GetIsolate(), "(shell)"));
Steve Blocka7e24c12009-10-30 11:49:00 +0000304 while (true) {
305 char buffer[kBufferSize];
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000306 fprintf(stderr, "> ");
Steve Blocka7e24c12009-10-30 11:49:00 +0000307 char* str = fgets(buffer, kBufferSize, stdin);
308 if (str == NULL) break;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000309 v8::HandleScope handle_scope(context->GetIsolate());
310 ExecuteString(context->GetIsolate(),
311 v8::String::NewFromUtf8(context->GetIsolate(), str),
312 name,
313 true,
314 true);
Steve Blocka7e24c12009-10-30 11:49:00 +0000315 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000316 fprintf(stderr, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000317}
318
319
320// Executes a string within the current v8 context.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000321bool ExecuteString(v8::Isolate* isolate,
322 v8::Handle<v8::String> source,
Steve Blocka7e24c12009-10-30 11:49:00 +0000323 v8::Handle<v8::Value> name,
324 bool print_result,
325 bool report_exceptions) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000326 v8::HandleScope handle_scope(isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000327 v8::TryCatch try_catch;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000328 v8::ScriptOrigin origin(name);
329 v8::Handle<v8::Script> script = v8::Script::Compile(source, &origin);
Steve Blocka7e24c12009-10-30 11:49:00 +0000330 if (script.IsEmpty()) {
331 // Print errors that happened during compilation.
332 if (report_exceptions)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000333 ReportException(isolate, &try_catch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000334 return false;
335 } else {
336 v8::Handle<v8::Value> result = script->Run();
337 if (result.IsEmpty()) {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100338 assert(try_catch.HasCaught());
Steve Blocka7e24c12009-10-30 11:49:00 +0000339 // Print errors that happened during execution.
340 if (report_exceptions)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000341 ReportException(isolate, &try_catch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000342 return false;
343 } else {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100344 assert(!try_catch.HasCaught());
Steve Blocka7e24c12009-10-30 11:49:00 +0000345 if (print_result && !result->IsUndefined()) {
346 // If all went well and the result wasn't undefined then print
347 // the returned value.
348 v8::String::Utf8Value str(result);
349 const char* cstr = ToCString(str);
350 printf("%s\n", cstr);
351 }
352 return true;
353 }
354 }
355}
356
357
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000358void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) {
359 v8::HandleScope handle_scope(isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000360 v8::String::Utf8Value exception(try_catch->Exception());
361 const char* exception_string = ToCString(exception);
362 v8::Handle<v8::Message> message = try_catch->Message();
363 if (message.IsEmpty()) {
364 // V8 didn't provide any extra information about this error; just
365 // print the exception.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000366 fprintf(stderr, "%s\n", exception_string);
Steve Blocka7e24c12009-10-30 11:49:00 +0000367 } else {
368 // Print (filename):(line number): (message).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000369 v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
Steve Blocka7e24c12009-10-30 11:49:00 +0000370 const char* filename_string = ToCString(filename);
371 int linenum = message->GetLineNumber();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000372 fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, exception_string);
Steve Blocka7e24c12009-10-30 11:49:00 +0000373 // Print line of source code.
374 v8::String::Utf8Value sourceline(message->GetSourceLine());
375 const char* sourceline_string = ToCString(sourceline);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000376 fprintf(stderr, "%s\n", sourceline_string);
Steve Blocka7e24c12009-10-30 11:49:00 +0000377 // Print wavy underline (GetUnderline is deprecated).
378 int start = message->GetStartColumn();
379 for (int i = 0; i < start; i++) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000380 fprintf(stderr, " ");
Steve Blocka7e24c12009-10-30 11:49:00 +0000381 }
382 int end = message->GetEndColumn();
383 for (int i = start; i < end; i++) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000384 fprintf(stderr, "^");
Steve Blocka7e24c12009-10-30 11:49:00 +0000385 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000386 fprintf(stderr, "\n");
Kristian Monsen25f61362010-05-21 11:50:48 +0100387 v8::String::Utf8Value stack_trace(try_catch->StackTrace());
388 if (stack_trace.length() > 0) {
389 const char* stack_trace_string = ToCString(stack_trace);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000390 fprintf(stderr, "%s\n", stack_trace_string);
Kristian Monsen25f61362010-05-21 11:50:48 +0100391 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000392 }
393}