diff options
Diffstat (limited to 'deps/v8/test/inspector/inspector-test.cc')
-rw-r--r-- | deps/v8/test/inspector/inspector-test.cc | 83 |
1 files changed, 30 insertions, 53 deletions
diff --git a/deps/v8/test/inspector/inspector-test.cc b/deps/v8/test/inspector/inspector-test.cc index 4f5a31d290..4321edccac 100644 --- a/deps/v8/test/inspector/inspector-test.cc +++ b/deps/v8/test/inspector/inspector-test.cc @@ -14,9 +14,9 @@ #include "include/v8.h" #include "src/base/platform/platform.h" -#include "src/flags.h" -#include "src/utils.h" -#include "src/vector.h" +#include "src/flags/flags.h" +#include "src/utils/utils.h" +#include "src/utils/vector.h" #include "test/inspector/isolate-data.h" #include "test/inspector/task-runner.h" @@ -27,6 +27,12 @@ namespace internal { extern void DisableEmbeddedBlobRefcounting(); extern void FreeCurrentEmbeddedBlob(); +extern v8::StartupData CreateSnapshotDataBlobInternal( + v8::SnapshotCreator::FunctionCodeHandling function_code_handling, + const char* embedded_source, v8::Isolate* isolate); +extern v8::StartupData WarmUpSnapshotDataBlobInternal( + v8::StartupData cold_snapshot_blob, const char* warmup_source); + } // namespace internal } // namespace v8 @@ -56,12 +62,26 @@ std::vector<uint16_t> ToVector(v8::Isolate* isolate, return buffer; } +std::vector<uint8_t> ToBytes(v8::Isolate* isolate, v8::Local<v8::String> str) { + std::vector<uint8_t> buffer(str->Length()); + str->WriteOneByte(isolate, buffer.data(), 0, str->Length()); + return buffer; +} + v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const char* str) { return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kNormal) .ToLocalChecked(); } v8::Local<v8::String> ToV8String(v8::Isolate* isolate, + const std::vector<uint8_t>& bytes) { + return v8::String::NewFromOneByte(isolate, bytes.data(), + v8::NewStringType::kNormal, + static_cast<int>(bytes.size())) + .ToLocalChecked(); +} + +v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const std::string& buffer) { int length = static_cast<int>(buffer.size()); return v8::String::NewFromUtf8(isolate, buffer.data(), @@ -262,7 +282,7 @@ class ExecuteStringTask : public TaskRunner::Task { int length = static_cast<int>(name_.size()); v8::internal::Vector<uint16_t> buffer = v8::internal::Vector<uint16_t>::New(length); - std::copy(name_.begin(), name_.end(), buffer.start()); + std::copy(name_.begin(), name_.end(), buffer.begin()); data->RegisterModule(context, buffer, &scriptSource); } } @@ -564,8 +584,8 @@ class UtilsExtension : public IsolateData::SetupGlobalTask { IsolateData::FromContext(context)->GetContextGroupId(context), args.GetIsolate(), args[2].As<v8::Function>()); - std::vector<uint16_t> state = - ToVector(args.GetIsolate(), args[1].As<v8::String>()); + std::vector<uint8_t> state = + ToBytes(args.GetIsolate(), args[1].As<v8::String>()); int context_group_id = args[0].As<v8::Int32>()->Value(); int session_id = 0; RunSyncTask(backend_runner_, [&context_group_id, &session_id, &channel, @@ -587,9 +607,9 @@ class UtilsExtension : public IsolateData::SetupGlobalTask { Exit(); } int session_id = args[0].As<v8::Int32>()->Value(); - std::vector<uint16_t> state; + std::vector<uint8_t> state; RunSyncTask(backend_runner_, [&session_id, &state](IsolateData* data) { - state = ToVector(data->DisconnectSession(session_id)->string()); + state = data->DisconnectSession(session_id); }); channels_.erase(session_id); args.GetReturnValue().Set(ToV8String(args.GetIsolate(), state)); @@ -1030,50 +1050,6 @@ class InspectorExtension : public IsolateData::SetupGlobalTask { } }; -bool RunExtraCode(v8::Isolate* isolate, v8::Local<v8::Context> context, - const char* utf8_source, const char* name) { - v8::Context::Scope context_scope(context); - v8::TryCatch try_catch(isolate); - v8::Local<v8::String> source_string; - if (!v8::String::NewFromUtf8(isolate, utf8_source, v8::NewStringType::kNormal) - .ToLocal(&source_string)) { - return false; - } - v8::Local<v8::String> resource_name = - v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kNormal) - .ToLocalChecked(); - v8::ScriptOrigin origin(resource_name); - v8::ScriptCompiler::Source source(source_string, origin); - v8::Local<v8::Script> script; - if (!v8::ScriptCompiler::Compile(context, &source).ToLocal(&script)) - return false; - if (script->Run(context).IsEmpty()) return false; - CHECK(!try_catch.HasCaught()); - return true; -} - -v8::StartupData CreateSnapshotDataBlob(const char* embedded_source = nullptr) { - // Create a new isolate and a new context from scratch, optionally run - // a script to embed, and serialize to create a snapshot blob. - v8::StartupData result = {nullptr, 0}; - { - v8::SnapshotCreator snapshot_creator; - v8::Isolate* isolate = snapshot_creator.GetIsolate(); - { - v8::HandleScope scope(isolate); - v8::Local<v8::Context> context = v8::Context::New(isolate); - if (embedded_source != nullptr && - !RunExtraCode(isolate, context, embedded_source, "<embedded>")) { - return result; - } - snapshot_creator.SetDefaultContext(context); - } - result = snapshot_creator.CreateBlob( - v8::SnapshotCreator::FunctionCodeHandling::kClear); - } - return result; -} - } // namespace int main(int argc, char* argv[]) { @@ -1092,7 +1068,8 @@ int main(int argc, char* argv[]) { if (strcmp(argv[i], "--embed") == 0) { argv[i++] = nullptr; printf("Embedding script '%s'\n", argv[i]); - startup_data = CreateSnapshotDataBlob(argv[i]); + startup_data = i::CreateSnapshotDataBlobInternal( + v8::SnapshotCreator::FunctionCodeHandling::kClear, argv[i], nullptr); argv[i] = nullptr; } } |