Переглянути джерело

LibWeb: Implement Streams AO CanTransferArrayBuffer

Shannon Booth 1 рік тому
батько
коміт
0245be70d8

+ 18 - 0
Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp

@@ -3736,6 +3736,24 @@ bool is_non_negative_number(JS::Value value)
     return true;
 }
 
+// https://streams.spec.whatwg.org/#can-transfer-array-buffer
+bool can_transfer_array_buffer(JS::ArrayBuffer const& array_buffer)
+{
+    // 1. Assert: Type(O) is Object.
+    // 2. Assert: O has an [[ArrayBufferData]] internal slot.
+
+    // 3. If ! IsDetachedBuffer(O) is true, return false.
+    if (array_buffer.is_detached())
+        return false;
+
+    // 4. If SameValue(O.[[ArrayBufferDetachKey]], undefined) is false, return false.
+    if (!JS::same_value(array_buffer.detach_key(), JS::js_undefined()))
+        return false;
+
+    // 5. Return true.
+    return true;
+}
+
 // https://streams.spec.whatwg.org/#close-sentinel
 // Non-standard function that implements the "close sentinel" value.
 JS::Value create_close_sentinel()

+ 1 - 0
Userland/Libraries/LibWeb/Streams/AbstractOperations.h

@@ -168,6 +168,7 @@ WebIDL::ExceptionOr<void> transform_stream_error_writable_and_unblock_write(Tran
 WebIDL::ExceptionOr<void> transform_stream_set_backpressure(TransformStream&, bool backpressure);
 
 bool is_non_negative_number(JS::Value);
+bool can_transfer_array_buffer(JS::ArrayBuffer const& array_buffer);
 
 JS::Value create_close_sentinel();
 bool is_close_sentinel(JS::Value);