Commit 72f7bf20 authored by Nidhi Jaju's avatar Nidhi Jaju Committed by Commit Bot

Add base class ReadableStreamController

This CL aims to add polymorphism to the readable stream controller
classes. In particular, it adds a new base class called
ReadableStreamController, and the ReadableStreamDefaultController and
ReadableByteStreamController classes inherit PullSteps() and
CancelSteps() from the ReadableStreamController.

This is based on the approach discussed in
https://docs.google.com/document/d/1rvKpGjppeqRSWntokY-ft_hU2i2us8gis6zgrrLWSTI/view

Bug: 614302
Change-Id: I58439e52e43b525cadbb1a9d36dd950005a7c32c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2531794
Commit-Queue: Nidhi Jaju <nidhijaju@google.com>
Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827038}
parent 0bc1ba79
...@@ -23,6 +23,7 @@ blink_core_sources_streams = [ ...@@ -23,6 +23,7 @@ blink_core_sources_streams = [
"readable_stream_byob_reader.h", "readable_stream_byob_reader.h",
"readable_stream_byob_request.cc", "readable_stream_byob_request.cc",
"readable_stream_byob_request.h", "readable_stream_byob_request.h",
"readable_stream_controller.h",
"readable_stream_default_controller.cc", "readable_stream_default_controller.cc",
"readable_stream_default_controller.h", "readable_stream_default_controller.h",
"readable_stream_default_controller_with_script_scope.cc", "readable_stream_default_controller_with_script_scope.cc",
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/streams/readable_byte_stream_controller.h" #include "third_party/blink/renderer/core/streams/readable_byte_stream_controller.h"
#include "third_party/blink/renderer/core/streams/readable_stream_byob_request.h" #include "third_party/blink/renderer/core/streams/readable_stream_byob_request.h"
#include "third_party/blink/renderer/core/streams/stream_promise_resolver.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h"
...@@ -50,6 +51,29 @@ void ReadableByteStreamController::error(ScriptState* script_state, ...@@ -50,6 +51,29 @@ void ReadableByteStreamController::error(ScriptState* script_state,
return; return;
} }
//
// Readable byte stream controller internal methods
//
v8::Local<v8::Promise> ReadableByteStreamController::CancelSteps(
ScriptState* script_state,
v8::Local<v8::Value> reason) {
ExceptionState exception_state(script_state->GetIsolate(),
ExceptionState::kExecutionContext, nullptr,
nullptr);
ThrowUnimplemented(exception_state);
return v8::Local<v8::Promise>();
}
StreamPromiseResolver* ReadableByteStreamController::PullSteps(
ScriptState* script_state) {
ExceptionState exception_state(script_state->GetIsolate(),
ExceptionState::kExecutionContext, nullptr,
nullptr);
ThrowUnimplemented(exception_state);
return nullptr;
}
void ReadableByteStreamController::ThrowUnimplemented( void ReadableByteStreamController::ThrowUnimplemented(
ExceptionState& exception_state) { ExceptionState& exception_state) {
exception_state.ThrowTypeError("unimplemented"); exception_state.ThrowTypeError("unimplemented");
......
...@@ -7,17 +7,20 @@ ...@@ -7,17 +7,20 @@
#include "base/optional.h" #include "base/optional.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/streams/readable_stream_controller.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer_view_helpers.h" #include "third_party/blink/renderer/core/typed_arrays/array_buffer_view_helpers.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "v8/include/v8.h"
namespace blink { namespace blink {
class ExceptionState;
class ScriptState;
class DOMArrayBufferView; class DOMArrayBufferView;
class ExceptionState;
class ReadableStreamBYOBRequest; class ReadableStreamBYOBRequest;
class ScriptState;
class StreamPromiseResolver;
class ReadableByteStreamController : public ScriptWrappable { class ReadableByteStreamController : public ReadableStreamController {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
...@@ -39,6 +42,13 @@ class ReadableByteStreamController : public ScriptWrappable { ...@@ -39,6 +42,13 @@ class ReadableByteStreamController : public ScriptWrappable {
void error(ScriptState*, ExceptionState&); void error(ScriptState*, ExceptionState&);
void error(ScriptState*, ScriptValue e, ExceptionState&); void error(ScriptState*, ScriptValue e, ExceptionState&);
// https://streams.spec.whatwg.org/#rbs-controller-private-cancel
v8::Local<v8::Promise> CancelSteps(ScriptState*,
v8::Local<v8::Value> reason) override;
// https://streams.spec.whatwg.org/#rbs-controller-private-pull
StreamPromiseResolver* PullSteps(ScriptState*) override;
private: private:
static void ThrowUnimplemented(ExceptionState&); static void ThrowUnimplemented(ExceptionState&);
}; };
......
// Copyright 2020 The Chromium AUthors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_CONTROLLER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_CONTROLLER_H_
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "v8/include/v8.h"
namespace blink {
class ScriptState;
class StreamPromiseResolver;
class ReadableStreamController : public ScriptWrappable {
public:
// https://streams.spec.whatwg.org/#abstract-opdef-readablestreamcontroller-cancelsteps
virtual v8::Local<v8::Promise> CancelSteps(ScriptState*,
v8::Local<v8::Value> reason) = 0;
// https://streams.spec.whatwg.org/#abstract-opdef-readablestreamcontroller-pullsteps
virtual StreamPromiseResolver* PullSteps(ScriptState*) = 0;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_CONTROLLER_H_
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_DEFAULT_CONTROLLER_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_DEFAULT_CONTROLLER_H_
#include "base/optional.h" #include "base/optional.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/core/streams/readable_stream_controller.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
namespace blink { namespace blink {
...@@ -21,7 +21,7 @@ class StreamAlgorithm; ...@@ -21,7 +21,7 @@ class StreamAlgorithm;
class StreamPromiseResolver; class StreamPromiseResolver;
class StreamStartAlgorithm; class StreamStartAlgorithm;
class ReadableStreamDefaultController : public ScriptWrappable { class ReadableStreamDefaultController : public ReadableStreamController {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
...@@ -72,15 +72,16 @@ class ReadableStreamDefaultController : public ScriptWrappable { ...@@ -72,15 +72,16 @@ class ReadableStreamDefaultController : public ScriptWrappable {
void Trace(Visitor*) const override; void Trace(Visitor*) const override;
private:
friend class ReadableStream;
friend class ReadableStreamDefaultReader;
// https://streams.spec.whatwg.org/#rs-default-controller-private-cancel // https://streams.spec.whatwg.org/#rs-default-controller-private-cancel
v8::Local<v8::Promise> CancelSteps(ScriptState*, v8::Local<v8::Value> reason); v8::Local<v8::Promise> CancelSteps(ScriptState*,
v8::Local<v8::Value> reason) override;
// https://streams.spec.whatwg.org/#rs-default-controller-private-pull // https://streams.spec.whatwg.org/#rs-default-controller-private-pull
StreamPromiseResolver* PullSteps(ScriptState*); StreamPromiseResolver* PullSteps(ScriptState*) override;
private:
friend class ReadableStream;
friend class ReadableStreamDefaultReader;
// https://streams.spec.whatwg.org/#readable-stream-default-controller-call-pull-if-needed // https://streams.spec.whatwg.org/#readable-stream-default-controller-call-pull-if-needed
static void CallPullIfNeeded(ScriptState*, ReadableStreamDefaultController*); static void CallPullIfNeeded(ScriptState*, ReadableStreamDefaultController*);
......
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