| 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> | 9 #include <locale.h> |
| 10 | 10 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 if (args[0]->IsFunction()) { | 205 if (args[0]->IsFunction()) { |
| 206 TaskRunner::FromContext(context)->Append(new SetTimeoutTask( | 206 TaskRunner::FromContext(context)->Append(new SetTimeoutTask( |
| 207 args.GetIsolate(), v8::Local<v8::Function>::Cast(args[0]))); | 207 args.GetIsolate(), v8::Local<v8::Function>::Cast(args[0]))); |
| 208 } else { | 208 } else { |
| 209 TaskRunner::FromContext(context)->Append( | 209 TaskRunner::FromContext(context)->Append( |
| 210 new ExecuteStringTask(ToVector(args[0].As<v8::String>()))); | 210 new ExecuteStringTask(ToVector(args[0].As<v8::String>()))); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 class InspectorExtension : public v8::Extension { |
| 216 public: |
| 217 InspectorExtension() |
| 218 : v8::Extension("v8_inspector/inspector", |
| 219 "native function attachInspector();" |
| 220 "native function detachInspector();") {} |
| 221 |
| 222 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
| 223 v8::Isolate* isolate, v8::Local<v8::String> name) { |
| 224 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 225 if (name->Equals(context, |
| 226 v8::String::NewFromUtf8(isolate, "attachInspector", |
| 227 v8::NewStringType::kNormal) |
| 228 .ToLocalChecked()) |
| 229 .FromJust()) { |
| 230 return v8::FunctionTemplate::New(isolate, InspectorExtension::Attach); |
| 231 } else if (name->Equals(context, |
| 232 v8::String::NewFromUtf8(isolate, "detachInspector", |
| 233 v8::NewStringType::kNormal) |
| 234 .ToLocalChecked()) |
| 235 .FromJust()) { |
| 236 return v8::FunctionTemplate::New(isolate, InspectorExtension::Detach); |
| 237 } |
| 238 return v8::Local<v8::FunctionTemplate>(); |
| 239 } |
| 240 |
| 241 private: |
| 242 static void Attach(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 243 v8::Isolate* isolate = args.GetIsolate(); |
| 244 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 245 v8_inspector::V8Inspector* inspector = |
| 246 InspectorClientImpl::InspectorFromContext(context); |
| 247 if (!inspector) { |
| 248 fprintf(stderr, "Inspector client not found - cannot attach!"); |
| 249 Exit(); |
| 250 } |
| 251 inspector->contextCreated( |
| 252 v8_inspector::V8ContextInfo(context, 1, v8_inspector::StringView())); |
| 253 } |
| 254 |
| 255 static void Detach(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 256 v8::Isolate* isolate = args.GetIsolate(); |
| 257 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 258 v8_inspector::V8Inspector* inspector = |
| 259 InspectorClientImpl::InspectorFromContext(context); |
| 260 if (!inspector) { |
| 261 fprintf(stderr, "Inspector client not found - cannot detach!"); |
| 262 Exit(); |
| 263 } |
| 264 inspector->contextDestroyed(context); |
| 265 } |
| 266 }; |
| 267 |
| 215 v8::Local<v8::String> ToString(v8::Isolate* isolate, | 268 v8::Local<v8::String> ToString(v8::Isolate* isolate, |
| 216 const v8_inspector::StringView& string) { | 269 const v8_inspector::StringView& string) { |
| 217 if (string.is8Bit()) | 270 if (string.is8Bit()) |
| 218 return v8::String::NewFromOneByte(isolate, string.characters8(), | 271 return v8::String::NewFromOneByte(isolate, string.characters8(), |
| 219 v8::NewStringType::kNormal, | 272 v8::NewStringType::kNormal, |
| 220 static_cast<int>(string.length())) | 273 static_cast<int>(string.length())) |
| 221 .ToLocalChecked(); | 274 .ToLocalChecked(); |
| 222 else | 275 else |
| 223 return v8::String::NewFromTwoByte(isolate, string.characters16(), | 276 return v8::String::NewFromTwoByte(isolate, string.characters16(), |
| 224 v8::NewStringType::kNormal, | 277 v8::NewStringType::kNormal, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 int main(int argc, char* argv[]) { | 313 int main(int argc, char* argv[]) { |
| 261 v8::V8::InitializeICUDefaultLocation(argv[0]); | 314 v8::V8::InitializeICUDefaultLocation(argv[0]); |
| 262 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); | 315 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); |
| 263 v8::V8::InitializePlatform(platform); | 316 v8::V8::InitializePlatform(platform); |
| 264 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 317 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 265 v8::V8::InitializeExternalStartupData(argv[0]); | 318 v8::V8::InitializeExternalStartupData(argv[0]); |
| 266 v8::V8::Initialize(); | 319 v8::V8::Initialize(); |
| 267 | 320 |
| 268 SetTimeoutExtension set_timeout_extension; | 321 SetTimeoutExtension set_timeout_extension; |
| 269 v8::RegisterExtension(&set_timeout_extension); | 322 v8::RegisterExtension(&set_timeout_extension); |
| 323 InspectorExtension inspector_extension; |
| 324 v8::RegisterExtension(&inspector_extension); |
| 270 UtilsExtension utils_extension; | 325 UtilsExtension utils_extension; |
| 271 v8::RegisterExtension(&utils_extension); | 326 v8::RegisterExtension(&utils_extension); |
| 272 SendMessageToBackendExtension send_message_to_backend_extension; | 327 SendMessageToBackendExtension send_message_to_backend_extension; |
| 273 v8::RegisterExtension(&send_message_to_backend_extension); | 328 v8::RegisterExtension(&send_message_to_backend_extension); |
| 274 | 329 |
| 275 v8::base::Semaphore ready_semaphore(0); | 330 v8::base::Semaphore ready_semaphore(0); |
| 276 | 331 |
| 277 const char* backend_extensions[] = {"v8_inspector/setTimeout"}; | 332 const char* backend_extensions[] = {"v8_inspector/setTimeout", |
| 333 "v8_inspector/inspector"}; |
| 278 v8::ExtensionConfiguration backend_configuration( | 334 v8::ExtensionConfiguration backend_configuration( |
| 279 arraysize(backend_extensions), backend_extensions); | 335 arraysize(backend_extensions), backend_extensions); |
| 280 TaskRunner backend_runner(&backend_configuration, false, &ready_semaphore); | 336 TaskRunner backend_runner(&backend_configuration, false, &ready_semaphore); |
| 281 ready_semaphore.Wait(); | 337 ready_semaphore.Wait(); |
| 282 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner); | 338 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner); |
| 283 | 339 |
| 284 const char* frontend_extensions[] = {"v8_inspector/utils", | 340 const char* frontend_extensions[] = {"v8_inspector/utils", |
| 285 "v8_inspector/frontend"}; | 341 "v8_inspector/frontend"}; |
| 286 v8::ExtensionConfiguration frontend_configuration( | 342 v8::ExtensionConfiguration frontend_configuration( |
| 287 arraysize(frontend_extensions), frontend_extensions); | 343 arraysize(frontend_extensions), frontend_extensions); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 307 argv[i]); | 363 argv[i]); |
| 308 Exit(); | 364 Exit(); |
| 309 } | 365 } |
| 310 frontend_runner.Append(new ExecuteStringTask(chars)); | 366 frontend_runner.Append(new ExecuteStringTask(chars)); |
| 311 } | 367 } |
| 312 | 368 |
| 313 frontend_runner.Join(); | 369 frontend_runner.Join(); |
| 314 backend_runner.Join(); | 370 backend_runner.Join(); |
| 315 return 0; | 371 return 0; |
| 316 } | 372 } |
| OLD | NEW |