Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

runtime - class inheritance pattern not compatible with frozen intrinsics #410

@kumavis

Description

@kumavis

it is becoming increasingly common to freeze javascript intrinsics (Object, Array...) (see nodejs, endo/ses, xs)

while this is generally not an issue for packages that do not extend intrinsics, there are a few unfortunate side effects due to javascript's "override mistake", namely obj.constructor = ... fails due to the inherited property "constructor" being read-only on Object.prototype

here is the inheritance pattern at fault

GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
GeneratorFunctionPrototype.constructor = GeneratorFunction;

here is a compatible inheritance pattern
https://github.com/isaacs/inherits/blob/9a2c29400c6d491e0b7beefe0c32efa3b462545d/inherits_browser.js#L6-L13
alternatively you can just use defineProperty instead of assignment

reproduction steps:

Object.freeze(Object.prototype)
require('./runtime.js')

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