Chromium Code Reviews| 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->GetEnteredContext(); | |
|
kozy
2016/10/21 15:06:53
GetCurrentContext()
robwu
2016/10/21 20:32:45
Done.
| |
| 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 fprintf(stdout, "Attaching context.\n"); | |
| 252 inspector->contextDestroyed(context); | |
|
kozy
2016/10/21 15:06:53
Do you really need this call? Otherwise it looks l
robwu
2016/10/21 20:32:45
Oops. Removed.
| |
| 253 inspector->contextCreated( | |
| 254 v8_inspector::V8ContextInfo(context, 1, v8_inspector::StringView())); | |
| 255 } | |
| 256 | |
| 257 static void Detach(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 258 v8::Isolate* isolate = args.GetIsolate(); | |
| 259 v8::Local<v8::Context> context = isolate->GetEnteredContext(); | |
| 260 v8_inspector::V8Inspector* inspector = | |
| 261 InspectorClientImpl::InspectorFromContext(context); | |
| 262 if (!inspector) { | |
| 263 fprintf(stderr, "Inspector client not found - cannot detach!"); | |
| 264 Exit(); | |
| 265 } | |
| 266 fprintf(stdout, "Detaching context.\n"); | |
| 267 inspector->contextDestroyed(context); | |
| 268 } | |
| 269 }; | |
| 270 | |
| 215 v8::Local<v8::String> ToString(v8::Isolate* isolate, | 271 v8::Local<v8::String> ToString(v8::Isolate* isolate, |
| 216 const v8_inspector::StringView& string) { | 272 const v8_inspector::StringView& string) { |
| 217 if (string.is8Bit()) | 273 if (string.is8Bit()) |
| 218 return v8::String::NewFromOneByte(isolate, string.characters8(), | 274 return v8::String::NewFromOneByte(isolate, string.characters8(), |
| 219 v8::NewStringType::kNormal, | 275 v8::NewStringType::kNormal, |
| 220 static_cast<int>(string.length())) | 276 static_cast<int>(string.length())) |
| 221 .ToLocalChecked(); | 277 .ToLocalChecked(); |
| 222 else | 278 else |
| 223 return v8::String::NewFromTwoByte(isolate, string.characters16(), | 279 return v8::String::NewFromTwoByte(isolate, string.characters16(), |
| 224 v8::NewStringType::kNormal, | 280 v8::NewStringType::kNormal, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 int main(int argc, char* argv[]) { | 316 int main(int argc, char* argv[]) { |
| 261 v8::V8::InitializeICUDefaultLocation(argv[0]); | 317 v8::V8::InitializeICUDefaultLocation(argv[0]); |
| 262 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); | 318 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); |
| 263 v8::V8::InitializePlatform(platform); | 319 v8::V8::InitializePlatform(platform); |
| 264 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 320 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 265 v8::V8::InitializeExternalStartupData(argv[0]); | 321 v8::V8::InitializeExternalStartupData(argv[0]); |
| 266 v8::V8::Initialize(); | 322 v8::V8::Initialize(); |
| 267 | 323 |
| 268 SetTimeoutExtension set_timeout_extension; | 324 SetTimeoutExtension set_timeout_extension; |
| 269 v8::RegisterExtension(&set_timeout_extension); | 325 v8::RegisterExtension(&set_timeout_extension); |
| 326 InspectorExtension inspector_extension; | |
| 327 v8::RegisterExtension(&inspector_extension); | |
| 270 UtilsExtension utils_extension; | 328 UtilsExtension utils_extension; |
| 271 v8::RegisterExtension(&utils_extension); | 329 v8::RegisterExtension(&utils_extension); |
| 272 SendMessageToBackendExtension send_message_to_backend_extension; | 330 SendMessageToBackendExtension send_message_to_backend_extension; |
| 273 v8::RegisterExtension(&send_message_to_backend_extension); | 331 v8::RegisterExtension(&send_message_to_backend_extension); |
| 274 | 332 |
| 275 v8::base::Semaphore ready_semaphore(0); | 333 v8::base::Semaphore ready_semaphore(0); |
| 276 | 334 |
| 277 const char* backend_extensions[] = {"v8_inspector/setTimeout"}; | 335 const char* backend_extensions[] = {"v8_inspector/setTimeout", |
| 336 "v8_inspector/inspector"}; | |
| 278 v8::ExtensionConfiguration backend_configuration( | 337 v8::ExtensionConfiguration backend_configuration( |
| 279 arraysize(backend_extensions), backend_extensions); | 338 arraysize(backend_extensions), backend_extensions); |
| 280 TaskRunner backend_runner(&backend_configuration, false, &ready_semaphore); | 339 TaskRunner backend_runner(&backend_configuration, false, &ready_semaphore); |
| 281 ready_semaphore.Wait(); | 340 ready_semaphore.Wait(); |
| 282 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner); | 341 SendMessageToBackendExtension::set_backend_task_runner(&backend_runner); |
| 283 | 342 |
| 284 const char* frontend_extensions[] = {"v8_inspector/utils", | 343 const char* frontend_extensions[] = {"v8_inspector/utils", |
| 285 "v8_inspector/frontend"}; | 344 "v8_inspector/frontend"}; |
| 286 v8::ExtensionConfiguration frontend_configuration( | 345 v8::ExtensionConfiguration frontend_configuration( |
| 287 arraysize(frontend_extensions), frontend_extensions); | 346 arraysize(frontend_extensions), frontend_extensions); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 307 argv[i]); | 366 argv[i]); |
| 308 Exit(); | 367 Exit(); |
| 309 } | 368 } |
| 310 frontend_runner.Append(new ExecuteStringTask(chars)); | 369 frontend_runner.Append(new ExecuteStringTask(chars)); |
| 311 } | 370 } |
| 312 | 371 |
| 313 frontend_runner.Join(); | 372 frontend_runner.Join(); |
| 314 backend_runner.Join(); | 373 backend_runner.Join(); |
| 315 return 0; | 374 return 0; |
| 316 } | 375 } |
| OLD | NEW |