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

Unified Diff: test/inspector-protocol/load-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/load-extension.cc
diff --git a/test/inspector-protocol/load-extension.cc b/test/inspector-protocol/load-extension.cc
new file mode 100644
index 0000000000000000000000000000000000000000..79b2ca546ba56a778cb9fe25df55dfe566065a6a
--- /dev/null
+++ b/test/inspector-protocol/load-extension.cc
@@ -0,0 +1,57 @@
+// 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/load-extension.h"
+
+#include "src/utils.h"
+#include "src/vector.h"
+
+namespace v8_inspector {
+
+namespace {
+
+v8::Local<v8::String> ReadFile(v8::Isolate* isolate, const char* name) {
+ bool exists = false;
+ v8::internal::Vector<const char> chars =
+ v8::internal::ReadFile(name, &exists, true);
+ if (!exists) return v8::Local<v8::String>();
+ v8::Local<v8::String> result =
+ v8::String::NewFromUtf8(isolate, chars.start(),
+ v8::NewStringType::kNormal, chars.length())
+ .ToLocalChecked();
+ return result;
+}
+
+} // namespace
+
+v8::Local<v8::FunctionTemplate> LoadExtension::GetNativeFunctionTemplate(
+ v8::Isolate* isolate, v8::Local<v8::String> str) {
+ return v8::FunctionTemplate::New(isolate, LoadExtension::Load);
+}
+
+void LoadExtension::Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ for (int i = 0; i < args.Length(); i++) {
+ v8::String::Utf8Value file(args[i]);
+ if (*file == NULL) {
+ fprintf(stderr, "Error loading file");
+ return;
+ }
+ v8::Isolate* isolate = args.GetIsolate();
+ v8::Local<v8::String> source = ReadFile(isolate, *file);
+ if (source.IsEmpty()) {
+ fprintf(stderr, "Error loading file");
+ return;
+ }
+ v8::ScriptOrigin origin(v8::String::Empty(isolate));
+ v8::ScriptCompiler::Source scriptSource(source, origin);
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+ v8::Local<v8::Script> script;
+ if (!v8::ScriptCompiler::Compile(context, &scriptSource).ToLocal(&script))
+ return;
+ v8::MaybeLocal<v8::Value> result;
+ result = script->Run(context);
+ }
+}
+
+} // namespace v8_inspector

Powered by Google App Engine
This is Rietveld 408576698