Skip to content

Commit

Permalink
deps: V8: cherry-pick d82c9af
Browse files Browse the repository at this point in the history
Original commit message:

    [api] Add unique_ptr constructor for StreamedSource

    Since StreamedSource takes ownership of the ExternalSourceStream
    passed into it, it should take it by unique_ptr rather than raw
    pointer to signal this transfer of ownership. The old constructor
    is now deprecated.

    Change-Id: I24681926c2f3141f7dd3664f72019a4c6deabfd7
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1520713
    Commit-Queue: Yang Guo <yangguo@chromium.org>
    Reviewed-by: Yang Guo <yangguo@chromium.org>
    Auto-Submit: Leszek Swirski <leszeks@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60232}

Refs: v8/v8@d82c9af

PR-URL: #26685
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
addaleax authored and refack committed Mar 28, 2019
1 parent 1f03fb4 commit 8181811
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.8',
'v8_embedder_string': '-node.9',

##### V8 defaults for Node.js #####

Expand Down
7 changes: 6 additions & 1 deletion deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExternalSourceStream> source_stream,
Encoding encoding);
~StreamedSource();

internal::ScriptStreamingData* impl() const { return impl_.get(); }
Expand Down
6 changes: 5 additions & 1 deletion deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,11 @@ void ScriptCompiler::ExternalSourceStream::ResetToBookmark() { UNREACHABLE(); }

ScriptCompiler::StreamedSource::StreamedSource(ExternalSourceStream* stream,
Encoding encoding)
: impl_(new i::ScriptStreamingData(stream, encoding)) {}
: StreamedSource(std::unique_ptr<ExternalSourceStream>(stream), encoding) {}

ScriptCompiler::StreamedSource::StreamedSource(
std::unique_ptr<ExternalSourceStream> stream, Encoding encoding)
: impl_(new i::ScriptStreamingData(std::move(stream), encoding)) {}

ScriptCompiler::StreamedSource::~StreamedSource() = default;

Expand Down
4 changes: 2 additions & 2 deletions deps/v8/src/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2173,9 +2173,9 @@ void Compiler::PostInstantiation(Handle<JSFunction> function,
// Implementation of ScriptStreamingData

ScriptStreamingData::ScriptStreamingData(
ScriptCompiler::ExternalSourceStream* source_stream,
std::unique_ptr<ScriptCompiler::ExternalSourceStream> source_stream,
ScriptCompiler::StreamedSource::Encoding encoding)
: source_stream(source_stream), encoding(encoding) {}
: source_stream(std::move(source_stream)), encoding(encoding) {}

ScriptStreamingData::~ScriptStreamingData() = default;

Expand Down
5 changes: 3 additions & 2 deletions deps/v8/src/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScriptCompiler::ExternalSourceStream> source_stream,
ScriptCompiler::StreamedSource::Encoding encoding);
~ScriptStreamingData();

void Release();
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/d8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class BackgroundCompileThread : public base::Thread {
BackgroundCompileThread(Isolate* isolate, Local<String> source)
: base::Thread(GetThreadOptions("BackgroundCompileThread")),
source_(source),
streamed_source_(new DummySourceStream(source, isolate),
streamed_source_(base::make_unique<DummySourceStream>(source, isolate),
v8::ScriptCompiler::StreamedSource::UTF8),
task_(v8::ScriptCompiler::StartStreamingScript(isolate,
&streamed_source_)) {}
Expand Down
8 changes: 4 additions & 4 deletions deps/v8/test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24799,8 +24799,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<TestSourceStream>(chunks), encoding);
v8::ScriptCompiler::ScriptStreamingTask* task =
v8::ScriptCompiler::StartStreamingScript(isolate, &source);

Expand Down Expand Up @@ -25071,7 +25071,7 @@ TEST(StreamingWithDebuggingEnabledLate) {
v8::TryCatch try_catch(isolate);

v8::ScriptCompiler::StreamedSource source(
new TestSourceStream(chunks),
v8::base::make_unique<TestSourceStream>(chunks),
v8::ScriptCompiler::StreamedSource::ONE_BYTE);
v8::ScriptCompiler::ScriptStreamingTask* task =
v8::ScriptCompiler::StartStreamingScript(isolate, &source);
Expand Down Expand Up @@ -25179,7 +25179,7 @@ TEST(StreamingWithHarmonyScopes) {

v8::TryCatch try_catch(isolate);
v8::ScriptCompiler::StreamedSource source(
new TestSourceStream(chunks),
v8::base::make_unique<TestSourceStream>(chunks),
v8::ScriptCompiler::StreamedSource::ONE_BYTE);
v8::ScriptCompiler::ScriptStreamingTask* task =
v8::ScriptCompiler::StartStreamingScript(isolate, &source);
Expand Down

0 comments on commit 8181811

Please sign in to comment.