Commit ed64b982 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[api] Clean up ScriptCompiler::StartStreaming* methods

Bug: chromium:1061857
Change-Id: I81ec92979b2e64f77385df79c084b98485c266ff
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2563265Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71525}
parent 17ed49b5
......@@ -1772,6 +1772,7 @@ class V8_EXPORT Script {
Local<UnboundScript> GetUnboundScript();
};
enum class ScriptType { kClassic, kModule };
/**
* For compiling scripts.
......@@ -2028,11 +2029,9 @@ class V8_EXPORT ScriptCompiler {
static ScriptStreamingTask* StartStreamingScript(
Isolate* isolate, StreamedSource* source,
CompileOptions options = kNoCompileOptions);
static ScriptStreamingTask* StartStreaming(Isolate* isolate,
StreamedSource* source);
// The same as ScriptCompiler::StartStreaming but for module scripts.
static ScriptStreamingTask* StartStreamingModule(Isolate* isolate,
StreamedSource* source);
static ScriptStreamingTask* StartStreaming(
Isolate* isolate, StreamedSource* source,
ScriptType type = ScriptType::kClassic);
/**
* Compiles a streamed script (bound to current context).
......
......@@ -2714,26 +2714,13 @@ ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript(
}
ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreaming(
Isolate* v8_isolate, StreamedSource* source) {
Isolate* v8_isolate, StreamedSource* source, v8::ScriptType type) {
if (!i::FLAG_script_streaming) return nullptr;
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
ASSERT_NO_SCRIPT_NO_EXCEPTION(isolate);
i::ScriptStreamingData* data = source->impl();
std::unique_ptr<i::BackgroundCompileTask> task =
std::make_unique<i::BackgroundCompileTask>(data, isolate,
i::ScriptType::kClassic);
data->task = std::move(task);
return new ScriptCompiler::ScriptStreamingTask(data);
}
ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingModule(
Isolate* v8_isolate, StreamedSource* source) {
if (!i::FLAG_script_streaming) return nullptr;
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
i::ScriptStreamingData* data = source->impl();
std::unique_ptr<i::BackgroundCompileTask> task =
std::make_unique<i::BackgroundCompileTask>(data, isolate,
i::ScriptType::kModule);
std::make_unique<i::BackgroundCompileTask>(data, isolate, type);
data->task = std::move(task);
return new ScriptCompiler::ScriptStreamingTask(data);
}
......
......@@ -460,7 +460,7 @@ class V8_EXPORT_PRIVATE BackgroundCompileTask {
// Compiler::GetSharedFunctionInfoForStreamedScript.
// Note: does not take ownership of |data|.
BackgroundCompileTask(ScriptStreamingData* data, Isolate* isolate,
ScriptType type);
v8::ScriptType type);
~BackgroundCompileTask();
// Creates a new task that when run will parse and compile the
......
......@@ -434,8 +434,6 @@ inline LanguageMode stricter_language_mode(LanguageMode mode1,
static_cast<int>(mode2));
}
enum class ScriptType { kClassic, kModule };
// A non-keyed store is of the form a.x = foo or a["x"] = foo whereas
// a keyed store is of the form a[expression] = foo.
enum class StoreOrigin { kMaybeKeyed, kNamed };
......
......@@ -541,13 +541,10 @@ class StreamingCompileTask final : public v8::Task {
public:
StreamingCompileTask(Isolate* isolate,
v8::ScriptCompiler::StreamedSource* streamed_source,
i::ScriptType type)
v8::ScriptType type)
: isolate_(isolate),
script_streaming_task_(
type == i::ScriptType::kClassic
? v8::ScriptCompiler::StartStreaming(isolate, streamed_source)
: v8::ScriptCompiler::StartStreamingModule(isolate,
streamed_source)) {
script_streaming_task_(v8::ScriptCompiler::StartStreaming(
isolate, streamed_source, type)) {
Shell::NotifyStartStreamingTask(isolate_);
}
......@@ -625,8 +622,8 @@ MaybeLocal<T> Shell::CompileString(Isolate* isolate, Local<Context> context,
v8::ScriptCompiler::StreamedSource::UTF8);
PostBlockingBackgroundTask(std::make_unique<StreamingCompileTask>(
isolate, &streamed_source,
std::is_same<T, Module>::value ? i::ScriptType::kModule
: i::ScriptType::kClassic));
std::is_same<T, Module>::value ? v8::ScriptType::kModule
: v8::ScriptType::kClassic));
// Pump the loop until the streaming task completes.
Shell::CompleteMessageLoop(isolate);
return CompileStreamed<T>(context, &streamed_source, source, origin);
......
......@@ -23533,7 +23533,7 @@ v8::MaybeLocal<Module> UnexpectedModuleResolveCallback(
}
// Helper function for running streaming tests.
void RunStreamingTest(const char** chunks, i::ScriptType type,
void RunStreamingTest(const char** chunks, v8::ScriptType type,
v8::ScriptCompiler::StreamedSource::Encoding encoding =
v8::ScriptCompiler::StreamedSource::ONE_BYTE,
bool expected_success = true,
......@@ -23547,9 +23547,7 @@ void RunStreamingTest(const char** chunks, i::ScriptType type,
v8::ScriptCompiler::StreamedSource source(
std::make_unique<TestSourceStream>(chunks), encoding);
v8::ScriptCompiler::ScriptStreamingTask* task =
type == i::ScriptType::kClassic
? v8::ScriptCompiler::StartStreaming(isolate, &source)
: v8::ScriptCompiler::StartStreamingModule(isolate, &source);
v8::ScriptCompiler::StartStreaming(isolate, &source, type);
// TestSourceStream::GetMoreData won't block, so it's OK to just run the
// task here in the main thread.
......@@ -23561,10 +23559,10 @@ void RunStreamingTest(const char** chunks, i::ScriptType type,
v8::ScriptOrigin origin(v8_str("http://foo.com"), 0, 0, false, -1,
v8::Local<v8::Value>(), false, false,
type == i::ScriptType::kModule);
type == v8::ScriptType::kModule);
char* full_source = TestSourceStream::FullSourceString(chunks);
if (type == i::ScriptType::kClassic) {
if (type == v8::ScriptType::kClassic) {
v8::MaybeLocal<Script> script = v8::ScriptCompiler::Compile(
env.local(), &source, v8_str(full_source), origin);
if (expected_success) {
......@@ -23612,9 +23610,9 @@ void RunStreamingTest(const char** chunks,
bool expected_success = true,
const char* expected_source_url = nullptr,
const char* expected_source_mapping_url = nullptr) {
RunStreamingTest(chunks, i::ScriptType::kClassic, encoding, expected_success,
RunStreamingTest(chunks, v8::ScriptType::kClassic, encoding, expected_success,
expected_source_url, expected_source_mapping_url);
RunStreamingTest(chunks, i::ScriptType::kModule, encoding, expected_success,
RunStreamingTest(chunks, v8::ScriptType::kModule, encoding, expected_success,
expected_source_url, expected_source_mapping_url);
}
......@@ -23651,7 +23649,7 @@ TEST(StreamingScriptEvalShadowing) {
"})()\n";
const char* chunks[] = {chunk1, nullptr};
// Only run the script version of this test.
RunStreamingTest(chunks, i::ScriptType::kClassic);
RunStreamingTest(chunks, v8::ScriptType::kClassic);
}
TEST(StreamingBiggerScript) {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment