tasks.cc 1.82 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2020 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/tasks.h"

#include <vector>

9 10
#include "include/v8-isolate.h"
#include "include/v8-script.h"
11 12 13 14 15 16
#include "test/inspector/isolate-data.h"
#include "test/inspector/utils.h"

namespace v8 {
namespace internal {

17
void ExecuteStringTask::Run(InspectorIsolateData* data) {
18 19 20 21 22
  v8::MicrotasksScope microtasks_scope(data->isolate(),
                                       v8::MicrotasksScope::kRunMicrotasks);
  v8::HandleScope handle_scope(data->isolate());
  v8::Local<v8::Context> context = data->GetDefaultContext(context_group_id_);
  v8::Context::Scope context_scope(context);
23 24
  v8::ScriptOrigin origin(data->isolate(), ToV8String(data->isolate(), name_),
                          line_offset_, column_offset_,
25 26 27 28 29
                          /* resource_is_shared_cross_origin */ false,
                          /* script_id */ -1,
                          /* source_map_url */ v8::Local<v8::Value>(),
                          /* resource_is_opaque */ false,
                          /* is_wasm */ false, is_module_);
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  v8::Local<v8::String> source;
  if (expression_.size() != 0)
    source = ToV8String(data->isolate(), expression_);
  else
    source = ToV8String(data->isolate(), expression_utf8_);

  v8::ScriptCompiler::Source scriptSource(source, origin);
  v8::Isolate::SafeForTerminationScope allowTermination(data->isolate());
  if (!is_module_) {
    v8::Local<v8::Script> script;
    if (!v8::ScriptCompiler::Compile(context, &scriptSource).ToLocal(&script))
      return;
    v8::MaybeLocal<v8::Value> result;
    result = script->Run(context);
  } else {
45
    data->RegisterModule(context, name_, &scriptSource);
46 47 48 49 50
  }
}

}  // namespace internal
}  // namespace v8