You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Uncaught TypeError when calling method on global object #1987
It turns out that we have two bugs related to the global object:
When we initialize builtins, they are added to the Global environment record as bindings, not as properties of the global object, which means that this and globalThis are empty objects ({}).
The global object has no prototype. This is required by the spec, and as far as I can tell, it should probably be the Object prototype, since hasOwnProperty() and others are part of the Object prototype.
The first issue is relatively easy to fix: we can just insert properties in the global object when we initialize builtins. In theory, we should not create bindings for these, and the global environment should check if a variable is part of the global object or one of the global bindings, but removing the insertion into the global bindings breaks around 50k tests.
The second issue is trickier, since when the global object gets constructed, the Object built-in doesn't exist, so we cannot easily assign its prototype to it. I will publish a PR that solves the first issue, but the second one will need some extra thought.
When we initialize builtins, they are added to the Global environment record as bindings, not as properties of the global object, which means that this and globalThis are empty objects ({}).
The global object has no prototype. This is required by the spec, and as far as I can tell, it should probably be the Object prototype, since hasOwnProperty() and others are part of the Object prototype.
The way the global object currently works is, that it uses special internal object methods defiend in GLOBAL_INTERNAL_METHODS in boa_engine/src/object/internal_methods/global.rs. That way it can use the global environment bindings as properties. The implementation currently completeley ignores the objects prototype. The best example is global_has_property where only the global property map is checked while the spec suggests that the object's prototype should be checked if no property is found on the object itself.
I think the best way to fix this issue is to add a global_prototype field on the Realm (same principle as global_property_map and global_extensible). Then the internal methods for the global object must be adjusted to use this global prototype in the same way that ordinary internal methods use the objects prototype. Hopefully this can be implemented without impacting the performance of those methods.
Additionally the internal methods __get_prototype_of__, __set_prototype_of__ and __own_property_keys__ must be implemented for global object as they are currently taken from the ordinary methods.
While the spec currently does not define that the prototype of the global object should be Object.prototype, there is an open issue that attempts to make sure that it is somewhere in the prototype chain tc39/ecma262#1967.
Activity
Razican commentedon Aug 22, 2022
It turns out that we have two bugs related to the global object:
Globalenvironment record as bindings, not as properties of the global object, which means thatthisandglobalThisare empty objects ({}).Objectprototype, sincehasOwnProperty()and others are part of theObjectprototype.The first issue is relatively easy to fix: we can just insert properties in the global object when we initialize builtins. In theory, we should not create bindings for these, and the global environment should check if a variable is part of the global object or one of the global bindings, but removing the insertion into the global bindings breaks around 50k tests.
The second issue is trickier, since when the global object gets constructed, the
Objectbuilt-in doesn't exist, so we cannot easily assign its prototype to it. I will publish a PR that solves the first issue, but the second one will need some extra thought.raskad commentedon Aug 23, 2022
The way the global object currently works is, that it uses special internal object methods defiend in
GLOBAL_INTERNAL_METHODSinboa_engine/src/object/internal_methods/global.rs. That way it can use the global environment bindings as properties. The implementation currently completeley ignores the objects prototype. The best example isglobal_has_propertywhere only the global property map is checked while the spec suggests that the object's prototype should be checked if no property is found on the object itself.I think the best way to fix this issue is to add a
global_prototypefield on theRealm(same principle asglobal_property_mapandglobal_extensible). Then the internal methods for the global object must be adjusted to use this global prototype in the same way that ordinary internal methods use the objects prototype. Hopefully this can be implemented without impacting the performance of those methods.Additionally the internal methods
__get_prototype_of__,__set_prototype_of__and__own_property_keys__must be implemented for global object as they are currently taken from the ordinary methods.While the spec currently does not define that the prototype of the global object should be
Object.prototype, there is an open issue that attempts to make sure that it is somewhere in the prototype chain tc39/ecma262#1967.Add URI encoding and decoding functions (#2267)
Implement missing global object internal methods (#2287)