Index: test/inspector/inspector-test.cc |
diff --git a/test/inspector/inspector-test.cc b/test/inspector/inspector-test.cc |
index b3dbcb4f52a9cd05733236a0f83dffa46a742f0f..2aeff592ca481da5495ca90cc2588557471a5536 100644 |
--- a/test/inspector/inspector-test.cc |
+++ b/test/inspector/inspector-test.cc |
@@ -53,6 +53,7 @@ class UtilsExtension : public v8::Extension { |
"native function print();" |
"native function quit();" |
"native function setlocale();" |
+ "native function read();" |
"native function load();" |
"native function compileAndRunWithOrigin();" |
"native function setCurrentTimeMSForTest();" |
@@ -79,6 +80,12 @@ class UtilsExtension : public v8::Extension { |
.FromJust()) { |
return v8::FunctionTemplate::New(isolate, UtilsExtension::SetLocale); |
} else if (name->Equals(context, |
+ v8::String::NewFromUtf8(isolate, "read", |
+ v8::NewStringType::kNormal) |
+ .ToLocalChecked()) |
+ .FromJust()) { |
+ return v8::FunctionTemplate::New(isolate, UtilsExtension::Read); |
+ } else if (name->Equals(context, |
v8::String::NewFromUtf8(isolate, "load", |
v8::NewStringType::kNormal) |
.ToLocalChecked()) |
@@ -173,27 +180,49 @@ class UtilsExtension : public v8::Extension { |
setlocale(LC_NUMERIC, *str); |
} |
- static void Load(const v8::FunctionCallbackInfo<v8::Value>& args) { |
- if (args.Length() != 1 || !args[0]->IsString()) { |
- fprintf(stderr, "Internal error: load gets one string argument."); |
- Exit(); |
- } |
- v8::String::Utf8Value str(args[0]); |
- v8::Isolate* isolate = args.GetIsolate(); |
+ static bool ReadFile(v8::Isolate* isolate, v8::Local<v8::Value> name, |
+ v8::internal::Vector<const char>* chars) { |
+ v8::String::Utf8Value str(name); |
bool exists = false; |
std::string filename(*str, str.length()); |
- v8::internal::Vector<const char> chars = |
- v8::internal::ReadFile(filename.c_str(), &exists); |
+ *chars = v8::internal::ReadFile(filename.c_str(), &exists); |
if (!exists) { |
isolate->ThrowException( |
- v8::String::NewFromUtf8(isolate, "Error loading file", |
+ v8::String::NewFromUtf8(isolate, "Error reading file", |
v8::NewStringType::kNormal) |
.ToLocalChecked()); |
- return; |
+ return false; |
+ } |
+ return true; |
+ } |
+ |
+ static void Read(const v8::FunctionCallbackInfo<v8::Value>& args) { |
+ if (args.Length() != 1 || !args[0]->IsString()) { |
+ fprintf(stderr, "Internal error: read gets one string argument."); |
+ Exit(); |
+ } |
+ v8::internal::Vector<const char> chars; |
+ v8::Isolate* isolate = args.GetIsolate(); |
+ if (ReadFile(isolate, args[0], &chars)) { |
+ args.GetReturnValue().Set( |
+ v8::String::NewFromUtf8(isolate, chars.start(), |
+ v8::NewStringType::kNormal, chars.length()) |
+ .ToLocalChecked()); |
+ } |
+ } |
+ |
+ static void Load(const v8::FunctionCallbackInfo<v8::Value>& args) { |
+ if (args.Length() != 1 || !args[0]->IsString()) { |
+ fprintf(stderr, "Internal error: load gets one string argument."); |
+ Exit(); |
+ } |
+ v8::internal::Vector<const char> chars; |
+ v8::Isolate* isolate = args.GetIsolate(); |
+ if (ReadFile(isolate, args[0], &chars)) { |
+ ExecuteStringTask task(chars); |
+ v8::Global<v8::Context> context(isolate, isolate->GetCurrentContext()); |
+ task.Run(isolate, context); |
} |
- ExecuteStringTask task(chars); |
- v8::Global<v8::Context> context(isolate, isolate->GetCurrentContext()); |
- task.Run(isolate, context); |
} |
static void CompileAndRunWithOrigin( |