@@ -999,12 +999,13 @@ fn node_api_create_object_with_properties<'s>(
999999 property_count : usize ,
10001000 result : * mut napi_value < ' s > ,
10011001) -> napi_status {
1002+ let env_ptr = env as * mut Env ;
10021003 check_arg ! ( env, result) ;
10031004
1004- if property_count > 0 {
1005- if property_names. is_null ( ) || property_values. is_null ( ) {
1006- return napi_set_last_error ( env as * mut Env , napi_invalid_arg ) ;
1007- }
1005+ if property_count > 0
1006+ && ( property_names. is_null ( ) || property_values. is_null ( ) )
1007+ {
1008+ return napi_set_last_error ( env_ptr , napi_invalid_arg ) ;
10081009 }
10091010
10101011 v8:: callback_scope!( unsafe scope, env. context( ) ) ;
@@ -1014,7 +1015,7 @@ fn node_api_create_object_with_properties<'s>(
10141015 Some ( local) => local,
10151016 } ;
10161017
1017- let names : & [ v8:: Local < v8:: Value > ] = if property_count == 0 {
1018+ let names_values : & [ v8:: Local < v8:: Value > ] = if property_count == 0 {
10181019 & [ ]
10191020 } else {
10201021 unsafe {
@@ -1036,18 +1037,23 @@ fn node_api_create_object_with_properties<'s>(
10361037 }
10371038 } ;
10381039
1039- let obj = v8:: Object :: with_prototype_and_properties (
1040- scope,
1041- prototype,
1042- names,
1043- values,
1044- ) ;
1040+ let names: Vec < v8:: Local < v8:: Name > > = match names_values
1041+ . iter ( )
1042+ . map ( |v| v8:: Local :: < v8:: Name > :: try_from ( * v) )
1043+ . collect :: < Result < Vec < _ > , _ > > ( )
1044+ {
1045+ Ok ( n) => n,
1046+ Err ( _) => return napi_set_last_error ( env_ptr, napi_name_expected) ,
1047+ } ;
1048+
1049+ let obj =
1050+ v8:: Object :: with_prototype_and_properties ( scope, prototype, & names, values) ;
10451051
10461052 unsafe {
10471053 * result = obj. into ( ) ;
10481054 }
10491055
1050- napi_clear_last_error ( env as * mut Env )
1056+ napi_clear_last_error ( env_ptr )
10511057}
10521058
10531059#[ napi_sym]
0 commit comments