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

The properties of the builtins are only enumerable after their first usage #152

Closed
renatahodovan opened this issue Jun 4, 2015 · 7 comments
Labels
bug Undesired behaviour ecma builtins Related to ECMA built-in routines

Comments

@renatahodovan
Copy link
Contributor

Jerry version:
Checked revision: 9d423d9
Build: debug.linux
OS:
Ubuntu 14.04, x86_64
Description:

Asking for the properties of any builtin objects results in a list, that only contains the previously used property names.
E.g:

var propertyNames = Object.getOwnPropertyNames(Math);
print(propertyNames.join(", "));

results an empty list. However:

var propertyNames = Object.getOwnPropertyNames(Object);
print(propertyNames.join(", "));

gives a list with only the "getOwnPropertyNames" property, since it was used already.

@egavrin egavrin added the bug Undesired behaviour label Jun 5, 2015
@egavrin egavrin added this to the ECMA builtins milestone Jun 5, 2015
@egavrin egavrin added the ecma builtins Related to ECMA built-in routines label Jun 5, 2015
@galpeter
Copy link
Contributor

@ruben-ayrapetyan, @egavrin I've created a proof-of-concept patch to see how could we initialize the properties, please see commit on the https://github.com/galpeter/jerryscript/commits/builtin_init branch. What do you think about it?

One thing I currently see that if we initialize all properties for a given built-in then we can remove the _try_to_instantiate_property method. which is currently not removed in the branch.

@ruben-ayrapetyan
Copy link
Contributor

@galpeter, could you, please, clarify would properties of built-ins that are not accessed during execution of a script, be initialized if the changes are applied?

@galpeter
Copy link
Contributor

@ruben-ayrapetyan, this would initialize all builtins as once you access the global object (with ecma_builtin_get) all builtins which are there are initialized, and also the properties of those builtins.

The code works that it would only initialize the given (ecma_instantiate_builtin function argument) builtin's properties and the builtin prototype's properties (and it's prototype's properties, etc..). For example if I do a print(Math) it would initialize it's funcion/value properties but also the Function Prototype builtin as it is required to create properties which have a function value (this is done by the function call ecma_builtin_make_function_object_for_routine)

@ruben-ayrapetyan
Copy link
Contributor

@galpeter, currently used version initializes a built-in's property only upon access to the property.

Could we implement enumeration without removing the lazy instantiation? Maybe, we could add special ecma_op_object_get_own_property_names for enumerating the names, without instantiating a built-in's properties until they are not not actually accessed.

What do you think about this?

@galpeter
Copy link
Contributor

@ruben-ayrapetyan currently the in the property list, which is returned by the ecma_get_property_list call, not all properties are there for built-ins. If we introduce a special function I'm afraid it could give us headache later on. If we introduce a special call we would need to have a list of all builtin property names somewhere, but then if we instantiate all properties for a builtin there is no need for such list as the property linked list will have all the names, thus we end up with the same information twice in the memory.

In short the approach could help, but it could also be that it just gives more code/memory usage in the end.

@ruben-ayrapetyan
Copy link
Contributor

@galpeter, names of properties for each built-in are already stored in memory (ecma_builtin_property_names static arrays).
Also, maybe, there is very limited number of points, were we really need the whole list of properties' names (not necessary instantiation of the properties).

Contrariwise, disabling lazy instantiation of built-in's properties increases memory usage.

@egavrin
Copy link
Contributor

egavrin commented Nov 19, 2015

var propertyNames = Object.getOwnPropertyNames(Math);
print(propertyNames.join(", "));
tan, sqrt, sin, round, random, pow, min, max, log, floor, exp, cos, ceil, atan2, atan, asin, acos, abs, SQRT2, SQRT1_2, PI, LOG10E, LOG2E, LN2, LN10, E

Works on master, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Undesired behaviour ecma builtins Related to ECMA built-in routines
Projects
None yet
Development

No branches or pull requests

4 participants