Closed lukewarlow closed 2 months ago
Hi @lukewarlow,
I would have expected descriptor.writable to be false?
Host objects always return { writable: true, enumerable: true, configurable: true }
or undefined
for Object.getOwnPropertyDescriptor
. The interceptor that V8 invokes for that function currently checks only whether an accessible .NET member with the specified name exists.
The problem is that the JavaScript and .NET type systems are very different. There are .NET scenarios that JavaScript descriptors don't cover – e.g., write-only properties – and cases where a .NET property's meta-information can't be determined upfront – e.g., situations involving custom setters and dynamic objects.
I would also expect the exception to be a TypeError?
No, ClearScript maps all .NET exceptions to JavaScript's Error
.
Is there a way to define a property as being non-writable in the javascript sense using attributes like this?
No, but you can use the facade pattern or JavaScript's Proxy
to make host objects behave more like JavaScript objects in the script environment.
Good luck!
Please reopen this issue if you have additional thoughts, findings, or questions about this topic. Thanks!
When setting a HostObject's property to be readonly to script, the descriptor from getOwnPropertyDescriptor() still says that the property is writable?
Results in
I would have expected descriptor.writable to be false?
I would also expect the exception to be a TypeError?
Is there a way to define a property as being non-writable in the javascript sense using attributes like this?