summaryrefslogtreecommitdiffstats
path: root/js/src/builtin/streams/ReadableStreamBYOBReader.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/builtin/streams/ReadableStreamBYOBReader.cpp
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/builtin/streams/ReadableStreamBYOBReader.cpp')
-rw-r--r--js/src/builtin/streams/ReadableStreamBYOBReader.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/js/src/builtin/streams/ReadableStreamBYOBReader.cpp b/js/src/builtin/streams/ReadableStreamBYOBReader.cpp
new file mode 100644
index 0000000000..9d8225dde4
--- /dev/null
+++ b/js/src/builtin/streams/ReadableStreamBYOBReader.cpp
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set ts=8 sts=2 et sw=2 tw=80:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * Class ReadableStreamBYOBReader.
+ *
+ * Byte streams and BYOB readers are unimplemented, so this is skeletal -- yet
+ * helpful to ensure certain trivial tests of the functionality in wpt, that
+ * don't actually test fully-constructed byte streams/BYOB readers, pass. 🙄
+ */
+
+#include "mozilla/Attributes.h" // MOZ_MUST_USE
+
+#include "jsapi.h" // JS_ReportErrorNumberASCII
+
+#include "builtin/streams/ReadableStream.h" // js::ReadableStream
+#include "builtin/streams/ReadableStreamReader.h" // js::CreateReadableStreamBYOBReader, js::ForAuthorCodeBool
+#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
+
+using JS::Handle;
+
+/*** 3.7. Class ReadableStreamBYOBReader *********************************/
+
+/**
+ * Stream spec, 3.7.3. new ReadableStreamBYOBReader ( stream )
+ * Steps 2-5.
+ */
+MOZ_MUST_USE JSObject* js::CreateReadableStreamBYOBReader(
+ JSContext* cx, Handle<ReadableStream*> unwrappedStream,
+ ForAuthorCodeBool forAuthorCode, Handle<JSObject*> proto /* = nullptr */) {
+ // Step 2: If ! IsReadableByteStreamController(
+ // stream.[[readableStreamController]]) is false, throw a
+ // TypeError exception.
+ // We don't implement byte stream controllers yet, so always throw here. Note
+ // that JSMSG_READABLESTREAM_BYTES_TYPE_NOT_IMPLEMENTED can't be used here
+ // because it's a RangeError (and sadly wpt actually tests this and we have a
+ // spurious failure if we don't make this a TypeError).
+ JS_ReportErrorNumberASCII(
+ cx, GetErrorMessage, nullptr,
+ JSMSG_READABLESTREAM_BYOB_READER_FOR_NON_BYTE_STREAM);
+
+ // Step 3: If ! IsReadableStreamLocked(stream) is true, throw a TypeError
+ // exception.
+ // Step 4: Perform ! ReadableStreamReaderGenericInitialize(this, stream).
+ // Step 5: Set this.[[readIntoRequests]] to a new empty List.
+ // Steps 3-5 are presently unreachable.
+ return nullptr;
+}