Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disguise accessor properties as data properties #4374

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zherczeg
Copy link
Member

This is a non-standard feature, and we can discuss how it should work. The only important thing is that it should have a negligible effect on performance.

@lygstate
Copy link
Contributor

What's this for? any design notes?

@zherczeg
Copy link
Member Author

This is a non-standard feature inspired by v8 engine. This allows disguising an accessor as data property. I.e. a message object created from a network packet can have a sender data property, but the property value is actually computed when the property is read. If this never happens, the property is never computed. Furthermore these accessor functions cannot be queried from the JS code, so it cannot be misused by the application.

Since this feature is non-standard, we can make our decisions about it. The most important thing for me: the performance impact should be minimal.

These properties can be created by setting a flag in the C API. This flag is also set, when the property descriptor is read, so the API functions can get these accessors. If an application never creates such properties, it can ignore this flag, which is useful for backward compatibility.
Option: the C API could also return with the data property.

Form JS side, Object.getOwnPropertyDescriptor and Object.getOwnPropertyDescriptors returns these as data properties. If the property has a setter, writable property is set to true, otherwise it is false.
Danger: these functions can change the object state, which does not normally happen.
Option: writable could be determined in another way, but I think this is good in practice.

Property definition:

Configurable properties: currently reconfiguring these accessors can be done.
Option: when the property configured as data, the setter function could be called. Question: what should happen if the setter is missing.

Non-configurable properties: when the property is defined as data property, the setter is called. If the setter is not present, it is compared to the returned value of the getter. Even in non-configurable case, writable can be changed from true to false. Currently the setter is released in this case.
Option: changing writable could yield an error.

@lygstate
Copy link
Contributor

lygstate commented Dec 29, 2020

This is a non-standard feature inspired by v8 engine. This allows disguising an accessor as data property. I.e. a message object

An reference link to v8 are appreciated, also what's the advantage of this, any demo of it?

created from a network packet can have a sender data property, but the property value is actually computed when the property is read. If this never happens, the property is never computed. Furthermore these accessor functions cannot be queried from the JS code, so it cannot be misused by the application.

Since this feature is non-standard, we can make our decisions about it. The most important thing for me: the performance impact should be minimal.

These properties can be created by setting a flag in the C API. This flag is also set, when the property descriptor is read, so the API functions can get these accessors. If an application never creates such properties, it can ignore this flag, which is useful for backward compatibility.
Option: the C API could also return with the data property.

Form JS side, Object.getOwnPropertyDescriptor and Object.getOwnPropertyDescriptors returns these as data properties. If the property has a setter, writable property is set to true, otherwise it is false.
Danger: these functions can change the object state, which does not normally happen.
Option: writable could be determined in another way, but I think this is good in practice.

Property definition:

Configurable properties: currently reconfiguring these accessors can be done.
Option: when the property configured as data, the setter function could be called. Question: what should happen if the setter is missing.

Non-configurable properties: when the property is defined as data property, the setter is called. If the setter is not present, it is compared to the returned value of the getter. Even in non-configurable case, writable can be changed from true to false. Currently the setter is released in this case.
Option: changing writable could yield an error.

@zherczeg
Copy link
Member Author

Needed to implement this https://v8.dev/docs/stack-trace-api

@zherczeg
Copy link
Member Author

Depends on #4373

@@ -194,6 +194,9 @@ typedef struct
/** [[Configurable]] */
bool is_configurable;

/** Is data accessor property */
bool is_data_accessor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an API breaking change and should be documented.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants