summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/streams/transform_stream.h
blob: 1fb4cead703b1bd9ef66f0c34bcf9e6033d05a1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_TRANSFORM_STREAM_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_TRANSFORM_STREAM_H_

#include "base/macros.h"
#include "third_party/blink/renderer/core/core_export.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 "v8/include/v8.h"

namespace blink {

class ExceptionState;
class ScriptState;
class ScriptValue;
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 GarbageCollectedFinalized<TransformStream> {
 public:
  TransformStream();
  ~TransformStream();

  // If HadException is true on return, the object is invalid and should be
  // destroyed.
  void Init(TransformStreamTransformer*, ScriptState*, ExceptionState&);

  ScriptValue Readable(ScriptState*, ExceptionState&) const;
  ScriptValue Writable(ScriptState*, ExceptionState&) const;

  void Trace(Visitor*);

 private:
  // These are class-scoped to avoid name clashes in jumbo builds.
  class Algorithm;
  class FlushAlgorithm;
  class TransformAlgorithm;

  // Common implementation for Readable() and Writable() accessors.
  ScriptValue Accessor(const char* accessor_function_name,
                       ScriptState*,
                       ExceptionState&) const;

  TraceWrapperV8Reference<v8::Value> stream_;

  DISALLOW_COPY_AND_ASSIGN(TransformStream);
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_TRANSFORM_STREAM_H_