| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if !defined(_WIN32) && !defined(_WIN64) | 5 #if !defined(_WIN32) && !defined(_WIN64) |
| 6 #include <unistd.h> // NOLINT | 6 #include <unistd.h> // NOLINT |
| 7 #endif // !defined(_WIN32) && !defined(_WIN64) | 7 #endif // !defined(_WIN32) && !defined(_WIN64) |
| 8 | 8 |
| 9 #include <locale.h> | |
| 10 | |
| 11 #include "include/libplatform/libplatform.h" | 9 #include "include/libplatform/libplatform.h" |
| 12 #include "include/v8.h" | 10 #include "include/v8.h" |
| 13 | 11 |
| 14 #include "src/base/platform/platform.h" | 12 #include "src/base/platform/platform.h" |
| 15 #include "src/flags.h" | 13 #include "src/flags.h" |
| 16 #include "src/utils.h" | 14 #include "src/utils.h" |
| 17 #include "src/vector.h" | 15 #include "src/vector.h" |
| 18 | 16 |
| 19 #include "test/inspector/inspector-impl.h" | 17 #include "test/inspector/inspector-impl.h" |
| 20 #include "test/inspector/task-runner.h" | 18 #include "test/inspector/task-runner.h" |
| 21 | 19 |
| 22 namespace { | 20 namespace { |
| 23 | 21 |
| 24 void Exit() { | 22 void Exit() { |
| 25 fflush(stdout); | 23 fflush(stdout); |
| 26 fflush(stderr); | 24 fflush(stderr); |
| 27 _exit(0); | 25 _exit(0); |
| 28 } | 26 } |
| 29 | 27 |
| 30 class UtilsExtension : public v8::Extension { | 28 class UtilsExtension : public v8::Extension { |
| 31 public: | 29 public: |
| 32 UtilsExtension() | 30 UtilsExtension() |
| 33 : v8::Extension("v8_inspector/utils", | 31 : v8::Extension("v8_inspector/utils", |
| 34 "native function print();" | 32 "native function print(); native function quit();") {} |
| 35 "native function quit();" | |
| 36 "native function setlocale();") {} | |
| 37 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( | 33 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
| 38 v8::Isolate* isolate, v8::Local<v8::String> name) { | 34 v8::Isolate* isolate, v8::Local<v8::String> name) { |
| 39 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 35 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 40 if (name->Equals(context, v8::String::NewFromUtf8( | 36 if (name->Equals(context, v8::String::NewFromUtf8( |
| 41 isolate, "print", v8::NewStringType::kNormal) | 37 isolate, "print", v8::NewStringType::kNormal) |
| 42 .ToLocalChecked()) | 38 .ToLocalChecked()) |
| 43 .FromJust()) { | 39 .FromJust()) { |
| 44 return v8::FunctionTemplate::New(isolate, UtilsExtension::Print); | 40 return v8::FunctionTemplate::New(isolate, UtilsExtension::Print); |
| 45 } else if (name->Equals(context, | 41 } else if (name->Equals(context, |
| 46 v8::String::NewFromUtf8(isolate, "quit", | 42 v8::String::NewFromUtf8(isolate, "quit", |
| 47 v8::NewStringType::kNormal) | 43 v8::NewStringType::kNormal) |
| 48 .ToLocalChecked()) | 44 .ToLocalChecked()) |
| 49 .FromJust()) { | 45 .FromJust()) { |
| 50 return v8::FunctionTemplate::New(isolate, UtilsExtension::Quit); | 46 return v8::FunctionTemplate::New(isolate, UtilsExtension::Quit); |
| 51 } else if (name->Equals(context, | |
| 52 v8::String::NewFromUtf8(isolate, "setlocale", | |
| 53 v8::NewStringType::kNormal) | |
| 54 .ToLocalChecked()) | |
| 55 .FromJust()) { | |
| 56 return v8::FunctionTemplate::New(isolate, UtilsExtension::SetLocale); | |
| 57 } | 47 } |
| 58 return v8::Local<v8::FunctionTemplate>(); | 48 return v8::Local<v8::FunctionTemplate>(); |
| 59 } | 49 } |
| 60 | 50 |
| 61 private: | 51 private: |
| 62 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args) { | 52 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 63 for (int i = 0; i < args.Length(); i++) { | 53 for (int i = 0; i < args.Length(); i++) { |
| 64 v8::HandleScope handle_scope(args.GetIsolate()); | 54 v8::HandleScope handle_scope(args.GetIsolate()); |
| 65 if (i != 0) { | 55 if (i != 0) { |
| 66 printf(" "); | 56 printf(" "); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 86 if (n != str.length()) { | 76 if (n != str.length()) { |
| 87 printf("Error in fwrite\n"); | 77 printf("Error in fwrite\n"); |
| 88 Quit(args); | 78 Quit(args); |
| 89 } | 79 } |
| 90 } | 80 } |
| 91 printf("\n"); | 81 printf("\n"); |
| 92 fflush(stdout); | 82 fflush(stdout); |
| 93 } | 83 } |
| 94 | 84 |
| 95 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) { Exit(); } | 85 static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) { Exit(); } |
| 96 | |
| 97 static void SetLocale(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 98 if (args.Length() != 1 || !args[0]->IsString()) { | |
| 99 fprintf(stderr, "Internal error: setlocale get one string argument."); | |
| 100 Exit(); | |
| 101 } | |
| 102 v8::String::Utf8Value str(args[0]); | |
| 103 setlocale(LC_NUMERIC, *str); | |
| 104 } | |
| 105 }; | 86 }; |
| 106 | 87 |
| 107 class SetTimeoutTask : public TaskRunner::Task { | 88 class SetTimeoutTask : public TaskRunner::Task { |
| 108 public: | 89 public: |
| 109 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function) | 90 SetTimeoutTask(v8::Isolate* isolate, v8::Local<v8::Function> function) |
| 110 : function_(isolate, function) {} | 91 : function_(isolate, function) {} |
| 111 virtual ~SetTimeoutTask() {} | 92 virtual ~SetTimeoutTask() {} |
| 112 | 93 |
| 113 bool is_inspector_task() final { return false; } | 94 bool is_inspector_task() final { return false; } |
| 114 | 95 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 fprintf(stderr, "Internal error: script file doesn't exists: %s\n", | 243 fprintf(stderr, "Internal error: script file doesn't exists: %s\n", |
| 263 argv[i]); | 244 argv[i]); |
| 264 Exit(); | 245 Exit(); |
| 265 } | 246 } |
| 266 frontend_runner.Append(new ExecuteStringTask(chars)); | 247 frontend_runner.Append(new ExecuteStringTask(chars)); |
| 267 } | 248 } |
| 268 | 249 |
| 269 frontend_runner.Join(); | 250 frontend_runner.Join(); |
| 270 return 0; | 251 return 0; |
| 271 } | 252 } |
| OLD | NEW |