Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Unified Diff: test/inspector-protocol/utils-extension.cc

Issue 2358943002: [inspector] added inspector protocol test runner (Closed)
Patch Set: a Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/inspector-protocol/utils-extension.cc
diff --git a/test/inspector-protocol/utils-extension.cc b/test/inspector-protocol/utils-extension.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d82994964f21524726fbaacd72c1427ed1c7f5f8
--- /dev/null
+++ b/test/inspector-protocol/utils-extension.cc
@@ -0,0 +1,67 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "test/inspector-protocol/utils-extension.h"
+
+#include "v8-platform.h"
+
+namespace v8_inspector {
+
+v8::Local<v8::FunctionTemplate> UtilsExtension::GetNativeFunctionTemplate(
+ v8::Isolate* isolate, v8::Local<v8::String> name) {
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+ if (name->Equals(context, v8::String::NewFromUtf8(isolate, "print",
+ v8::NewStringType::kNormal)
+ .ToLocalChecked())
+ .FromJust()) {
+ return v8::FunctionTemplate::New(isolate, UtilsExtension::Print);
+ } else if (name->Equals(context,
+ v8::String::NewFromUtf8(isolate, "quit",
+ v8::NewStringType::kNormal)
+ .ToLocalChecked())
+ .FromJust()) {
+ return v8::FunctionTemplate::New(isolate, UtilsExtension::Quit);
+ }
+ return v8::Local<v8::FunctionTemplate>();
+}
+
+void UtilsExtension::Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ for (int i = 0; i < args.Length(); i++) {
+ v8::HandleScope handle_scope(args.GetIsolate());
+ if (i != 0) {
+ printf(" ");
+ }
+
+ // Explicitly catch potential exceptions in toString().
+ v8::TryCatch try_catch(args.GetIsolate());
+ v8::Local<v8::Value> arg = args[i];
+ v8::Local<v8::String> str_obj;
+
+ if (arg->IsSymbol()) {
+ arg = v8::Local<v8::Symbol>::Cast(arg)->Name();
+ }
+ if (!arg->ToString(args.GetIsolate()->GetCurrentContext())
+ .ToLocal(&str_obj)) {
+ try_catch.ReThrow();
+ return;
+ }
+
+ v8::String::Utf8Value str(str_obj);
+ int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout));
+ if (n != str.length()) {
+ printf("Error in fwrite\n");
+ Quit(args);
+ }
+ }
+ printf("\n");
+ fflush(stdout);
+}
+
+void UtilsExtension::Quit(const v8::FunctionCallbackInfo<v8::Value>&) {
+ fflush(stdout);
+ fflush(stderr);
+ _exit(0);
+}
+
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698