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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "test/inspector-protocol/load-extension.h"
6
7 #include "src/utils.h"
8 #include "src/vector.h"
9
10 namespace v8_inspector {
11
12 namespace {
13
14 v8::Local<v8::String> ReadFile(v8::Isolate* isolate, const char* name) {
15 bool exists = false;
16 v8::internal::Vector<const char> chars =
17 v8::internal::ReadFile(name, &exists, true);
18 if (!exists) return v8::Local<v8::String>();
19 v8::Local<v8::String> result =
20 v8::String::NewFromUtf8(isolate, chars.start(),
21 v8::NewStringType::kNormal, chars.length())
22 .ToLocalChecked();
23 return result;
24 }
25
26 } // namespace
27
28 v8::Local<v8::FunctionTemplate> LoadExtension::GetNativeFunctionTemplate(
29 v8::Isolate* isolate, v8::Local<v8::String> str) {
30 return v8::FunctionTemplate::New(isolate, LoadExtension::Load);
31 }
32
33 void LoadExtension::Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
34 for (int i = 0; i < args.Length(); i++) {
35 v8::String::Utf8Value file(args[i]);
36 if (*file == NULL) {
37 fprintf(stderr, "Error loading file");
38 return;
39 }
40 v8::Isolate* isolate = args.GetIsolate();
41 v8::Local<v8::String> source = ReadFile(isolate, *file);
42 if (source.IsEmpty()) {
43 fprintf(stderr, "Error loading file");
44 return;
45 }
46 v8::ScriptOrigin origin(v8::String::Empty(isolate));
47 v8::ScriptCompiler::Source scriptSource(source, origin);
48 v8::Local<v8::Context> context = isolate->GetCurrentContext();
49 v8::Local<v8::Script> script;
50 if (!v8::ScriptCompiler::Compile(context, &scriptSource).ToLocal(&script))
51 return;
52 v8::MaybeLocal<v8::Value> result;
53 result = script->Run(context);
54 }
55 }
56
57 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698