From d5f18f8e2f91e3b7ba43c79ca1466d73aa5eb7b8 Mon Sep 17 00:00:00 2001 From: Alistair Date: Tue, 7 Nov 2023 10:33:58 +0000 Subject: [PATCH] Update `[[HostDefined]]` example. --- boa_examples/src/bin/host_defined.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/boa_examples/src/bin/host_defined.rs b/boa_examples/src/bin/host_defined.rs index c60d4c4dcfb..9425a02f4a5 100644 --- a/boa_examples/src/bin/host_defined.rs +++ b/boa_examples/src/bin/host_defined.rs @@ -34,14 +34,15 @@ fn main() -> Result<(), JsError> { // Insert a default CustomHostDefinedStruct. realm - .host_defined() + .host_defined_mut() .insert_default::(); { assert!(realm.host_defined().has::()); // Get the [[HostDefined]] field from the realm and downcast it to our concrete type. - let Some(host_defined) = realm.host_defined().get::() else { + let host_defined = realm.host_defined(); + let Some(host_defined) = host_defined.get::() else { return Err(JsNativeError::typ() .with_message("Realm does not have HostDefined field") .into()); @@ -53,15 +54,15 @@ fn main() -> Result<(), JsError> { // Insert another struct with state into [[HostDefined]] field. realm - .host_defined() + .host_defined_mut() .insert(AnotherCustomHostDefinedStruct::new(10)); { assert!(realm.host_defined().has::()); // Get the [[HostDefined]] field from the realm and downcast it to our concrete type. - let Some(host_defined) = realm.host_defined().get::() - else { + let host_defined = realm.host_defined(); + let Some(host_defined) = host_defined.get::() else { return Err(JsNativeError::typ() .with_message("Realm does not have HostDefined field") .into()); @@ -73,7 +74,7 @@ fn main() -> Result<(), JsError> { // Remove a type from the [[HostDefined]] field. assert!(realm - .host_defined() + .host_defined_mut() .remove::() .is_some()); @@ -86,8 +87,8 @@ fn main() -> Result<(), JsError> { NativeFunction::from_fn_ptr(|_, args, context| { let value: usize = args.get_or_undefined(0).try_js_into(context)?; - let host_defined = context.realm().host_defined(); - let Some(mut host_defined) = host_defined.get_mut::() else { + let mut host_defined = context.realm().host_defined_mut(); + let Some(host_defined) = host_defined.get_mut::() else { return Err(JsNativeError::typ() .with_message("Realm does not have HostDefined field") .into()); @@ -122,7 +123,8 @@ fn main() -> Result<(), JsError> { ", ))?; - let Some(host_defined) = realm.host_defined().get::() else { + let host_defined = realm.host_defined(); + let Some(host_defined) = host_defined.get::() else { return Err(JsNativeError::typ() .with_message("Realm does not have HostDefined field") .into());