@@ -369,56 +369,59 @@ private void ProjectFields(EdgeEmbeddedItem externalItem)
369369 EdgeJsValue getMethodValue = EdgeJsValue . CreateFunction ( nativeGetFunction ) ;
370370 descriptorValue . SetProperty ( "get" , getMethodValue , true ) ;
371371
372- EdgeJsNativeFunction nativeSetFunction = ( callee , isConstructCall , args , argCount , callbackData ) =>
372+ if ( ! field . IsInitOnly )
373373 {
374- EdgeJsValue undefinedValue = EdgeJsValue . Undefined ;
375-
376- if ( instance && obj is null )
374+ EdgeJsNativeFunction nativeSetFunction = ( callee , isConstructCall , args , argCount , callbackData ) =>
377375 {
378- CreateAndSetTypeError ( string . Format (
379- CommonStrings . Runtime_InvalidThisContextForHostObjectField , fieldName ) ) ;
380- return undefinedValue ;
381- }
376+ EdgeJsValue undefinedValue = EdgeJsValue . Undefined ;
382377
383- object value = MapToHostType ( args [ 1 ] ) ;
384- ReflectionHelpers . FixFieldValueType ( ref value , field ) ;
378+ if ( instance && obj is null )
379+ {
380+ CreateAndSetTypeError ( string . Format (
381+ CommonStrings . Runtime_InvalidThisContextForHostObjectField , fieldName ) ) ;
382+ return undefinedValue ;
383+ }
385384
386- try
387- {
388- field . SetValue ( obj , value ) ;
389- }
390- catch ( Exception e )
391- {
392- Exception exception = UnwrapException ( e ) ;
393- var wrapperException = exception as WrapperException ;
394- EdgeJsValue errorValue ;
385+ object value = MapToHostType ( args [ 1 ] ) ;
386+ ReflectionHelpers . FixFieldValueType ( ref value , field ) ;
395387
396- if ( wrapperException is not null )
388+ try
397389 {
398- errorValue = CreateErrorFromWrapperException ( wrapperException ) ;
390+ field . SetValue ( obj , value ) ;
399391 }
400- else
392+ catch ( Exception e )
401393 {
402- string errorMessage = instance ?
403- string . Format ( CommonStrings . Runtime_HostObjectFieldSettingFailed , fieldName ,
404- exception . Message )
405- :
406- string . Format ( CommonStrings . Runtime_HostTypeFieldSettingFailed , fieldName , typeName ,
407- exception . Message )
408- ;
409- errorValue = EdgeJsErrorHelpers . CreateError ( errorMessage ) ;
394+ Exception exception = UnwrapException ( e ) ;
395+ var wrapperException = exception as WrapperException ;
396+ EdgeJsValue errorValue ;
397+
398+ if ( wrapperException is not null )
399+ {
400+ errorValue = CreateErrorFromWrapperException ( wrapperException ) ;
401+ }
402+ else
403+ {
404+ string errorMessage = instance ?
405+ string . Format ( CommonStrings . Runtime_HostObjectFieldSettingFailed , fieldName ,
406+ exception . Message )
407+ :
408+ string . Format ( CommonStrings . Runtime_HostTypeFieldSettingFailed , fieldName , typeName ,
409+ exception . Message )
410+ ;
411+ errorValue = EdgeJsErrorHelpers . CreateError ( errorMessage ) ;
412+ }
413+ EdgeJsContext . SetException ( errorValue ) ;
414+
415+ return undefinedValue ;
410416 }
411- EdgeJsContext . SetException ( errorValue ) ;
412417
413418 return undefinedValue ;
414- }
415-
416- return undefinedValue ;
417- } ;
418- nativeFunctions . Add ( nativeSetFunction ) ;
419+ } ;
420+ nativeFunctions . Add ( nativeSetFunction ) ;
419421
420- EdgeJsValue setMethodValue = EdgeJsValue . CreateFunction ( nativeSetFunction ) ;
421- descriptorValue . SetProperty ( "set" , setMethodValue , true ) ;
422+ EdgeJsValue setMethodValue = EdgeJsValue . CreateFunction ( nativeSetFunction ) ;
423+ descriptorValue . SetProperty ( "set" , setMethodValue , true ) ;
424+ }
422425
423426 typeValue . DefineProperty ( fieldName , descriptorValue ) ;
424427 }
@@ -448,7 +451,7 @@ private void ProjectProperties(EdgeEmbeddedItem externalItem)
448451 EdgeJsValue descriptorValue = EdgeJsValue . CreateObject ( ) ;
449452 descriptorValue . SetProperty ( "enumerable" , EdgeJsValue . True , true ) ;
450453
451- if ( property . GetGetMethod ( ) is not null )
454+ if ( property . CanRead )
452455 {
453456 EdgeJsNativeFunction nativeGetFunction = ( callee , isConstructCall , args , argCount , callbackData ) =>
454457 {
@@ -503,7 +506,7 @@ private void ProjectProperties(EdgeEmbeddedItem externalItem)
503506 descriptorValue . SetProperty ( "get" , getMethodValue , true ) ;
504507 }
505508
506- if ( property . GetSetMethod ( ) is not null )
509+ if ( property . CanWrite )
507510 {
508511 EdgeJsNativeFunction nativeSetFunction = ( callee , isConstructCall , args , argCount , callbackData ) =>
509512 {
0 commit comments