mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
implement Writablestreamdefaultcontroller abortcontroller (#37511)
using abort signal and abortcontroller in Writablestreamdefaultcontroller Part of https://github.com/servo/servo/issues/34866 --------- Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
parent
3ee339eb6d
commit
fc2135cc02
9 changed files with 63 additions and 119 deletions
|
@ -35,7 +35,7 @@ impl AbortController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://dom.spec.whatwg.org/#dom-abortcontroller-abortcontroller>
|
/// <https://dom.spec.whatwg.org/#dom-abortcontroller-abortcontroller>
|
||||||
fn new_with_proto(
|
pub(crate) fn new_with_proto(
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
proto: Option<HandleObject>,
|
proto: Option<HandleObject>,
|
||||||
can_gc: CanGc,
|
can_gc: CanGc,
|
||||||
|
@ -52,10 +52,22 @@ impl AbortController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://dom.spec.whatwg.org/#abortcontroller-signal-abort>
|
/// <https://dom.spec.whatwg.org/#abortcontroller-signal-abort>
|
||||||
fn signal_abort(&self, cx: JSContext, reason: HandleValue, realm: InRealm, can_gc: CanGc) {
|
pub(crate) fn signal_abort(
|
||||||
|
&self,
|
||||||
|
cx: JSContext,
|
||||||
|
reason: HandleValue,
|
||||||
|
realm: InRealm,
|
||||||
|
can_gc: CanGc,
|
||||||
|
) {
|
||||||
// signal abort on controller’s signal with reason if it is given.
|
// signal abort on controller’s signal with reason if it is given.
|
||||||
self.signal.signal_abort(cx, reason, realm, can_gc);
|
self.signal.signal_abort(cx, reason, realm, can_gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <https://dom.spec.whatwg.org/#abortcontroller-signal>
|
||||||
|
pub(crate) fn signal(&self) -> DomRoot<AbortSignal> {
|
||||||
|
// The signal getter steps are to return this’s signal.
|
||||||
|
self.signal.as_rooted()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AbortControllerMethods<crate::DomTypeHolder> for AbortController {
|
impl AbortControllerMethods<crate::DomTypeHolder> for AbortController {
|
||||||
|
|
|
@ -59,7 +59,6 @@ impl AbortSignal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn new_with_proto(
|
pub(crate) fn new_with_proto(
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
proto: Option<HandleObject>,
|
proto: Option<HandleObject>,
|
||||||
|
|
|
@ -738,7 +738,7 @@ impl PipeTo {
|
||||||
let promise = match action {
|
let promise = match action {
|
||||||
ShutdownAction::WritableStreamAbort => {
|
ShutdownAction::WritableStreamAbort => {
|
||||||
let dest = self.writer.get_stream().expect("Stream must be set");
|
let dest = self.writer.get_stream().expect("Stream must be set");
|
||||||
dest.abort(cx, global, error.handle(), can_gc)
|
dest.abort(cx, global, error.handle(), realm, can_gc)
|
||||||
},
|
},
|
||||||
ShutdownAction::ReadableStreamCancel => {
|
ShutdownAction::ReadableStreamCancel => {
|
||||||
let source = self
|
let source = self
|
||||||
|
@ -771,7 +771,7 @@ impl PipeTo {
|
||||||
// If dest.[[state]] is "writable",
|
// If dest.[[state]] is "writable",
|
||||||
let promise = if dest.is_writable() {
|
let promise = if dest.is_writable() {
|
||||||
// return ! WritableStreamAbort(dest, error)
|
// return ! WritableStreamAbort(dest, error)
|
||||||
dest.abort(cx, global, error.handle(), can_gc)
|
dest.abort(cx, global, error.handle(), realm, can_gc)
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, return a promise resolved with undefined.
|
// Otherwise, return a promise resolved with undefined.
|
||||||
Promise::new_resolved(global, cx, (), can_gc)
|
Promise::new_resolved(global, cx, (), can_gc)
|
||||||
|
|
|
@ -655,6 +655,7 @@ impl WritableStream {
|
||||||
cx: SafeJSContext,
|
cx: SafeJSContext,
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
provided_reason: SafeHandleValue,
|
provided_reason: SafeHandleValue,
|
||||||
|
realm: InRealm,
|
||||||
can_gc: CanGc,
|
can_gc: CanGc,
|
||||||
) -> Rc<Promise> {
|
) -> Rc<Promise> {
|
||||||
// If stream.[[state]] is "closed" or "errored",
|
// If stream.[[state]] is "closed" or "errored",
|
||||||
|
@ -663,10 +664,21 @@ impl WritableStream {
|
||||||
return Promise::new_resolved(global, cx, (), can_gc);
|
return Promise::new_resolved(global, cx, (), can_gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Signal abort on stream.[[controller]].[[abortController]] with reason.
|
// Signal abort on stream.[[controller]].[[abortController]] with reason.
|
||||||
|
self.get_controller()
|
||||||
|
.expect("Stream must have a controller.")
|
||||||
|
.signal_abort(cx, provided_reason, realm, can_gc);
|
||||||
|
|
||||||
// TODO: If state is "closed" or "errored", return a promise resolved with undefined.
|
// Let state be stream.[[state]].
|
||||||
// Note: state may have changed because of signal above.
|
let state = self.state.get();
|
||||||
|
|
||||||
|
// If state is "closed" or "errored", return a promise resolved with undefined.
|
||||||
|
if matches!(
|
||||||
|
state,
|
||||||
|
WritableStreamState::Closed | WritableStreamState::Errored
|
||||||
|
) {
|
||||||
|
return Promise::new_resolved(global, cx, (), can_gc);
|
||||||
|
}
|
||||||
|
|
||||||
// If stream.[[pendingAbortRequest]] is not undefined,
|
// If stream.[[pendingAbortRequest]] is not undefined,
|
||||||
if self.pending_abort_request.borrow().is_some() {
|
if self.pending_abort_request.borrow().is_some() {
|
||||||
|
@ -1077,7 +1089,7 @@ impl WritableStreamMethods<crate::DomTypeHolder> for WritableStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return ! WritableStreamAbort(this, reason).
|
// Return ! WritableStreamAbort(this, reason).
|
||||||
self.abort(cx, &global, reason, can_gc)
|
self.abort(cx, &global, reason, realm, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://streams.spec.whatwg.org/#ws-close>
|
/// <https://streams.spec.whatwg.org/#ws-close>
|
||||||
|
|
|
@ -27,6 +27,7 @@ use crate::dom::messageport::MessagePort;
|
||||||
use crate::dom::promise::Promise;
|
use crate::dom::promise::Promise;
|
||||||
use crate::dom::promisenativehandler::{Callback, PromiseNativeHandler};
|
use crate::dom::promisenativehandler::{Callback, PromiseNativeHandler};
|
||||||
use crate::dom::readablestreamdefaultcontroller::{EnqueuedValue, QueueWithSizes, ValueWithSize};
|
use crate::dom::readablestreamdefaultcontroller::{EnqueuedValue, QueueWithSizes, ValueWithSize};
|
||||||
|
use crate::dom::types::{AbortController, AbortSignal};
|
||||||
use crate::dom::writablestream::WritableStream;
|
use crate::dom::writablestream::WritableStream;
|
||||||
use crate::realms::{InRealm, enter_realm};
|
use crate::realms::{InRealm, enter_realm};
|
||||||
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
|
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
|
||||||
|
@ -339,15 +340,20 @@ pub struct WritableStreamDefaultController {
|
||||||
|
|
||||||
/// <https://streams.spec.whatwg.org/#writablestreamdefaultcontroller-stream>
|
/// <https://streams.spec.whatwg.org/#writablestreamdefaultcontroller-stream>
|
||||||
stream: MutNullableDom<WritableStream>,
|
stream: MutNullableDom<WritableStream>,
|
||||||
|
|
||||||
|
/// <https://streams.spec.whatwg.org/#writablestreamdefaultcontroller-abortcontroller>
|
||||||
|
abort_controller: Dom<AbortController>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WritableStreamDefaultController {
|
impl WritableStreamDefaultController {
|
||||||
/// <https://streams.spec.whatwg.org/#set-up-writable-stream-default-controller-from-underlying-sink>
|
/// <https://streams.spec.whatwg.org/#set-up-writable-stream-default-controller-from-underlying-sink>
|
||||||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||||
fn new_inherited(
|
fn new_inherited(
|
||||||
|
global: &GlobalScope,
|
||||||
underlying_sink_type: UnderlyingSinkType,
|
underlying_sink_type: UnderlyingSinkType,
|
||||||
strategy_hwm: f64,
|
strategy_hwm: f64,
|
||||||
strategy_size: Rc<QueuingStrategySize>,
|
strategy_size: Rc<QueuingStrategySize>,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> WritableStreamDefaultController {
|
) -> WritableStreamDefaultController {
|
||||||
WritableStreamDefaultController {
|
WritableStreamDefaultController {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
|
@ -358,6 +364,7 @@ impl WritableStreamDefaultController {
|
||||||
strategy_hwm,
|
strategy_hwm,
|
||||||
strategy_size: RefCell::new(Some(strategy_size)),
|
strategy_size: RefCell::new(Some(strategy_size)),
|
||||||
started: Default::default(),
|
started: Default::default(),
|
||||||
|
abort_controller: Dom::from_ref(&AbortController::new_with_proto(global, None, can_gc)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,9 +378,11 @@ impl WritableStreamDefaultController {
|
||||||
) -> DomRoot<WritableStreamDefaultController> {
|
) -> DomRoot<WritableStreamDefaultController> {
|
||||||
reflect_dom_object(
|
reflect_dom_object(
|
||||||
Box::new(WritableStreamDefaultController::new_inherited(
|
Box::new(WritableStreamDefaultController::new_inherited(
|
||||||
|
global,
|
||||||
underlying_sink_type,
|
underlying_sink_type,
|
||||||
strategy_hwm,
|
strategy_hwm,
|
||||||
strategy_size,
|
strategy_size,
|
||||||
|
can_gc,
|
||||||
)),
|
)),
|
||||||
global,
|
global,
|
||||||
can_gc,
|
can_gc,
|
||||||
|
@ -389,6 +398,18 @@ impl WritableStreamDefaultController {
|
||||||
self.underlying_sink_obj.set(*this_object);
|
self.underlying_sink_obj.set(*this_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// "Signal abort" call from <https://streams.spec.whatwg.org/#writable-stream-abort>
|
||||||
|
pub(crate) fn signal_abort(
|
||||||
|
&self,
|
||||||
|
cx: SafeJSContext,
|
||||||
|
reason: SafeHandleValue,
|
||||||
|
realm: InRealm,
|
||||||
|
can_gc: CanGc,
|
||||||
|
) {
|
||||||
|
self.abort_controller
|
||||||
|
.signal_abort(cx, reason, realm, can_gc);
|
||||||
|
}
|
||||||
|
|
||||||
/// <https://streams.spec.whatwg.org/#writable-stream-default-controller-clear-algorithms>
|
/// <https://streams.spec.whatwg.org/#writable-stream-default-controller-clear-algorithms>
|
||||||
fn clear_algorithms(&self) {
|
fn clear_algorithms(&self) {
|
||||||
match &self.underlying_sink_type {
|
match &self.underlying_sink_type {
|
||||||
|
@ -1085,4 +1106,10 @@ impl WritableStreamDefaultControllerMethods<crate::DomTypeHolder>
|
||||||
// Perform ! WritableStreamDefaultControllerError(this, e).
|
// Perform ! WritableStreamDefaultControllerError(this, e).
|
||||||
self.error(&stream, cx, e, &global, can_gc);
|
self.error(&stream, cx, e, &global, can_gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <https://streams.spec.whatwg.org/#ws-default-controller-signal>
|
||||||
|
fn Signal(&self) -> DomRoot<AbortSignal> {
|
||||||
|
// Return this.[[abortController]]’s signal.
|
||||||
|
self.abort_controller.signal()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,6 +238,7 @@ impl WritableStreamDefaultWriter {
|
||||||
cx: SafeJSContext,
|
cx: SafeJSContext,
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
reason: SafeHandleValue,
|
reason: SafeHandleValue,
|
||||||
|
realm: InRealm,
|
||||||
can_gc: CanGc,
|
can_gc: CanGc,
|
||||||
) -> Rc<Promise> {
|
) -> Rc<Promise> {
|
||||||
// Let stream be writer.[[stream]].
|
// Let stream be writer.[[stream]].
|
||||||
|
@ -247,7 +248,7 @@ impl WritableStreamDefaultWriter {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return ! WritableStreamAbort(stream, reason).
|
// Return ! WritableStreamAbort(stream, reason).
|
||||||
stream.abort(cx, global, reason, can_gc)
|
stream.abort(cx, global, reason, realm, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://streams.spec.whatwg.org/#writable-stream-default-writer-close>
|
/// <https://streams.spec.whatwg.org/#writable-stream-default-writer-close>
|
||||||
|
@ -468,7 +469,7 @@ impl WritableStreamDefaultWriterMethods<crate::DomTypeHolder> for WritableStream
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return ! WritableStreamDefaultWriterAbort(this, reason).
|
// Return ! WritableStreamDefaultWriterAbort(this, reason).
|
||||||
self.abort(cx, &global, reason, can_gc)
|
self.abort(cx, &global, reason, realm, can_gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://streams.spec.whatwg.org/#default-writer-close>
|
/// <https://streams.spec.whatwg.org/#default-writer-close>
|
||||||
|
|
|
@ -6,6 +6,6 @@
|
||||||
|
|
||||||
[Exposed=*]
|
[Exposed=*]
|
||||||
interface WritableStreamDefaultController {
|
interface WritableStreamDefaultController {
|
||||||
// readonly attribute AbortSignal signal;
|
readonly attribute AbortSignal signal;
|
||||||
undefined error(optional any e);
|
undefined error(optional any e);
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,28 +5,6 @@
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
[pipe-through.any.worker.html]
|
[pipe-through.any.worker.html]
|
||||||
expected: ERROR
|
|
||||||
[pipeThrough should accept a real AbortSignal]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically 'null']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically '0']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically 'NaN']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically 'true']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically 'AbortSignal']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically '[object AbortSignal\]']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[pipe-through.any.sharedworker.html]
|
[pipe-through.any.sharedworker.html]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
@ -45,26 +23,3 @@
|
||||||
|
|
||||||
[pipe-through.any.shadowrealm-in-sharedworker.html]
|
[pipe-through.any.shadowrealm-in-sharedworker.html]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
[pipe-through.any.html]
|
|
||||||
expected: ERROR
|
|
||||||
[pipeThrough should accept a real AbortSignal]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically 'null']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically '0']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically 'NaN']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically 'true']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically 'AbortSignal']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[invalid values of signal should throw; specifically '[object AbortSignal\]']
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,69 +1,7 @@
|
||||||
[aborting.any.html]
|
|
||||||
[WritableStreamDefaultController.signal]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[the abort signal is signalled synchronously - write]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[the abort signal is signalled synchronously - close]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[the abort signal is not signalled on error]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[the abort signal is not signalled on write failure]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[the abort signal is not signalled on close failure]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[recursive abort() call from abort() aborting signal (not started)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[recursive abort() call from abort() aborting signal]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[recursive close() call from abort() aborting signal (not started)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[recursive close() call from abort() aborting signal]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[aborting.https.any.shadowrealm-in-serviceworker.html]
|
[aborting.https.any.shadowrealm-in-serviceworker.html]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
[aborting.any.worker.html]
|
[aborting.any.worker.html]
|
||||||
[WritableStreamDefaultController.signal]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[the abort signal is signalled synchronously - write]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[the abort signal is signalled synchronously - close]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[the abort signal is not signalled on error]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[the abort signal is not signalled on write failure]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[the abort signal is not signalled on close failure]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[recursive abort() call from abort() aborting signal (not started)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[recursive abort() call from abort() aborting signal]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[recursive close() call from abort() aborting signal (not started)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[recursive close() call from abort() aborting signal]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[aborting.any.shadowrealm-in-dedicatedworker.html]
|
[aborting.any.shadowrealm-in-dedicatedworker.html]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue