mirror of
https://github.com/servo/servo.git
synced 2025-09-17 02:18:23 +01:00
script: Make set_dictionary_property a safe function (#39191)
Makes `set_dictionary_property` safe. Testing: Changes are internal, this shouldn't affect behavior. Fixes: #39128 Signed-off-by: lumiscosity <averyrudelphe@gmail.com>
This commit is contained in:
parent
af8723c0b1
commit
088d16d634
4 changed files with 13 additions and 20 deletions
|
@ -222,16 +222,12 @@ impl MessagePort {
|
||||||
type_.safe_to_jsval(cx, type_string.handle_mut());
|
type_.safe_to_jsval(cx, type_string.handle_mut());
|
||||||
|
|
||||||
// Perform ! CreateDataProperty(message, "type", type).
|
// Perform ! CreateDataProperty(message, "type", type).
|
||||||
unsafe {
|
set_dictionary_property(cx, message.handle(), "type", type_string.handle())
|
||||||
set_dictionary_property(*cx, message.handle(), "type", type_string.handle())
|
.expect("Setting the message type should not fail.");
|
||||||
.expect("Setting the message type should not fail.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform ! CreateDataProperty(message, "value", value).
|
// Perform ! CreateDataProperty(message, "value", value).
|
||||||
unsafe {
|
set_dictionary_property(cx, message.handle(), "value", value)
|
||||||
set_dictionary_property(*cx, message.handle(), "value", value)
|
.expect("Setting the message value should not fail.");
|
||||||
.expect("Setting the message value should not fail.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let targetPort be the port with which port is entangled, if any; otherwise let it be null.
|
// Let targetPort be the port with which port is entangled, if any; otherwise let it be null.
|
||||||
// Done in `global.post_messageport_msg`.
|
// Done in `global.post_messageport_msg`.
|
||||||
|
|
|
@ -236,10 +236,8 @@ pub(crate) fn evaluate_key_path_on_value(
|
||||||
// Step 1.3.4. Let p be ! ToString(i).
|
// Step 1.3.4. Let p be ! ToString(i).
|
||||||
// Step 1.3.5. Let status be CreateDataProperty(result, p, key).
|
// Step 1.3.5. Let status be CreateDataProperty(result, p, key).
|
||||||
// Step 1.3.6. Assert: status is true.
|
// Step 1.3.6. Assert: status is true.
|
||||||
unsafe {
|
set_dictionary_property(cx, result.handle(), &i.to_string(), key.handle())
|
||||||
set_dictionary_property(*cx, result.handle(), &i.to_string(), key.handle())
|
.map_err(|_| Error::JSFailed)?;
|
||||||
.map_err(|_| Error::JSFailed)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 1.3.7. Increase i by 1.
|
// Step 1.3.7. Increase i by 1.
|
||||||
// Done by for loop with enumerate()
|
// Done by for loop with enumerate()
|
||||||
|
|
|
@ -7545,7 +7545,7 @@ impl{self.generic} Clone for {self.makeClassName(self.dictionary)}{self.genericS
|
||||||
insertion = (
|
insertion = (
|
||||||
f"rooted!(in(cx) let mut {varName}_js = UndefinedValue());\n"
|
f"rooted!(in(cx) let mut {varName}_js = UndefinedValue());\n"
|
||||||
f"{varName}.to_jsval(cx, {varName}_js.handle_mut());\n"
|
f"{varName}.to_jsval(cx, {varName}_js.handle_mut());\n"
|
||||||
f'set_dictionary_property(cx, obj.handle(), "{dictionaryName}", {varName}_js.handle()).unwrap();')
|
f'set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "{dictionaryName}", {varName}_js.handle()).unwrap();')
|
||||||
return CGGeneric(insertion)
|
return CGGeneric(insertion)
|
||||||
|
|
||||||
def memberInsert(memberInfo: tuple[IDLArgument, JSToNativeConversionInfo]) -> CGThing:
|
def memberInsert(memberInfo: tuple[IDLArgument, JSToNativeConversionInfo]) -> CGThing:
|
||||||
|
|
|
@ -290,12 +290,9 @@ pub unsafe fn get_dictionary_property(
|
||||||
/// Set the property with name `property` from `object`.
|
/// Set the property with name `property` from `object`.
|
||||||
/// Returns `Err(())` on JSAPI failure, or null object,
|
/// Returns `Err(())` on JSAPI failure, or null object,
|
||||||
/// and Ok(()) otherwise
|
/// and Ok(()) otherwise
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
/// `cx` must point to a valid, non-null JSContext.
|
|
||||||
#[allow(clippy::result_unit_err)]
|
#[allow(clippy::result_unit_err)]
|
||||||
pub unsafe fn set_dictionary_property(
|
pub fn set_dictionary_property(
|
||||||
cx: *mut JSContext,
|
cx: SafeJSContext,
|
||||||
object: HandleObject,
|
object: HandleObject,
|
||||||
property: &str,
|
property: &str,
|
||||||
value: HandleValue,
|
value: HandleValue,
|
||||||
|
@ -305,8 +302,10 @@ pub unsafe fn set_dictionary_property(
|
||||||
}
|
}
|
||||||
|
|
||||||
let property = CString::new(property).unwrap();
|
let property = CString::new(property).unwrap();
|
||||||
if !JS_SetProperty(cx, object, property.as_ptr(), value) {
|
unsafe {
|
||||||
return Err(());
|
if !JS_SetProperty(*cx, object, property.as_ptr(), value) {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue