summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/streams/readable_stream.cc
blob: 8b787d62af19a78aadd748c8cdeb4ef10c11118e (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
67
68
69
70
71
72
73
74
// 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 "third_party/blink/renderer/core/streams/readable_stream.h"

#include "third_party/blink/renderer/core/streams/readable_stream_native.h"
#include "third_party/blink/renderer/core/streams/readable_stream_wrapper.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"

namespace blink {

ReadableStream* ReadableStream::Create(ScriptState* script_state,
                                       ExceptionState& exception_state) {
  return Create(
      script_state,
      ScriptValue(script_state, v8::Undefined(script_state->GetIsolate())),
      ScriptValue(script_state, v8::Undefined(script_state->GetIsolate())),
      exception_state);
}

ReadableStream* ReadableStream::Create(ScriptState* script_state,
                                       ScriptValue underlying_source,
                                       ExceptionState& exception_state) {
  return Create(
      script_state, underlying_source,
      ScriptValue(script_state, v8::Undefined(script_state->GetIsolate())),
      exception_state);
}

ReadableStream* ReadableStream::Create(ScriptState* script_state,
                                       ScriptValue underlying_source,
                                       ScriptValue strategy,
                                       ExceptionState& exception_state) {
  if (RuntimeEnabledFeatures::StreamsNativeEnabled()) {
    return ReadableStreamNative::Create(script_state, underlying_source,
                                        strategy, exception_state);
  }

  return ReadableStreamWrapper::Create(script_state, underlying_source,
                                       strategy, exception_state);
}

ReadableStream* ReadableStream::CreateWithCountQueueingStrategy(
    ScriptState* script_state,
    UnderlyingSourceBase* underlying_source,
    size_t high_water_mark) {
  if (RuntimeEnabledFeatures::StreamsNativeEnabled()) {
    return ReadableStreamNative::CreateWithCountQueueingStrategy(
        script_state, underlying_source, high_water_mark);
  }

  // TODO(ricea): Select implementation based on StreamsNative feature here.
  return ReadableStreamWrapper::CreateWithCountQueueingStrategy(
      script_state, underlying_source, high_water_mark);
}

// static
ReadableStream* ReadableStream::Deserialize(ScriptState* script_state,
                                            MessagePort* port,
                                            ExceptionState& exception_state) {
  // TODO(ricea): Implementation serialization for the native implementation.
  if (RuntimeEnabledFeatures::StreamsNativeEnabled()) {
    exception_state.ThrowTypeError(
        "serialization disabled because StreamsNative feature is enabled");
    return nullptr;
  }

  return ReadableStreamWrapper::Deserialize(script_state, port,
                                            exception_state);
}

}  // namespace blink