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 "include/libplatform/libplatform.h" | 9 #include "include/libplatform/libplatform.h" |
10 #include "include/v8.h" | 10 #include "include/v8.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 "native function setTimeout();") {} | 121 "native function setTimeout();") {} |
122 | 122 |
123 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( | 123 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
124 v8::Isolate* isolate, v8::Local<v8::String> name) { | 124 v8::Isolate* isolate, v8::Local<v8::String> name) { |
125 return v8::FunctionTemplate::New(isolate, SetTimeoutExtension::SetTimeout); | 125 return v8::FunctionTemplate::New(isolate, SetTimeoutExtension::SetTimeout); |
126 } | 126 } |
127 | 127 |
128 private: | 128 private: |
129 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) { | 129 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args) { |
130 v8::Isolate* isolate = args.GetIsolate(); | 130 v8::Isolate* isolate = args.GetIsolate(); |
131 if (args.Length() != 2 || !args[1]->IsNumber() || !args[0]->IsFunction() || | 131 if (args.Length() != 2 || !args[1]->IsNumber() || |
| 132 (!args[0]->IsFunction() && !args[0]->IsString()) || |
132 args[1].As<v8::Number>()->Value() != 0.0) { | 133 args[1].As<v8::Number>()->Value() != 0.0) { |
133 fprintf(stderr, | 134 fprintf(stderr, |
134 "Internal error: only setTimeout(function, 0) is supported."); | 135 "Internal error: only setTimeout(function, 0) is supported."); |
135 Exit(); | 136 Exit(); |
136 } | 137 } |
137 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); | 138 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); |
138 TaskRunner::FromContext(context)->Append(new SetTimeoutTask( | 139 if (args[0]->IsFunction()) { |
139 args.GetIsolate(), v8::Local<v8::Function>::Cast(args[0]))); | 140 TaskRunner::FromContext(context)->Append(new SetTimeoutTask( |
| 141 args.GetIsolate(), v8::Local<v8::Function>::Cast(args[0]))); |
| 142 } else { |
| 143 v8::Local<v8::String> data = args[0].As<v8::String>(); |
| 144 std::unique_ptr<uint16_t[]> buffer(new uint16_t[data->Length()]); |
| 145 data->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, data->Length()); |
| 146 v8_inspector::String16 source = |
| 147 v8_inspector::String16(buffer.get(), data->Length()); |
| 148 TaskRunner::FromContext(context)->Append(new ExecuteStringTask(source)); |
| 149 } |
140 } | 150 } |
141 }; | 151 }; |
142 | 152 |
143 v8_inspector::String16 ToString16(const v8_inspector::StringView& string) { | 153 v8_inspector::String16 ToString16(const v8_inspector::StringView& string) { |
144 if (string.is8Bit()) | 154 if (string.is8Bit()) |
145 return v8_inspector::String16( | 155 return v8_inspector::String16( |
146 reinterpret_cast<const char*>(string.characters8()), string.length()); | 156 reinterpret_cast<const char*>(string.characters8()), string.length()); |
147 return v8_inspector::String16( | 157 return v8_inspector::String16( |
148 reinterpret_cast<const uint16_t*>(string.characters16()), | 158 reinterpret_cast<const uint16_t*>(string.characters16()), |
149 string.length()); | 159 string.length()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 UtilsExtension utils_extension; | 192 UtilsExtension utils_extension; |
183 v8::RegisterExtension(&utils_extension); | 193 v8::RegisterExtension(&utils_extension); |
184 SendMessageToBackendExtension send_message_to_backend_extension; | 194 SendMessageToBackendExtension send_message_to_backend_extension; |
185 v8::RegisterExtension(&send_message_to_backend_extension); | 195 v8::RegisterExtension(&send_message_to_backend_extension); |
186 | 196 |
187 v8::base::Semaphore ready_semaphore(0); | 197 v8::base::Semaphore ready_semaphore(0); |
188 | 198 |
189 const char* backend_extensions[] = {"v8_inspector/setTimeout"}; | 199 const char* backend_extensions[] = {"v8_inspector/setTimeout"}; |
190 v8::ExtensionConfiguration backend_configuration( | 200 v8::ExtensionConfiguration backend_configuration( |
191 arraysize(backend_extensions), backend_extensions); | 201 arraysize(backend_extensions), backend_extensions); |
192 TaskRunner backend_runner(&backend_configuration, &ready_semaphore); | 202 TaskRunner backend_runner(&backend_configuration, false, &ready_semaphore); |
193 ready_semaphore.Wait(); | 203 ready_semaphore.Wait(); |
194 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner); | 204 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner); |
195 | 205 |
196 const char* frontend_extensions[] = {"v8_inspector/utils", | 206 const char* frontend_extensions[] = {"v8_inspector/utils", |
197 "v8_inspector/frontend"}; | 207 "v8_inspector/frontend"}; |
198 v8::ExtensionConfiguration frontend_configuration( | 208 v8::ExtensionConfiguration frontend_configuration( |
199 arraysize(frontend_extensions), frontend_extensions); | 209 arraysize(frontend_extensions), frontend_extensions); |
200 TaskRunner frontend_runner(&frontend_configuration, &ready_semaphore); | 210 TaskRunner frontend_runner(&frontend_configuration, true, &ready_semaphore); |
201 ready_semaphore.Wait(); | 211 ready_semaphore.Wait(); |
202 | 212 |
203 FrontendChannelImpl frontend_channel(&frontend_runner); | 213 FrontendChannelImpl frontend_channel(&frontend_runner); |
204 InspectorClientImpl inspector_client(&backend_runner, &frontend_channel, | 214 InspectorClientImpl inspector_client(&backend_runner, &frontend_channel, |
205 &ready_semaphore); | 215 &ready_semaphore); |
206 ready_semaphore.Wait(); | 216 ready_semaphore.Wait(); |
207 | 217 |
208 for (int i = 1; i < argc; ++i) { | 218 for (int i = 1; i < argc; ++i) { |
209 if (argv[i][0] == '-') break; | 219 if (argv[i][0] == '-') break; |
210 | 220 |
211 bool exists = false; | 221 bool exists = false; |
212 v8::internal::Vector<const char> chars = | 222 v8::internal::Vector<const char> chars = |
213 v8::internal::ReadFile(argv[i], &exists, true); | 223 v8::internal::ReadFile(argv[i], &exists, true); |
214 if (!exists) { | 224 if (!exists) { |
215 fprintf(stderr, "Internal error: script file doesn't exists: %s\n", | 225 fprintf(stderr, "Internal error: script file doesn't exists: %s\n", |
216 argv[i]); | 226 argv[i]); |
217 Exit(); | 227 Exit(); |
218 } | 228 } |
219 v8_inspector::String16 source = | 229 v8_inspector::String16 source = |
220 v8_inspector::String16::fromUTF8(chars.start(), chars.length()); | 230 v8_inspector::String16::fromUTF8(chars.start(), chars.length()); |
221 frontend_runner.Append(new ExecuteStringTask(source)); | 231 frontend_runner.Append(new ExecuteStringTask(source)); |
222 } | 232 } |
223 | 233 |
224 frontend_runner.Join(); | 234 frontend_runner.Join(); |
225 return 0; | 235 return 0; |
226 } | 236 } |
OLD | NEW |