mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
feat: add CanGc argument in get_dictionary_property (#36156)
* feat: add CanGc argument in get_dictionary_property Signed-off-by: Arya Nair <aryaajitnair@gmail.com> * feat: add CanGc argument in get_dictionary_property Signed-off-by: Arya Nair <aryaajitnair@gmail.com> --------- Signed-off-by: Arya Nair <aryaajitnair@gmail.com>
This commit is contained in:
parent
5a5e49ce47
commit
80fc64d063
6 changed files with 29 additions and 15 deletions
|
@ -282,7 +282,7 @@ struct TransmitBodyPromiseHandler {
|
||||||
impl Callback for TransmitBodyPromiseHandler {
|
impl Callback for TransmitBodyPromiseHandler {
|
||||||
/// Step 5 of <https://fetch.spec.whatwg.org/#concept-request-transmit-body>
|
/// Step 5 of <https://fetch.spec.whatwg.org/#concept-request-transmit-body>
|
||||||
fn callback(&self, cx: JSContext, v: HandleValue, _realm: InRealm, can_gc: CanGc) {
|
fn callback(&self, cx: JSContext, v: HandleValue, _realm: InRealm, can_gc: CanGc) {
|
||||||
let is_done = match get_read_promise_done(cx, &v) {
|
let is_done = match get_read_promise_done(cx, &v, can_gc) {
|
||||||
Ok(is_done) => is_done,
|
Ok(is_done) => is_done,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Step 5.5, the "otherwise" steps.
|
// Step 5.5, the "otherwise" steps.
|
||||||
|
@ -299,7 +299,7 @@ impl Callback for TransmitBodyPromiseHandler {
|
||||||
return self.stream.stop_reading(can_gc);
|
return self.stream.stop_reading(can_gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
let chunk = match get_read_promise_bytes(cx, &v) {
|
let chunk = match get_read_promise_bytes(cx, &v, can_gc) {
|
||||||
Ok(chunk) => chunk,
|
Ok(chunk) => chunk,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Step 5.5, the "otherwise" steps.
|
// Step 5.5, the "otherwise" steps.
|
||||||
|
@ -660,7 +660,7 @@ impl Callback for ConsumeBodyPromiseHandler {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("ConsumeBodyPromiseHandler has no stream in callback.");
|
.expect("ConsumeBodyPromiseHandler has no stream in callback.");
|
||||||
|
|
||||||
let is_done = match get_read_promise_done(cx, &v) {
|
let is_done = match get_read_promise_done(cx, &v, can_gc) {
|
||||||
Ok(is_done) => is_done,
|
Ok(is_done) => is_done,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
stream.stop_reading(can_gc);
|
stream.stop_reading(can_gc);
|
||||||
|
@ -673,7 +673,7 @@ impl Callback for ConsumeBodyPromiseHandler {
|
||||||
// When read is fulfilled with an object whose done property is true.
|
// When read is fulfilled with an object whose done property is true.
|
||||||
self.resolve_result_promise(cx, can_gc);
|
self.resolve_result_promise(cx, can_gc);
|
||||||
} else {
|
} else {
|
||||||
let chunk = match get_read_promise_bytes(cx, &v) {
|
let chunk = match get_read_promise_bytes(cx, &v, can_gc) {
|
||||||
Ok(chunk) => chunk,
|
Ok(chunk) => chunk,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
stream.stop_reading(can_gc);
|
stream.stop_reading(can_gc);
|
||||||
|
|
|
@ -303,6 +303,7 @@ pub(crate) fn get_dictionary_property(
|
||||||
object: HandleObject,
|
object: HandleObject,
|
||||||
property: &str,
|
property: &str,
|
||||||
rval: MutableHandleValue,
|
rval: MutableHandleValue,
|
||||||
|
_can_gc: CanGc,
|
||||||
) -> Result<bool, ()> {
|
) -> Result<bool, ()> {
|
||||||
fn has_property(
|
fn has_property(
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl ByteLengthQueuingStrategyMethods<crate::DomTypeHolder> for ByteLengthQueuin
|
||||||
let fun = native_fn!(byte_length_queuing_strategy_size, c"size", 1, 0);
|
let fun = native_fn!(byte_length_queuing_strategy_size, c"size", 1, 0);
|
||||||
// Step 3. Set globalObject’s byte length queuing strategy size function to
|
// Step 3. Set globalObject’s byte length queuing strategy size function to
|
||||||
// a Function that represents a reference to F,
|
// a Function that represents a reference to F,
|
||||||
// with callback context equal to globalObject’s relevant settings object.
|
// with callback context equal to globalObject's relevant settings object.
|
||||||
global.set_byte_length_queuing_strategy_size(fun.clone());
|
global.set_byte_length_queuing_strategy_size(fun.clone());
|
||||||
Ok(fun)
|
Ok(fun)
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,7 @@ pub(crate) unsafe fn byte_length_queuing_strategy_size(
|
||||||
object.handle(),
|
object.handle(),
|
||||||
"byteLength",
|
"byteLength",
|
||||||
MutableHandleValue::from_raw(args.rval()),
|
MutableHandleValue::from_raw(args.rval()),
|
||||||
|
CanGc::note(),
|
||||||
)
|
)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,8 +197,14 @@ impl Callback for PipeTo {
|
||||||
} else {
|
} else {
|
||||||
rooted!(in(*cx) let object = result.to_object());
|
rooted!(in(*cx) let object = result.to_object());
|
||||||
rooted!(in(*cx) let mut done = UndefinedValue());
|
rooted!(in(*cx) let mut done = UndefinedValue());
|
||||||
get_dictionary_property(*cx, object.handle(), "done", done.handle_mut())
|
get_dictionary_property(
|
||||||
.unwrap()
|
*cx,
|
||||||
|
object.handle(),
|
||||||
|
"done",
|
||||||
|
done.handle_mut(),
|
||||||
|
can_gc,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// If any chunks have been read but not yet written, write them to dest.
|
// If any chunks have been read but not yet written, write them to dest.
|
||||||
|
@ -347,7 +353,7 @@ impl PipeTo {
|
||||||
rooted!(in(*cx) let object = chunk.to_object());
|
rooted!(in(*cx) let object = chunk.to_object());
|
||||||
rooted!(in(*cx) let mut bytes = UndefinedValue());
|
rooted!(in(*cx) let mut bytes = UndefinedValue());
|
||||||
let has_value =
|
let has_value =
|
||||||
get_dictionary_property(*cx, object.handle(), "value", bytes.handle_mut())
|
get_dictionary_property(*cx, object.handle(), "value", bytes.handle_mut(), can_gc)
|
||||||
.expect("Chunk should have a value.");
|
.expect("Chunk should have a value.");
|
||||||
if !bytes.is_undefined() && has_value {
|
if !bytes.is_undefined() && has_value {
|
||||||
// Write the chunk.
|
// Write the chunk.
|
||||||
|
@ -1932,14 +1938,18 @@ impl ReadableStreamMethods<crate::DomTypeHolder> for ReadableStream {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
/// Get the `done` property of an object that a read promise resolved to.
|
/// Get the `done` property of an object that a read promise resolved to.
|
||||||
pub(crate) fn get_read_promise_done(cx: SafeJSContext, v: &SafeHandleValue) -> Result<bool, Error> {
|
pub(crate) fn get_read_promise_done(
|
||||||
|
cx: SafeJSContext,
|
||||||
|
v: &SafeHandleValue,
|
||||||
|
can_gc: CanGc,
|
||||||
|
) -> Result<bool, Error> {
|
||||||
if !v.is_object() {
|
if !v.is_object() {
|
||||||
return Err(Error::Type("Unknown format for done property.".to_string()));
|
return Err(Error::Type("Unknown format for done property.".to_string()));
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
rooted!(in(*cx) let object = v.to_object());
|
rooted!(in(*cx) let object = v.to_object());
|
||||||
rooted!(in(*cx) let mut done = UndefinedValue());
|
rooted!(in(*cx) let mut done = UndefinedValue());
|
||||||
match get_dictionary_property(*cx, object.handle(), "done", done.handle_mut()) {
|
match get_dictionary_property(*cx, object.handle(), "done", done.handle_mut(), can_gc) {
|
||||||
Ok(true) => match bool::from_jsval(*cx, done.handle(), ()) {
|
Ok(true) => match bool::from_jsval(*cx, done.handle(), ()) {
|
||||||
Ok(ConversionResult::Success(val)) => Ok(val),
|
Ok(ConversionResult::Success(val)) => Ok(val),
|
||||||
Ok(ConversionResult::Failure(error)) => Err(Error::Type(error.to_string())),
|
Ok(ConversionResult::Failure(error)) => Err(Error::Type(error.to_string())),
|
||||||
|
@ -1956,6 +1966,7 @@ pub(crate) fn get_read_promise_done(cx: SafeJSContext, v: &SafeHandleValue) -> R
|
||||||
pub(crate) fn get_read_promise_bytes(
|
pub(crate) fn get_read_promise_bytes(
|
||||||
cx: SafeJSContext,
|
cx: SafeJSContext,
|
||||||
v: &SafeHandleValue,
|
v: &SafeHandleValue,
|
||||||
|
can_gc: CanGc,
|
||||||
) -> Result<Vec<u8>, Error> {
|
) -> Result<Vec<u8>, Error> {
|
||||||
if !v.is_object() {
|
if !v.is_object() {
|
||||||
return Err(Error::Type(
|
return Err(Error::Type(
|
||||||
|
@ -1965,7 +1976,7 @@ pub(crate) fn get_read_promise_bytes(
|
||||||
unsafe {
|
unsafe {
|
||||||
rooted!(in(*cx) let object = v.to_object());
|
rooted!(in(*cx) let object = v.to_object());
|
||||||
rooted!(in(*cx) let mut bytes = UndefinedValue());
|
rooted!(in(*cx) let mut bytes = UndefinedValue());
|
||||||
match get_dictionary_property(*cx, object.handle(), "value", bytes.handle_mut()) {
|
match get_dictionary_property(*cx, object.handle(), "value", bytes.handle_mut(), can_gc) {
|
||||||
Ok(true) => {
|
Ok(true) => {
|
||||||
match Vec::<u8>::from_jsval(*cx, bytes.handle(), ConversionBehavior::EnforceRange) {
|
match Vec::<u8>::from_jsval(*cx, bytes.handle(), ConversionBehavior::EnforceRange) {
|
||||||
Ok(ConversionResult::Success(val)) => Ok(val),
|
Ok(ConversionResult::Success(val)) => Ok(val),
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl Callback for ReadLoopFulFillmentHandler {
|
||||||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||||
fn callback(&self, cx: SafeJSContext, v: SafeHandleValue, realm: InRealm, can_gc: CanGc) {
|
fn callback(&self, cx: SafeJSContext, v: SafeHandleValue, realm: InRealm, can_gc: CanGc) {
|
||||||
let global = self.reader.global();
|
let global = self.reader.global();
|
||||||
let is_done = match get_read_promise_done(cx, &v) {
|
let is_done = match get_read_promise_done(cx, &v, can_gc) {
|
||||||
Ok(is_done) => is_done,
|
Ok(is_done) => is_done,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.reader
|
self.reader
|
||||||
|
@ -82,7 +82,7 @@ impl Callback for ReadLoopFulFillmentHandler {
|
||||||
.expect("Releasing the reader should succeed");
|
.expect("Releasing the reader should succeed");
|
||||||
} else {
|
} else {
|
||||||
// <https://streams.spec.whatwg.org/#ref-for-read-request-chunk-steps%E2%91%A6>
|
// <https://streams.spec.whatwg.org/#ref-for-read-request-chunk-steps%E2%91%A6>
|
||||||
let chunk = match get_read_promise_bytes(cx, &v) {
|
let chunk = match get_read_promise_bytes(cx, &v, can_gc) {
|
||||||
Ok(chunk) => chunk,
|
Ok(chunk) => chunk,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// If chunk is not a Uint8Array object, call failureSteps with a TypeError and abort these steps.
|
// If chunk is not a Uint8Array object, call failureSteps with a TypeError and abort these steps.
|
||||||
|
|
|
@ -7394,8 +7394,9 @@ impl{self.generic} Clone for {self.makeClassName(self.dictionary)}{self.genericS
|
||||||
conversion = (
|
conversion = (
|
||||||
"{\n"
|
"{\n"
|
||||||
" rooted!(in(*cx) let mut rval = UndefinedValue());\n"
|
" rooted!(in(*cx) let mut rval = UndefinedValue());\n"
|
||||||
f' if get_dictionary_property(*cx, object.handle(), "{member.identifier.name}", rval.handle_mut())?'
|
" if get_dictionary_property(*cx, object.handle(), "
|
||||||
" && !rval.is_undefined() {\n"
|
f'"{member.identifier.name}", '
|
||||||
|
"rval.handle_mut(), CanGc::note())? && !rval.is_undefined() {\n"
|
||||||
f"{indent(conversion)}\n"
|
f"{indent(conversion)}\n"
|
||||||
" } else {\n"
|
" } else {\n"
|
||||||
f"{indent(default)}\n"
|
f"{indent(default)}\n"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue