ES5 class rewriting incompatible with frozen intrinsics
See original GitHub issueBug Report
When TSC targets ES5, classes that extend other classes generate JS that throws a Cannot assign to read only property 'constructor' of object
TypeError when the intrinsics, particularly the Function.prototype
, are frozen. This affects programs that are freezing their intrinsics to protect against supply chain attacks, particularly using SES.
🔎 Search Terms
- constructor
- frozen
🕗 Version & Regression Information
I identified this issue in the published code of external-editor
3.1.0, which is using TypeScript 3.5.2 https://github.com/mrkmg/node-external-editor/blob/e1070a8295b8ebbafa7b29802ae0e2da0fad47c0/tsconfig.json
In the playground, the output is consistent for the very oldest and very newest versions of TypeScript when targeting ES5.
⏯ Playground Link
Playground link with relevant code
💻 Code
Object.freeze(Function);
Object.freeze(Function.prototype);
class Foo {
constructor() {
}
}
class Bar extends Foo {
constructor() {
}
}
🙁 Actual behavior
This code throws an exception like:
TypeError: Cannot assign to read only property 'constructor' of object ''
🙂 Expected behavior
This should not throw an exception. This can be achieved by using Object.defineProperty(prototype, 'constructor', {value: constructor})
instead of prototype.constructor = constructor
. This is a symptom of the so-called property override mistake, in the design of ES5.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (4 by maintainers)
Top GitHub Comments
Would it work if the ES3 and ES5 helpers were identical:
@rbuckton should this
be