@@ -94,20 +94,19 @@ fn generate_public_component(
94
94
property_and_callback_accessors. push ( quote ! (
95
95
#[ allow( dead_code) ]
96
96
pub fn #caller_ident( & self , #( #args_name : #callback_args, ) * ) -> #return_type {
97
- self . 0 . borrow( ) . instance( ) . invoke( #prop_name, & [ #( #args_name. into( ) , ) * ] )
98
- . unwrap_or_else( |e| panic!( "Cannot invoke callback {}::{}: {e}" , #component_name, #prop_name) )
99
- . try_into( ) . expect( "Invalid return type" )
97
+ self . 0 . borrow( ) . invoke( #prop_name, & [ #( #args_name. into( ) , ) * ] )
98
+ . try_into( ) . unwrap_or_else( |_| panic!( "Invalid return type for callback {}::{}" , #component_name, #prop_name) )
100
99
}
101
100
) ) ;
102
101
let on_ident = format_ident ! ( "on_{}" , prop_ident) ;
103
102
property_and_callback_accessors. push ( quote ! (
104
103
#[ allow( dead_code) ]
105
104
pub fn #on_ident( & self , f: impl FnMut ( #( #callback_args) , * ) -> #return_type + ' static ) {
106
105
let f = :: core:: cell:: RefCell :: new( f) ;
107
- self . 0 . borrow ( ) . instance ( ) . set_callback( #prop_name, move |values| {
106
+ self . 0 . borrow_mut ( ) . set_callback( #prop_name, sp :: Rc :: new ( move |values| {
108
107
let [ #( #args_name, ) * ] = values else { panic!( "invalid number of argument for callback {}::{}" , #component_name, #prop_name) } ;
109
108
( * f. borrow_mut( ) ) ( #( #args_name. clone( ) . try_into( ) . unwrap_or_else( |_| panic!( "invalid argument for callback {}::{}" , #component_name, #prop_name) ) , ) * ) . into( )
110
- } ) . unwrap_or_else ( |e| panic! ( "Cannot set callback {}::{}: {e}" , #component_name , #prop_name ) )
109
+ } ) )
111
110
}
112
111
) ) ;
113
112
} else if let Type :: Function ( function) = & p. ty {
@@ -120,9 +119,8 @@ fn generate_public_component(
120
119
property_and_callback_accessors. push ( quote ! (
121
120
#[ allow( dead_code) ]
122
121
pub fn #caller_ident( & self , #( #args_name : #callback_args, ) * ) -> #return_type {
123
- self . 0 . borrow( ) . instance( ) . invoke( #prop_name, & [ #( #args_name. into( ) , ) * ] )
124
- . unwrap_or_else( |e| panic!( "Cannot invoke callback {}::{}: {e}" , #component_name, #prop_name) )
125
- . try_into( ) . expect( "Invalid return type" )
122
+ self . 0 . borrow( ) . invoke( #prop_name, & [ #( #args_name. into( ) , ) * ] )
123
+ . try_into( ) . unwrap_or_else( |_| panic!( "Invalid return type for function {}::{}" , #component_name, #prop_name) )
126
124
}
127
125
) ) ;
128
126
} else {
@@ -134,11 +132,8 @@ fn generate_public_component(
134
132
property_and_callback_accessors. push ( quote ! (
135
133
#[ allow( dead_code) ]
136
134
pub fn #getter_ident( & self ) -> #rust_property_type {
137
- #[ allow( unused_imports) ]
138
- #convert_from_value(
139
- self . 0 . instance( ) get_property( #prop_name)
140
- . unwrap_or_else( |e| panic!( "Cannot get property {}::{} - {e}" , #component_name, #prop_name) )
141
- ) . expect( "Invalid property type" )
135
+ #convert_from_value( self . 0 . borrow( ) . get_property( #prop_name) )
136
+ . unwrap_or_else( |_| panic!( "Invalid property type for {}::{}" , #component_name, #prop_name) )
142
137
}
143
138
) ) ;
144
139
@@ -147,8 +142,7 @@ fn generate_public_component(
147
142
property_and_callback_accessors. push ( quote ! (
148
143
#[ allow( dead_code) ]
149
144
pub fn #setter_ident( & self , value: #rust_property_type) {
150
- self . 0 . set_property( #prop_name, #convert_to_value( value) )
151
- . unwrap_or_else( |e| panic!( "Cannot set property {}::{} - {e}" , #component_name, #prop_name) ) ;
145
+ self . 0 . borrow_mut( ) . set_property( #prop_name, #convert_to_value( value) )
152
146
}
153
147
) ) ;
154
148
} else {
@@ -253,20 +247,19 @@ fn generate_global(global: &llr::GlobalComponent, root: &llr::CompilationUnit) -
253
247
property_and_callback_accessors. push ( quote ! (
254
248
#[ allow( dead_code) ]
255
249
pub fn #caller_ident( & self , #( #args_name : #callback_args, ) * ) -> #return_type {
256
- self . 0 . borrow( ) . instance( ) . invoke_global( #global_name, #prop_name, & [ #( #args_name. into( ) , ) * ] )
257
- . unwrap_or_else( |e| panic!( "Cannot invoke callback {}::{}: {e}" , #global_name, #prop_name) )
258
- . try_into( ) . expect( "Invalid return type" )
250
+ self . 0 . borrow( ) . invoke_global( #global_name, #prop_name, & [ #( #args_name. into( ) , ) * ] )
251
+ . try_into( ) . unwrap_or_else( |_| panic!( "Invalid return type for callback {}::{}" , #global_name, #prop_name) )
259
252
}
260
253
) ) ;
261
254
let on_ident = format_ident ! ( "on_{}" , prop_ident) ;
262
255
property_and_callback_accessors. push ( quote ! (
263
256
#[ allow( dead_code) ]
264
257
pub fn #on_ident( & self , f: impl FnMut ( #( #callback_args) , * ) -> #return_type + ' static ) {
265
258
let f = :: core:: cell:: RefCell :: new( f) ;
266
- self . 0 . borrow ( ) . instance ( ) . set_global_callback( #global_name, #prop_name, move |values| {
259
+ self . 0 . borrow_mut ( ) . set_global_callback( #global_name, #prop_name, sp :: Rc :: new ( move |values| {
267
260
let [ #( #args_name, ) * ] = values else { panic!( "invalid number of argument for callback {}::{}" , #global_name, #prop_name) } ;
268
261
( * f. borrow_mut( ) ) ( #( #args_name. clone( ) . try_into( ) . unwrap_or_else( |_| panic!( "invalid argument for callback {}::{}" , #global_name, #prop_name) ) , ) * ) . into( )
269
- } ) . unwrap_or_else ( |e| panic! ( "Cannot set callback {}::{}: {e}" , #global_name , #prop_name ) )
262
+ } ) )
270
263
}
271
264
) ) ;
272
265
} else if let Type :: Function ( function) = & p. ty {
@@ -279,9 +272,8 @@ fn generate_global(global: &llr::GlobalComponent, root: &llr::CompilationUnit) -
279
272
property_and_callback_accessors. push ( quote ! (
280
273
#[ allow( dead_code) ]
281
274
pub fn #caller_ident( & self , #( #args_name : #callback_args, ) * ) -> #return_type {
282
- self . 0 . borrow( ) . instance( ) . invoke_global( #global_name, #prop_name, & [ #( #args_name. into( ) , ) * ] )
283
- . unwrap_or_else( |e| panic!( "Cannot invoke callback {}::{}: {e}" , #global_name, #prop_name) )
284
- . try_into( ) . expect( "Invalid return type" )
275
+ self . 0 . borrow( ) . invoke_global( #global_name, #prop_name, & [ #( #args_name. into( ) , ) * ] )
276
+ . try_into( ) . unwrap_or_else( |_| panic!( "Invalid return type for function {}::{}" , #global_name, #prop_name) )
285
277
}
286
278
) ) ;
287
279
} else {
@@ -293,10 +285,8 @@ fn generate_global(global: &llr::GlobalComponent, root: &llr::CompilationUnit) -
293
285
property_and_callback_accessors. push ( quote ! (
294
286
#[ allow( dead_code) ]
295
287
pub fn #getter_ident( & self ) -> #rust_property_type {
296
- #convert_from_value(
297
- self . 0 . borrow( ) . instance( ) . get_global_property( #global_name, #prop_name)
298
- . unwrap_or_else( |e| panic!( "Cannot get property {}::{} - {e}" , #global_name, #prop_name) )
299
- ) . expect( "Invalid property type" )
288
+ #convert_from_value( self . 0 . borrow( ) . get_global_property( #global_name, #prop_name) )
289
+ . unwrap_or_else( |_| panic!( "Invalid property type for {}::{}" , #global_name, #prop_name) )
300
290
}
301
291
) ) ;
302
292
@@ -305,8 +295,7 @@ fn generate_global(global: &llr::GlobalComponent, root: &llr::CompilationUnit) -
305
295
property_and_callback_accessors. push ( quote ! (
306
296
#[ allow( dead_code) ]
307
297
pub fn #setter_ident( & self , value: #rust_property_type) {
308
- self . 0 . borrow( ) . instance( ) . set_global_property( #global_name, #prop_name, #convert_to_value( value) )
309
- . unwrap_or_else( |e| panic!( "Cannot set property {}::{} - {e}" , #global_name, #prop_name) ) ;
298
+ self . 0 . borrow_mut( ) . set_global_property( #global_name, #prop_name, #convert_to_value( value) )
310
299
}
311
300
) ) ;
312
301
} else {
0 commit comments