Skip to content

Add QueuingStrategy and UnderlyingSource#32572

Merged
gterzian merged 13 commits intoservo:readablestream-re-implementationfrom
wusyong:quly
Jun 24, 2024
Merged

Add QueuingStrategy and UnderlyingSource#32572
gterzian merged 13 commits intoservo:readablestream-re-implementationfrom
wusyong:quly

Conversation

@wusyong
Copy link
Copy Markdown
Member

@wusyong wusyong commented Jun 20, 2024

This PR add QueuingStrategy and UnderlyingSource. The related types are also added but with todo!() implementations.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes do not require tests because SM stream is still enabled. This PR aims to add the implementation incrementatlly.

@wusyong wusyong marked this pull request as draft June 20, 2024 06:50
@wusyong wusyong marked this pull request as ready for review June 20, 2024 09:12
@wusyong
Copy link
Copy Markdown
Member Author

wusyong commented Jun 20, 2024

@gterzian Here's the first PR to readablestream-re-implementation. Could you see if the implementation looks good to you?

Copy link
Copy Markdown
Member

@gterzian gterzian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok just one thing that would be nice to do before merging. Also, as said we want to move the unsafe code into dom/bindings, but we can do that in a follow-up(cc @Taym95 that may be a good one for you)

cx: SafeJSContext,
_global: &GlobalScope,
_proto: Option<SafeHandleObject>,
underlying_source: Option<*mut JSObject>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please look into using UnderlyingSource here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is the signature required by the codegen.
And I think the spec also says it will convert to UnderlyingSource in step 2.
https://streams.spec.whatwg.org/#rs-constructor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, ok.

Comment on lines +59 to +89
let global = self.reflector_.global();
let cx = GlobalScope::get_cx();
// Return this's relevant global object's count queuing strategy
// size function.
if let Some(fun) = global.get_count_queuing_strategy_size() {
return Ok(fun);
}

// Step 1. Let steps be the following steps:
// Note: See count_queuing_strategy_size instead.

unsafe {
// Step 2. Let F be
// ! CreateBuiltinFunction(steps, 0, "size", « »,
// globalObject’s relevant Realm).
let raw_fun = JS_NewFunction(
*cx,
Some(count_queuing_strategy_size),
0,
0,
b"size\0".as_ptr() as *const c_char,
);
assert!(!raw_fun.is_null());

// Step 3. Set globalObject’s count queuing strategy size function to
// a Function that represents a reference to F,
// with callback context equal to globalObject’s relevant settings object.
let fun_obj = JS_GetFunctionObject(raw_fun);
let fun = Function::new(cx, fun_obj);
global.set_count_queuing_strategy_size(fun.clone());
Ok(fun)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated, but we will take care of it in another PR when we move this unsafe_code to dom/bindings.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah current Function creation still requires us to write unsafe c function. Maybe we can improve Function later.

Copy link
Copy Markdown
Member

@gterzian gterzian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Let's move the unsafe code do dom/bindings in a subsequent step...

@gterzian gterzian merged commit eb54a96 into servo:readablestream-re-implementation Jun 24, 2024
gterzian pushed a commit to gterzian/servo that referenced this pull request Jul 11, 2024
---------

Co-authored-by: Jason Tsai <[email protected]>
Signed-off-by: gterzian <[email protected]>
gterzian pushed a commit to gterzian/servo that referenced this pull request Jul 11, 2024
---------

Co-authored-by: Jason Tsai <[email protected]>
Signed-off-by: gterzian <[email protected]>
wusyong added a commit that referenced this pull request Aug 21, 2024
---------

Co-authored-by: Jason Tsai <[email protected]>
Signed-off-by: Wu Wayne <[email protected]>
Taym95 pushed a commit to Taym95/servo that referenced this pull request Oct 30, 2024
---------

Co-authored-by: Jason Tsai <[email protected]>
Signed-off-by: Wu Wayne <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants