Index: src/d8.cc |
diff --git a/src/d8.cc b/src/d8.cc |
index c3b0bfcb430868547aa9593ab63036fed5c0d95c..0d1b93699bc9ef3342df90d84616f1dec7746124 100644 |
--- a/src/d8.cc |
+++ b/src/d8.cc |
@@ -924,8 +924,13 @@ Handle<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) { |
FunctionTemplate::New(isolate, ReadLine)); |
global_template->Set(String::NewFromUtf8(isolate, "load"), |
FunctionTemplate::New(isolate, Load)); |
- global_template->Set(String::NewFromUtf8(isolate, "quit"), |
- FunctionTemplate::New(isolate, Quit)); |
+ // Some Emscripten-generated code tries to call 'quit', which in turn would |
+ // call C's exit(). This would lead to memory leaks, because there is no way |
+ // we can terminate cleanly then, so we need a way to hide 'quit'. |
+ if (!options.omit_quit) { |
+ global_template->Set(String::NewFromUtf8(isolate, "quit"), |
+ FunctionTemplate::New(isolate, Quit)); |
+ } |
global_template->Set(String::NewFromUtf8(isolate, "version"), |
FunctionTemplate::New(isolate, Version)); |
@@ -1374,6 +1379,9 @@ bool Shell::SetOptions(int argc, char* argv[]) { |
// TODO(jochen) See issue 3351 |
options.send_idle_notification = true; |
argv[i] = NULL; |
+ } else if (strcmp(argv[i], "--omit-quit") == 0) { |
+ options.omit_quit = true; |
+ argv[i] = NULL; |
} else if (strcmp(argv[i], "-f") == 0) { |
// Ignore any -f flags for compatibility with other stand-alone |
// JavaScript engines. |