blob: 9b5f0b5d4c90bc96b0add11901fb312c5f4156f7 [file] [log] [blame]
// Copyright 2018 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.
#include "base/macros.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_v8_reference.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "v8/include/v8.h"
namespace blink {
class ExceptionState;
class ScriptState;
class ReadableStream;
class TransformStreamTransformer;
class Visitor;
// Creates and wraps a JavaScript TransformStream object with a transformation
// defined in C++. Provides access to the readable and writable streams.
// On-heap references to this class must always be via a TraceWrapperMember, and
// must always have an ancestor in the V8 heap, or |stream_| will be lost.
// To ensure that the JS TransformStream is always referenced, this class uses
// two-stage construction. After calling the constructor, store the reference
// in a TraceWrapperMember before calling Init(). Init() must always be called
// before using the instance.
class CORE_EXPORT TransformStream final : public ScriptWrappable {
~TransformStream() override;
// |Create| functions internally call Init().
static TransformStream* Create(ScriptState*, ExceptionState&);
static TransformStream* Create(ScriptState*,
ScriptValue transformer,
static TransformStream* Create(ScriptState*,
ScriptValue transformer,
ScriptValue writable_strategy,
static TransformStream* Create(ScriptState*,
ScriptValue transformer,
ScriptValue writable_strategy,
ScriptValue readable_strategy,
// If HadException is true on return, the object is invalid and should be
// destroyed.
void Init(TransformStreamTransformer*, ScriptState*, ExceptionState&);
// IDL attributes
ReadableStream* readable() const { return readable_; }
ScriptValue writable(ScriptState* script_state,
ExceptionState& exception_state) const {
return Writable(script_state, exception_state);
ReadableStream* Readable() const { return readable_; }
ScriptValue Writable(ScriptState*, ExceptionState&) const;
void Trace(Visitor*) override;
// These are class-scoped to avoid name clashes in jumbo builds.
class Algorithm;
class FlushAlgorithm;
class TransformAlgorithm;
void InitInternal(ScriptState*,
v8::Local<v8::Object> stream,
TraceWrapperV8Reference<v8::Value> stream_;
TraceWrapperMember<ReadableStream> readable_;
} // namespace blink