Commit 40935da5 authored by Adam Rice's avatar Adam Rice Committed by Commit Bot

Remove UnderlyingSinkBase lock notifications

In order to prevent a fetch's body from being garbage collected while it
was being read, BodyStreamBuffer's HasPendingActivity() method was made
to return true when the ReadableStream was locked. With unified GC, this
is no longer necessary, and is a source of bugs.

Remove the functionality from UnderlyingSourceBase to track when the
ReadableStream wrapping it is locked.

Also clear the |controller_| member in
ReadableStreamDefaultControllerNative::Close() and Error(). This is no
longer functionally important but can aid earlier garbage collection.

BUG=902633

Change-Id: If6150e26697f68f984fd05484169709bc165663e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1662255Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670026}
parent 4459bffd
...@@ -295,9 +295,7 @@ void BodyStreamBuffer::OnStateChange() { ...@@ -295,9 +295,7 @@ void BodyStreamBuffer::OnStateChange() {
} }
bool BodyStreamBuffer::HasPendingActivity() const { bool BodyStreamBuffer::HasPendingActivity() const {
if (loader_) return loader_;
return true;
return UnderlyingSourceBase::HasPendingActivity();
} }
void BodyStreamBuffer::ContextDestroyed(ExecutionContext* destroyed_context) { void BodyStreamBuffer::ContextDestroyed(ExecutionContext* destroyed_context) {
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
const internalReadableStreamSymbol = v8.createPrivateSymbol( const internalReadableStreamSymbol = v8.createPrivateSymbol(
'internal ReadableStream in exposed ReadableStream interface'); 'internal ReadableStream in exposed ReadableStream interface');
// Remove this once C++ code has been updated to use CreateReadableStream. // Remove this once C++ code has been updated to use CreateReadableStream.
const _lockNotifyTarget = v8.createPrivateSymbol('[[lockNotifyTarget]]');
const _strategySizeAlgorithm = v8.createPrivateSymbol( const _strategySizeAlgorithm = v8.createPrivateSymbol(
'[[strategySizeAlgorithm]]'); '[[strategySizeAlgorithm]]');
const _pullAlgorithm = v8.createPrivateSymbol('[[pullAlgorithm]]'); const _pullAlgorithm = v8.createPrivateSymbol('[[pullAlgorithm]]');
...@@ -47,9 +46,6 @@ ...@@ -47,9 +46,6 @@
const CLOSE_REQUESTED = 0b10; const CLOSE_REQUESTED = 0b10;
const PULLING = 0b100; const PULLING = 0b100;
const PULL_AGAIN = 0b1000; const PULL_AGAIN = 0b1000;
// TODO(ricea): Remove this once blink::UnderlyingSourceBase no longer needs
// it.
const BLINK_LOCK_NOTIFICATIONS = 0b10000;
const ObjectCreate = global.Object.create; const ObjectCreate = global.Object.create;
...@@ -127,10 +123,10 @@ ...@@ -127,10 +123,10 @@
// CreateReadableStream. // CreateReadableStream.
constructor(underlyingSource = {}, strategy = {}, constructor(underlyingSource = {}, strategy = {},
internalArgument = undefined) { internalArgument = undefined) {
const enableBlinkLockNotifications = const createdByUA =
internalArgument === createWithExternalControllerSentinel; internalArgument === createWithExternalControllerSentinel;
if (!useCounted && !enableBlinkLockNotifications) { if (!useCounted && !createdByUA) {
binding.countUse('ReadableStreamConstructor'); binding.countUse('ReadableStreamConstructor');
useCounted = true; useCounted = true;
} }
...@@ -157,8 +153,7 @@ ...@@ -157,8 +153,7 @@
highWaterMark = ValidateAndNormalizeHighWaterMark(highWaterMark); highWaterMark = ValidateAndNormalizeHighWaterMark(highWaterMark);
SetUpReadableStreamDefaultControllerFromUnderlyingSource( SetUpReadableStreamDefaultControllerFromUnderlyingSource(
this, underlyingSource, highWaterMark, sizeAlgorithm, this, underlyingSource, highWaterMark, sizeAlgorithm);
enableBlinkLockNotifications);
} }
} }
...@@ -381,11 +376,8 @@ ...@@ -381,11 +376,8 @@
return new ReadableStreamDefaultReader(stream); return new ReadableStreamDefaultReader(stream);
} }
// The non-standard boolean |enableBlinkLockNotifications| argument indicates
// whether the stream is being created from C++.
function CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, function CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm,
highWaterMark, sizeAlgorithm, highWaterMark, sizeAlgorithm) {
enableBlinkLockNotifications) {
if (highWaterMark === undefined) { if (highWaterMark === undefined) {
highWaterMark = 1; highWaterMark = 1;
} }
...@@ -399,7 +391,7 @@ ...@@ -399,7 +391,7 @@
const controller = ObjectCreate(ReadableStreamDefaultController_prototype); const controller = ObjectCreate(ReadableStreamDefaultController_prototype);
SetUpReadableStreamDefaultController( SetUpReadableStreamDefaultController(
stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm,
highWaterMark, sizeAlgorithm, enableBlinkLockNotifications); highWaterMark, sizeAlgorithm);
return stream; return stream;
} }
...@@ -490,11 +482,9 @@ ...@@ -490,11 +482,9 @@
const startAlgorithm = () => undefined; const startAlgorithm = () => undefined;
const branch1Stream = CreateReadableStream( const branch1Stream = CreateReadableStream(
startAlgorithm, pullAlgorithm, cancel1Algorithm, undefined, undefined, startAlgorithm, pullAlgorithm, cancel1Algorithm);
false);
const branch2Stream = CreateReadableStream( const branch2Stream = CreateReadableStream(
startAlgorithm, pullAlgorithm, cancel2Algorithm, undefined, undefined, startAlgorithm, pullAlgorithm, cancel2Algorithm);
false);
const branch1controller = branch1Stream[_controller]; const branch1controller = branch1Stream[_controller];
const branch2controller = branch2Stream[_controller]; const branch2controller = branch2Stream[_controller];
...@@ -695,17 +685,6 @@ ...@@ -695,17 +685,6 @@
} }
function ReadableStreamReaderGenericInitialize(reader, stream) { function ReadableStreamReaderGenericInitialize(reader, stream) {
// TODO(yhirano): Remove this when we don't need hasPendingActivity in
// blink::UnderlyingSourceBase.
const controller = stream[_controller];
if (controller[_readableStreamDefaultControllerBits] &
BLINK_LOCK_NOTIFICATIONS) {
// The stream is created with an external controller (i.e. made in
// Blink).
const lockNotifyTarget = controller[_lockNotifyTarget];
callFunction(lockNotifyTarget.notifyLockAcquired, lockNotifyTarget);
}
reader[_ownerReadableStream] = stream; reader[_ownerReadableStream] = stream;
stream[_reader] = reader; stream[_reader] = reader;
...@@ -724,17 +703,6 @@ ...@@ -724,17 +703,6 @@
} }
function ReadableStreamReaderGenericRelease(reader) { function ReadableStreamReaderGenericRelease(reader) {
// TODO(yhirano): Remove this when we don't need hasPendingActivity in
// blink::UnderlyingSourceBase.
const controller = reader[_ownerReadableStream][_controller];
if (controller[_readableStreamDefaultControllerBits] &
BLINK_LOCK_NOTIFICATIONS) {
// The stream is created with an external controller (i.e. made in
// Blink).
const lockNotifyTarget = controller[_lockNotifyTarget];
callFunction(lockNotifyTarget.notifyLockReleased, lockNotifyTarget);
}
if (ReadableStreamGetState(reader[_ownerReadableStream]) === if (ReadableStreamGetState(reader[_ownerReadableStream]) ===
STATE_READABLE) { STATE_READABLE) {
rejectPromise( rejectPromise(
...@@ -1000,12 +968,10 @@ ...@@ -1000,12 +968,10 @@
function SetUpReadableStreamDefaultController( function SetUpReadableStreamDefaultController(
stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm,
highWaterMark, sizeAlgorithm, enableBlinkLockNotifications) { highWaterMark, sizeAlgorithm) {
controller[_controlledReadableStream] = stream; controller[_controlledReadableStream] = stream;
controller[_queue] = new binding.SimpleQueue(); controller[_queue] = new binding.SimpleQueue();
controller[_queueTotalSize] = 0; controller[_queueTotalSize] = 0;
controller[_readableStreamDefaultControllerBits] =
enableBlinkLockNotifications ? BLINK_LOCK_NOTIFICATIONS : 0b0;
controller[_strategySizeAlgorithm] = sizeAlgorithm; controller[_strategySizeAlgorithm] = sizeAlgorithm;
controller[_strategyHWM] = highWaterMark; controller[_strategyHWM] = highWaterMark;
controller[_pullAlgorithm] = pullAlgorithm; controller[_pullAlgorithm] = pullAlgorithm;
...@@ -1019,8 +985,7 @@ ...@@ -1019,8 +985,7 @@
} }
function SetUpReadableStreamDefaultControllerFromUnderlyingSource( function SetUpReadableStreamDefaultControllerFromUnderlyingSource(
stream, underlyingSource, highWaterMark, sizeAlgorithm, stream, underlyingSource, highWaterMark, sizeAlgorithm) {
enableBlinkLockNotifications) {
const controller = ObjectCreate(ReadableStreamDefaultController_prototype); const controller = ObjectCreate(ReadableStreamDefaultController_prototype);
const startAlgorithm = const startAlgorithm =
() => CallOrNoop1(underlyingSource, 'start', controller, () => CallOrNoop1(underlyingSource, 'start', controller,
...@@ -1029,13 +994,9 @@ ...@@ -1029,13 +994,9 @@
underlyingSource, 'pull', 0, controller, 'underlyingSource.pull'); underlyingSource, 'pull', 0, controller, 'underlyingSource.pull');
const cancelAlgorithm = CreateAlgorithmFromUnderlyingMethod( const cancelAlgorithm = CreateAlgorithmFromUnderlyingMethod(
underlyingSource, 'cancel', 1, 'underlyingSource.cancel'); underlyingSource, 'cancel', 1, 'underlyingSource.cancel');
// TODO(ricea): Remove this once C++ API has been updated.
if (enableBlinkLockNotifications) {
controller[_lockNotifyTarget] = underlyingSource;
}
SetUpReadableStreamDefaultController( SetUpReadableStreamDefaultController(
stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm,
highWaterMark, sizeAlgorithm, enableBlinkLockNotifications); highWaterMark, sizeAlgorithm);
} }
// //
......
...@@ -193,7 +193,7 @@ ...@@ -193,7 +193,7 @@
}; };
stream[_readable] = binding.CreateReadableStream( stream[_readable] = binding.CreateReadableStream(
startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark, startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark,
readableSizeAlgorithm, false); readableSizeAlgorithm);
stream[_backpressure] = undefined; stream[_backpressure] = undefined;
stream[_backpressureChangePromise] = undefined; stream[_backpressureChangePromise] = undefined;
TransformStreamSetBackpressure(stream, true); TransformStreamSetBackpressure(stream, true);
......
...@@ -271,7 +271,6 @@ void ReadableStreamDefaultController::Trace(Visitor* visitor) { ...@@ -271,7 +271,6 @@ void ReadableStreamDefaultController::Trace(Visitor* visitor) {
visitor->Trace(pull_algorithm_); visitor->Trace(pull_algorithm_);
visitor->Trace(queue_); visitor->Trace(queue_);
visitor->Trace(strategy_size_algorithm_); visitor->Trace(strategy_size_algorithm_);
visitor->Trace(lock_notify_target_);
ScriptWrappable::Trace(visitor); ScriptWrappable::Trace(visitor);
} }
...@@ -494,7 +493,6 @@ void ReadableStreamDefaultController::SetUp( ...@@ -494,7 +493,6 @@ void ReadableStreamDefaultController::SetUp(
StreamAlgorithm* cancel_algorithm, StreamAlgorithm* cancel_algorithm,
double high_water_mark, double high_water_mark,
StrategySizeAlgorithm* size_algorithm, StrategySizeAlgorithm* size_algorithm,
bool enable_blink_lock_notifications,
ExceptionState& exception_state) { ExceptionState& exception_state) {
// https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller // https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller
// 1. Assert: stream.[[readableStreamController]] is undefined. // 1. Assert: stream.[[readableStreamController]] is undefined.
...@@ -510,10 +508,6 @@ void ReadableStreamDefaultController::SetUp( ...@@ -510,10 +508,6 @@ void ReadableStreamDefaultController::SetUp(
DCHECK(controller->queue_->IsEmpty()); DCHECK(controller->queue_->IsEmpty());
DCHECK_EQ(controller->queue_->TotalSize(), 0); DCHECK_EQ(controller->queue_->TotalSize(), 0);
// Not part of the standard.
controller->enable_blink_lock_notifications_ =
enable_blink_lock_notifications;
// 5. Set controller.[[strategySizeAlgorithm]] to sizeAlgorithm and // 5. Set controller.[[strategySizeAlgorithm]] to sizeAlgorithm and
// controller.[[strategyHWM]] to highWaterMark. // controller.[[strategyHWM]] to highWaterMark.
controller->strategy_size_algorithm_ = size_algorithm; controller->strategy_size_algorithm_ = size_algorithm;
...@@ -610,7 +604,6 @@ void ReadableStreamDefaultController::SetUpFromUnderlyingSource( ...@@ -610,7 +604,6 @@ void ReadableStreamDefaultController::SetUpFromUnderlyingSource(
v8::Local<v8::Object> underlying_source, v8::Local<v8::Object> underlying_source,
double high_water_mark, double high_water_mark,
StrategySizeAlgorithm* size_algorithm, StrategySizeAlgorithm* size_algorithm,
bool enable_blink_lock_notifications,
ExceptionState& exception_state) { ExceptionState& exception_state) {
// https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller-from-underlying-source // https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller-from-underlying-source
// 2. Let controller be ObjectCreate(the original value of // 2. Let controller be ObjectCreate(the original value of
...@@ -646,18 +639,11 @@ void ReadableStreamDefaultController::SetUpFromUnderlyingSource( ...@@ -646,18 +639,11 @@ void ReadableStreamDefaultController::SetUpFromUnderlyingSource(
return; return;
} }
// TODO(ricea): Remove this once C++ API has been updated.
if (enable_blink_lock_notifications) {
controller->lock_notify_target_.Set(script_state->GetIsolate(),
underlying_source);
}
// 6. Perform ? SetUpReadableStreamDefaultController(stream, controller, // 6. Perform ? SetUpReadableStreamDefaultController(stream, controller,
// startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, // startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark,
// sizeAlgorithm). // sizeAlgorithm).
SetUp(script_state, stream, controller, start_algorithm, pull_algorithm, SetUp(script_state, stream, controller, start_algorithm, pull_algorithm,
cancel_algorithm, high_water_mark, size_algorithm, cancel_algorithm, high_water_mark, size_algorithm, exception_state);
enable_blink_lock_notifications, exception_state);
} }
} // namespace blink } // namespace blink
...@@ -100,7 +100,6 @@ class ReadableStreamDefaultController : public ScriptWrappable { ...@@ -100,7 +100,6 @@ class ReadableStreamDefaultController : public ScriptWrappable {
StreamAlgorithm* cancel_algorithm, StreamAlgorithm* cancel_algorithm,
double high_water_mark, double high_water_mark,
StrategySizeAlgorithm* size_algorithm, StrategySizeAlgorithm* size_algorithm,
bool enable_blink_lock_notifications,
ExceptionState&); ExceptionState&);
// https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller-from-underlying-source // https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller-from-underlying-source
...@@ -109,7 +108,6 @@ class ReadableStreamDefaultController : public ScriptWrappable { ...@@ -109,7 +108,6 @@ class ReadableStreamDefaultController : public ScriptWrappable {
v8::Local<v8::Object> underlying_source, v8::Local<v8::Object> underlying_source,
double high_water_mark, double high_water_mark,
StrategySizeAlgorithm* size_algorithm, StrategySizeAlgorithm* size_algorithm,
bool enable_blink_lock_notifications,
ExceptionState&); ExceptionState&);
// Boolean flags are grouped together to reduce object size. Verbs have been // Boolean flags are grouped together to reduce object size. Verbs have been
...@@ -118,14 +116,12 @@ class ReadableStreamDefaultController : public ScriptWrappable { ...@@ -118,14 +116,12 @@ class ReadableStreamDefaultController : public ScriptWrappable {
bool will_pull_again_ = false; bool will_pull_again_ = false;
bool is_pulling_ = false; bool is_pulling_ = false;
bool is_started_ = false; bool is_started_ = false;
bool enable_blink_lock_notifications_ = false;
Member<StreamAlgorithm> cancel_algorithm_; Member<StreamAlgorithm> cancel_algorithm_;
Member<ReadableStreamNative> controlled_readable_stream_; Member<ReadableStreamNative> controlled_readable_stream_;
Member<StreamAlgorithm> pull_algorithm_; Member<StreamAlgorithm> pull_algorithm_;
Member<QueueWithSizes> queue_; Member<QueueWithSizes> queue_;
double strategy_high_water_mark_ = 0.0; double strategy_high_water_mark_ = 0.0;
Member<StrategySizeAlgorithm> strategy_size_algorithm_; Member<StrategySizeAlgorithm> strategy_size_algorithm_;
TraceWrapperV8Reference<v8::Object> lock_notify_target_;
}; };
} // namespace blink } // namespace blink
......
...@@ -31,8 +31,6 @@ class ReadableStreamDefaultControllerWrapper final ...@@ -31,8 +31,6 @@ class ReadableStreamDefaultControllerWrapper final
// (close/desiredSize/enqueue/error will become no-ops afterward.) // (close/desiredSize/enqueue/error will become no-ops afterward.)
void NoteHasBeenCanceled() override { js_controller_.Clear(); } void NoteHasBeenCanceled() override { js_controller_.Clear(); }
bool IsActive() const override { return !js_controller_.IsEmpty(); }
void Close() override { void Close() override {
ScriptState* script_state = script_state_; ScriptState* script_state = script_state_;
// This will assert that the context is valid; do not call this method when // This will assert that the context is valid; do not call this method when
...@@ -129,8 +127,6 @@ class ReadableStreamDefaultControllerNative final ...@@ -129,8 +127,6 @@ class ReadableStreamDefaultControllerNative final
void NoteHasBeenCanceled() override { controller_ = nullptr; } void NoteHasBeenCanceled() override { controller_ = nullptr; }
bool IsActive() const override { return controller_; }
void Close() override { void Close() override {
if (!controller_) if (!controller_)
return; return;
...@@ -138,6 +134,7 @@ class ReadableStreamDefaultControllerNative final ...@@ -138,6 +134,7 @@ class ReadableStreamDefaultControllerNative final
ScriptState::Scope scope(script_state_); ScriptState::Scope scope(script_state_);
ReadableStreamDefaultController::Close(script_state_, controller_); ReadableStreamDefaultController::Close(script_state_, controller_);
controller_ = nullptr;
} }
double DesiredSize() const override { double DesiredSize() const override {
...@@ -173,6 +170,7 @@ class ReadableStreamDefaultControllerNative final ...@@ -173,6 +170,7 @@ class ReadableStreamDefaultControllerNative final
ReadableStreamDefaultController::Error(script_state_, controller_, ReadableStreamDefaultController::Error(script_state_, controller_,
js_error); js_error);
controller_ = nullptr;
} }
void Trace(Visitor* visitor) override { void Trace(Visitor* visitor) override {
......
...@@ -33,7 +33,6 @@ class CORE_EXPORT ReadableStreamDefaultControllerInterface ...@@ -33,7 +33,6 @@ class CORE_EXPORT ReadableStreamDefaultControllerInterface
// (Close/DesiredSize/Enqueue/Error will become no-ops afterward.) // (Close/DesiredSize/Enqueue/Error will become no-ops afterward.)
virtual void NoteHasBeenCanceled() = 0; virtual void NoteHasBeenCanceled() = 0;
virtual bool IsActive() const = 0;
virtual void Close() = 0; virtual void Close() = 0;
virtual double DesiredSize() const = 0; virtual double DesiredSize() const = 0;
virtual void Enqueue(v8::Local<v8::Value> js_chunk) const = 0; virtual void Enqueue(v8::Local<v8::Value> js_chunk) const = 0;
......
...@@ -1047,8 +1047,7 @@ ReadableStreamNative* ReadableStreamNative::Create( ...@@ -1047,8 +1047,7 @@ ReadableStreamNative* ReadableStreamNative::Create(
// sizeAlgorithm). // sizeAlgorithm).
ReadableStreamDefaultController::SetUp( ReadableStreamDefaultController::SetUp(
script_state, stream, controller, start_algorithm, pull_algorithm, script_state, stream, controller, start_algorithm, pull_algorithm,
cancel_algorithm, high_water_mark, size_algorithm, false, cancel_algorithm, high_water_mark, size_algorithm, exception_state);
exception_state);
if (exception_state.HadException()) { if (exception_state.HadException()) {
return nullptr; return nullptr;
} }
...@@ -1059,14 +1058,12 @@ ReadableStreamNative* ReadableStreamNative::Create( ...@@ -1059,14 +1058,12 @@ ReadableStreamNative* ReadableStreamNative::Create(
ReadableStreamNative::ReadableStreamNative() = default; ReadableStreamNative::ReadableStreamNative() = default;
// TODO(ricea): Remove |enable_blink_lock_notifications| once
// blink::ReadableStreamOperations has been updated to use CreateReadableStream.
ReadableStreamNative::ReadableStreamNative(ScriptState* script_state, ReadableStreamNative::ReadableStreamNative(ScriptState* script_state,
ScriptValue raw_underlying_source, ScriptValue raw_underlying_source,
ScriptValue raw_strategy, ScriptValue raw_strategy,
bool enable_blink_lock_notifications, bool created_by_ua,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (!enable_blink_lock_notifications) { if (!created_by_ua) {
// TODO(ricea): Move this to IDL once blink::ReadableStreamOperations is // TODO(ricea): Move this to IDL once blink::ReadableStreamOperations is
// no longer using the public constructor. // no longer using the public constructor.
UseCounter::Count(ExecutionContext::From(script_state), UseCounter::Count(ExecutionContext::From(script_state),
...@@ -1151,7 +1148,7 @@ ReadableStreamNative::ReadableStreamNative(ScriptState* script_state, ...@@ -1151,7 +1148,7 @@ ReadableStreamNative::ReadableStreamNative(ScriptState* script_state,
// (this, underlyingSource, highWaterMark, sizeAlgorithm). // (this, underlyingSource, highWaterMark, sizeAlgorithm).
ReadableStreamDefaultController::SetUpFromUnderlyingSource( ReadableStreamDefaultController::SetUpFromUnderlyingSource(
script_state, this, underlying_source, high_water_mark, size_algorithm, script_state, this, underlying_source, high_water_mark, size_algorithm,
enable_blink_lock_notifications, exception_state); exception_state);
} }
ReadableStreamNative::~ReadableStreamNative() = default; ReadableStreamNative::~ReadableStreamNative() = default;
......
...@@ -67,14 +67,11 @@ class ReadableStreamNative : public ReadableStream { ...@@ -67,14 +67,11 @@ class ReadableStreamNative : public ReadableStream {
ReadableStreamNative(); ReadableStreamNative();
// TODO(ricea): Remove |enable_blink_lock_notifications| once
// blink::ReadableStreamOperations has been updated to use
// CreateReadableStream.
// https://streams.spec.whatwg.org/#rs-constructor // https://streams.spec.whatwg.org/#rs-constructor
ReadableStreamNative(ScriptState*, ReadableStreamNative(ScriptState*,
ScriptValue raw_underlying_source, ScriptValue raw_underlying_source,
ScriptValue raw_strategy, ScriptValue raw_strategy,
bool enable_blink_lock_notifications, bool created_by_ua,
ExceptionState&); ExceptionState&);
~ReadableStreamNative() override; ~ReadableStreamNative() override;
......
...@@ -368,46 +368,6 @@ TEST(ReadableStreamOperationsTest, ...@@ -368,46 +368,6 @@ TEST(ReadableStreamOperationsTest,
EXPECT_TRUE(it3->IsDone()); EXPECT_TRUE(it3->IsDone());
} }
TEST(ReadableStreamOperationsTest,
UnderlyingSourceShouldHavePendingActivityWhenLockedAndControllerIsActive) {
V8TestingScope scope;
TryCatchScope try_catch_scope(scope.GetIsolate());
auto* underlying_source =
MakeGarbageCollected<TestUnderlyingSource>(scope.GetScriptState());
ScriptValue strategy = ReadableStreamOperations::CreateCountQueuingStrategy(
scope.GetScriptState(), 10);
ASSERT_FALSE(strategy.IsEmpty());
ScriptValue internal_stream = ReadableStreamOperations::CreateReadableStream(
scope.GetScriptState(), underlying_source, strategy);
ASSERT_FALSE(internal_stream.IsEmpty());
CHECK(!RuntimeEnabledFeatures::StreamsNativeEnabled());
auto* stream = ReadableStreamWrapper::CreateFromInternalStream(
scope.GetScriptState(), internal_stream, ASSERT_NO_EXCEPTION);
ASSERT_TRUE(stream);
v8::Local<v8::Object> global = scope.GetScriptState()->GetContext()->Global();
ASSERT_TRUE(global
->Set(scope.GetContext(),
V8String(scope.GetIsolate(), "stream"),
ToV8(stream, scope.GetScriptState()))
.IsJust());
EXPECT_FALSE(underlying_source->HasPendingActivity());
EvalWithPrintingError(&scope, "let reader = stream.getReader();");
EXPECT_TRUE(underlying_source->HasPendingActivity());
EvalWithPrintingError(&scope, "reader.releaseLock();");
EXPECT_FALSE(underlying_source->HasPendingActivity());
EvalWithPrintingError(&scope, "reader = stream.getReader();");
EXPECT_TRUE(underlying_source->HasPendingActivity());
underlying_source->Enqueue(
ScriptValue(scope.GetScriptState(), v8::Undefined(scope.GetIsolate())));
underlying_source->Close();
EXPECT_FALSE(underlying_source->HasPendingActivity());
}
TEST(ReadableStreamOperationsTest, IsReadable) { TEST(ReadableStreamOperationsTest, IsReadable) {
V8TestingScope scope; V8TestingScope scope;
TryCatchScope try_catch_scope(scope.GetIsolate()); TryCatchScope try_catch_scope(scope.GetIsolate());
......
...@@ -170,16 +170,6 @@ void ReadableStreamReader::GenericRelease(ScriptState* script_state, ...@@ -170,16 +170,6 @@ void ReadableStreamReader::GenericRelease(ScriptState* script_state,
DCHECK_EQ(reader->owner_readable_stream_->reader_, reader); DCHECK_EQ(reader->owner_readable_stream_->reader_, reader);
auto* isolate = script_state->GetIsolate(); auto* isolate = script_state->GetIsolate();
// TODO(yhirano): Remove this when we don"t need hasPendingActivity in
// blink::UnderlyingSourceBase.
ReadableStreamDefaultController* controller =
reader->owner_readable_stream_->readable_stream_controller_;
if (controller->enable_blink_lock_notifications_) {
// The stream is created with an external controller (i.e. made in
// Blink).
auto lock_notify_target = controller->lock_notify_target_.NewLocal(isolate);
CallNullaryMethod(script_state, lock_notify_target, "notifyLockReleased");
}
// 3. If reader.[[ownerReadableStream]].[[state]] is "readable", reject // 3. If reader.[[ownerReadableStream]].[[state]] is "readable", reject
// reader.[[closedPromise]] with a TypeError exception. // reader.[[closedPromise]] with a TypeError exception.
...@@ -237,17 +227,6 @@ void ReadableStreamReader::GenericInitialize(ScriptState* script_state, ...@@ -237,17 +227,6 @@ void ReadableStreamReader::GenericInitialize(ScriptState* script_state,
ReadableStreamReader* reader, ReadableStreamReader* reader,
ReadableStreamNative* stream) { ReadableStreamNative* stream) {
auto* isolate = script_state->GetIsolate(); auto* isolate = script_state->GetIsolate();
// TODO(yhirano): Remove this when we don't need hasPendingActivity in
// blink::UnderlyingSourceBase.
ReadableStreamDefaultController* controller =
stream->readable_stream_controller_;
if (controller->enable_blink_lock_notifications_) {
// The stream is created with an external controller (i.e. made in
// Blink).
v8::Local<v8::Object> lock_notify_target =
controller->lock_notify_target_.NewLocal(isolate);
CallNullaryMethod(script_state, lock_notify_target, "notifyLockAcquired");
}
// https://streams.spec.whatwg.org/#readable-stream-reader-generic-initialize // https://streams.spec.whatwg.org/#readable-stream-reader-generic-initialize
// 1. Set reader.[[forAuthorCode]] to true. // 1. Set reader.[[forAuthorCode]] to true.
...@@ -290,32 +269,4 @@ void ReadableStreamReader::GenericInitialize(ScriptState* script_state, ...@@ -290,32 +269,4 @@ void ReadableStreamReader::GenericInitialize(ScriptState* script_state,
} }
} }
void ReadableStreamReader::CallNullaryMethod(ScriptState* script_state,
v8::Local<v8::Object> object,
const char* method_name) {
auto* isolate = script_state->GetIsolate();
auto context = script_state->GetContext();
v8::TryCatch try_catch(isolate);
v8::Local<v8::Value> method;
if (!object->Get(context, V8AtomicString(isolate, method_name))
.ToLocal(&method)) {
DLOG(WARNING) << "Ignored failed lookup of '" << method_name
<< "' in CallNullaryMethod";
return;
}
if (!method->IsFunction()) {
DLOG(WARNING) << "Didn't call '" << method_name
<< "' in CallNullaryMethod because it was the wrong type";
return;
}
v8::MaybeLocal<v8::Value> result =
method.As<v8::Function>()->Call(context, object, 0, nullptr);
if (result.IsEmpty()) {
DLOG(WARNING) << "Ignored failure of '" << method_name
<< "' in CallNullaryMethod";
}
}
} // namespace blink } // namespace blink
...@@ -82,12 +82,6 @@ class CORE_EXPORT ReadableStreamReader : public ScriptWrappable { ...@@ -82,12 +82,6 @@ class CORE_EXPORT ReadableStreamReader : public ScriptWrappable {
ReadableStreamReader*, ReadableStreamReader*,
ReadableStreamNative*); ReadableStreamNative*);
// Calls method |method_name| on |object|, passing no arguments, and ignoring
// errors. Used for Blink lock notifications.
static void CallNullaryMethod(ScriptState*,
v8::Local<v8::Object> object,
const char* method_name);
Member<StreamPromiseResolver> closed_promise_; Member<StreamPromiseResolver> closed_promise_;
bool for_author_code_ = true; bool for_author_code_ = true;
Member<ReadableStreamNative> owner_readable_stream_; Member<ReadableStreamNative> owner_readable_stream_;
......
...@@ -47,22 +47,6 @@ ScriptValue UnderlyingSourceBase::type(ScriptState* script_state) const { ...@@ -47,22 +47,6 @@ ScriptValue UnderlyingSourceBase::type(ScriptState* script_state) const {
return ScriptValue(script_state, v8::Undefined(script_state->GetIsolate())); return ScriptValue(script_state, v8::Undefined(script_state->GetIsolate()));
} }
void UnderlyingSourceBase::notifyLockAcquired() {
is_stream_locked_ = true;
}
void UnderlyingSourceBase::notifyLockReleased() {
is_stream_locked_ = false;
}
bool UnderlyingSourceBase::HasPendingActivity() const {
// This will return false within a finite time period _assuming_ that
// consumers use the controller to close or error the stream.
// Browser-created readable streams should always close or error within a
// finite time period, due to timeouts etc.
return controller_ && controller_->IsActive() && is_stream_locked_;
}
void UnderlyingSourceBase::ContextDestroyed(ExecutionContext*) { void UnderlyingSourceBase::ContextDestroyed(ExecutionContext*) {
if (controller_) { if (controller_) {
controller_->NoteHasBeenCanceled(); controller_->NoteHasBeenCanceled();
......
...@@ -22,7 +22,6 @@ class ReadableStreamDefaultControllerInterface; ...@@ -22,7 +22,6 @@ class ReadableStreamDefaultControllerInterface;
class CORE_EXPORT UnderlyingSourceBase class CORE_EXPORT UnderlyingSourceBase
: public ScriptWrappable, : public ScriptWrappable,
public ActiveScriptWrappable<UnderlyingSourceBase>,
public ContextLifecycleObserver { public ContextLifecycleObserver {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(UnderlyingSourceBase); USING_GARBAGE_COLLECTED_MIXIN(UnderlyingSourceBase);
...@@ -41,13 +40,8 @@ class CORE_EXPORT UnderlyingSourceBase ...@@ -41,13 +40,8 @@ class CORE_EXPORT UnderlyingSourceBase
ScriptValue type(ScriptState*) const; ScriptValue type(ScriptState*) const;
void notifyLockAcquired();
void notifyLockReleased();
// ScriptWrappable
bool HasPendingActivity() const override;
// ContextLifecycleObserver // ContextLifecycleObserver
// TODO(ricea): Is this still useful?
void ContextDestroyed(ExecutionContext*) override; void ContextDestroyed(ExecutionContext*) override;
protected: protected:
...@@ -60,7 +54,6 @@ class CORE_EXPORT UnderlyingSourceBase ...@@ -60,7 +54,6 @@ class CORE_EXPORT UnderlyingSourceBase
private: private:
Member<ReadableStreamDefaultControllerInterface> controller_; Member<ReadableStreamDefaultControllerInterface> controller_;
bool is_stream_locked_ = false;
}; };
} // namespace blink } // namespace blink
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
// automatically for use in initializing a ReadableStream. // automatically for use in initializing a ReadableStream.
[ [
ActiveScriptWrappable,
NoInterfaceObject NoInterfaceObject
] ]
interface UnderlyingSourceBase { interface UnderlyingSourceBase {
...@@ -18,7 +17,4 @@ interface UnderlyingSourceBase { ...@@ -18,7 +17,4 @@ interface UnderlyingSourceBase {
// This only exists to prevent Object.prototype.type being accessed. // This only exists to prevent Object.prototype.type being accessed.
[CallWith=ScriptState] readonly attribute any type; [CallWith=ScriptState] readonly attribute any type;
void notifyLockAcquired();
void notifyLockReleased();
}; };
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