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