diff --git a/include/v8.h b/include/v8.h index ac0091a65b..377fb7b57e 100644 --- a/include/v8.h +++ b/include/v8.h @@ -1535,7 +1535,12 @@ class V8_EXPORT ScriptCompiler { public: enum Encoding { ONE_BYTE, TWO_BYTE, UTF8 }; - StreamedSource(ExternalSourceStream* source_stream, Encoding encoding); + V8_DEPRECATE_SOON( + "This class takes ownership of source_stream, so use the constructor " + "taking a unique_ptr to make these semantics clearer", + StreamedSource(ExternalSourceStream* source_stream, Encoding encoding)); + StreamedSource(std::unique_ptr source_stream, + Encoding encoding); ~StreamedSource(); internal::ScriptStreamingData* impl() const { return impl_.get(); } diff --git a/src/api.cc b/src/api.cc index 1aee916c0a..a6cab34cab 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2072,7 +2072,11 @@ void ScriptCompiler::ExternalSourceStream::ResetToBookmark() { UNREACHABLE(); } ScriptCompiler::StreamedSource::StreamedSource(ExternalSourceStream* stream, Encoding encoding) - : impl_(new i::ScriptStreamingData(stream, encoding)) {} + : StreamedSource(std::unique_ptr(stream), encoding) {} + +ScriptCompiler::StreamedSource::StreamedSource( + std::unique_ptr stream, Encoding encoding) + : impl_(new i::ScriptStreamingData(std::move(stream), encoding)) {} ScriptCompiler::StreamedSource::~StreamedSource() = default; diff --git a/src/compiler.cc b/src/compiler.cc index e02b032e9a..d309237876 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -2169,9 +2169,9 @@ void Compiler::PostInstantiation(Handle function, // Implementation of ScriptStreamingData ScriptStreamingData::ScriptStreamingData( - ScriptCompiler::ExternalSourceStream* source_stream, + std::unique_ptr source_stream, ScriptCompiler::StreamedSource::Encoding encoding) - : source_stream(source_stream), encoding(encoding) {} + : source_stream(std::move(source_stream)), encoding(encoding) {} ScriptStreamingData::~ScriptStreamingData() = default; diff --git a/src/compiler.h b/src/compiler.h index 4233aa80e2..f234482d0c 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -376,8 +376,9 @@ class V8_EXPORT_PRIVATE BackgroundCompileTask { // Contains all data which needs to be transmitted between threads for // background parsing and compiling and finalizing it on the main thread. struct ScriptStreamingData { - ScriptStreamingData(ScriptCompiler::ExternalSourceStream* source_stream, - ScriptCompiler::StreamedSource::Encoding encoding); + ScriptStreamingData( + std::unique_ptr source_stream, + ScriptCompiler::StreamedSource::Encoding encoding); ~ScriptStreamingData(); void Release(); diff --git a/src/d8.cc b/src/d8.cc index 742cb762ca..f3293640e1 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -413,7 +413,7 @@ class BackgroundCompileThread : public base::Thread { BackgroundCompileThread(Isolate* isolate, Local source) : base::Thread(GetThreadOptions("BackgroundCompileThread")), source_(source), - streamed_source_(new DummySourceStream(source, isolate), + streamed_source_(base::make_unique(source, isolate), v8::ScriptCompiler::StreamedSource::UTF8), task_(v8::ScriptCompiler::StartStreamingScript(isolate, &streamed_source_)) {} diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 78be21ee6b..c2d796bb77 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -24899,8 +24899,8 @@ void RunStreamingTest(const char** chunks, v8::HandleScope scope(isolate); v8::TryCatch try_catch(isolate); - v8::ScriptCompiler::StreamedSource source(new TestSourceStream(chunks), - encoding); + v8::ScriptCompiler::StreamedSource source( + v8::base::make_unique(chunks), encoding); v8::ScriptCompiler::ScriptStreamingTask* task = v8::ScriptCompiler::StartStreamingScript(isolate, &source); @@ -25171,7 +25171,7 @@ TEST(StreamingWithDebuggingEnabledLate) { v8::TryCatch try_catch(isolate); v8::ScriptCompiler::StreamedSource source( - new TestSourceStream(chunks), + v8::base::make_unique(chunks), v8::ScriptCompiler::StreamedSource::ONE_BYTE); v8::ScriptCompiler::ScriptStreamingTask* task = v8::ScriptCompiler::StartStreamingScript(isolate, &source); @@ -25279,7 +25279,7 @@ TEST(StreamingWithHarmonyScopes) { v8::TryCatch try_catch(isolate); v8::ScriptCompiler::StreamedSource source( - new TestSourceStream(chunks), + v8::base::make_unique(chunks), v8::ScriptCompiler::StreamedSource::ONE_BYTE); v8::ScriptCompiler::ScriptStreamingTask* task = v8::ScriptCompiler::StartStreamingScript(isolate, &source);