Skip to content

returnlessSource in decode.ts contains a victim of the JS override mistake #101

Open
@FUDCo

Description

@FUDCo

Note: I have filed a PR (#100) with two one-line fixes that addresses this. This issue is for tracking and hopefully so that somebody notices.

The function returnlessSource attempts to remove the return property from iterators, by assigning undefined to the property in question. Due to the JavaScript "override mistake" (a notorious problem in the language spec dating back almost two decades that has resisted correction due to concerns about hypothetical backwards compatibility issues with older websites), this assignment fails with a TypeError if the code is running in a locked down environment (such as, in my case, Hardened JavaScript) in which the primordial objects are frozen. The fix is to use Object.defineProperty in place of direct assignment.

To quote the Google:

The "override mistake" in JavaScript refers to an unexpected behavior that occurs when attempting to assign a value to a property in an object, where a read-only property with the same name exists higher up in the prototype chain. Instead of shadowing the prototype property as one might expect, the assignment is prevented, and in strict mode, it throws a TypeError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions