@@ -543,56 +543,59 @@ private void ProjectFields(EmbeddedItem externalItem)
543543 JsValue getMethodValue = JsValue . CreateFunction ( nativeGetFunction ) ;
544544 descriptorValue . SetProperty ( "get" , getMethodValue , true ) ;
545545
546- JsNativeFunction nativeSetFunction = ( callee , isConstructCall , args , argCount , callbackData ) =>
546+ if ( ! field . IsInitOnly )
547547 {
548- JsValue undefinedValue = JsValue . Undefined ;
549-
550- if ( instance && obj is null )
548+ JsNativeFunction nativeSetFunction = ( callee , isConstructCall , args , argCount , callbackData ) =>
551549 {
552- CreateAndSetTypeError ( string . Format (
553- Strings . Runtime_InvalidThisContextForHostObjectField , fieldName ) ) ;
554- return undefinedValue ;
555- }
550+ JsValue undefinedValue = JsValue . Undefined ;
556551
557- object value = MapToHostType ( args [ 1 ] ) ;
558- ReflectionHelpers . FixFieldValueType ( ref value , field ) ;
552+ if ( instance && obj is null )
553+ {
554+ CreateAndSetTypeError ( string . Format (
555+ Strings . Runtime_InvalidThisContextForHostObjectField , fieldName ) ) ;
556+ return undefinedValue ;
557+ }
559558
560- try
561- {
562- field . SetValue ( obj , value ) ;
563- }
564- catch ( Exception e )
565- {
566- Exception exception = UnwrapException ( e ) ;
567- var wrapperException = exception as WrapperException ;
568- JsValue errorValue ;
559+ object value = MapToHostType ( args [ 1 ] ) ;
560+ ReflectionHelpers . FixFieldValueType ( ref value , field ) ;
569561
570- if ( wrapperException is not null )
562+ try
571563 {
572- errorValue = CreateErrorFromWrapperException ( wrapperException ) ;
564+ field . SetValue ( obj , value ) ;
573565 }
574- else
566+ catch ( Exception e )
575567 {
576- string errorMessage = instance ?
577- string . Format ( Strings . Runtime_HostObjectFieldSettingFailed , fieldName ,
578- exception . Message )
579- :
580- string . Format ( Strings . Runtime_HostTypeFieldSettingFailed , fieldName , typeName ,
581- exception . Message )
582- ;
583- errorValue = JsErrorHelpers . CreateError ( errorMessage ) ;
568+ Exception exception = UnwrapException ( e ) ;
569+ var wrapperException = exception as WrapperException ;
570+ JsValue errorValue ;
571+
572+ if ( wrapperException is not null )
573+ {
574+ errorValue = CreateErrorFromWrapperException ( wrapperException ) ;
575+ }
576+ else
577+ {
578+ string errorMessage = instance ?
579+ string . Format ( Strings . Runtime_HostObjectFieldSettingFailed , fieldName ,
580+ exception . Message )
581+ :
582+ string . Format ( Strings . Runtime_HostTypeFieldSettingFailed , fieldName , typeName ,
583+ exception . Message )
584+ ;
585+ errorValue = JsErrorHelpers . CreateError ( errorMessage ) ;
586+ }
587+ JsContext . SetException ( errorValue ) ;
588+
589+ return undefinedValue ;
584590 }
585- JsContext . SetException ( errorValue ) ;
586591
587592 return undefinedValue ;
588- }
589-
590- return undefinedValue ;
591- } ;
592- nativeFunctions . Add ( nativeSetFunction ) ;
593+ } ;
594+ nativeFunctions . Add ( nativeSetFunction ) ;
593595
594- JsValue setMethodValue = JsValue . CreateFunction ( nativeSetFunction ) ;
595- descriptorValue . SetProperty ( "set" , setMethodValue , true ) ;
596+ JsValue setMethodValue = JsValue . CreateFunction ( nativeSetFunction ) ;
597+ descriptorValue . SetProperty ( "set" , setMethodValue , true ) ;
598+ }
596599
597600 typeValue . DefineProperty ( fieldName , descriptorValue ) ;
598601 }
@@ -622,7 +625,7 @@ private void ProjectProperties(EmbeddedItem externalItem)
622625 JsValue descriptorValue = JsValue . CreateObject ( ) ;
623626 descriptorValue . SetProperty ( "enumerable" , JsValue . True , true ) ;
624627
625- if ( property . GetGetMethod ( ) is not null )
628+ if ( property . CanRead )
626629 {
627630 JsNativeFunction nativeGetFunction = ( callee , isConstructCall , args , argCount , callbackData ) =>
628631 {
@@ -677,7 +680,7 @@ private void ProjectProperties(EmbeddedItem externalItem)
677680 descriptorValue . SetProperty ( "get" , getMethodValue , true ) ;
678681 }
679682
680- if ( property . GetSetMethod ( ) is not null )
683+ if ( property . CanWrite )
681684 {
682685 JsNativeFunction nativeSetFunction = ( callee , isConstructCall , args , argCount , callbackData ) =>
683686 {
0 commit comments