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
prototype
property of Temporal types should not be writable
#1965
Comments
|
I can't speak to the Intl ones, but I would expect the 262 ones to all use the same property descriptor. If the Temporal spec somehow says something different, it should be fixed - a function's prototype property shouldn't be changeable. |
altho actually now that I check, a userland function does have a writable prototype property ( In a polyfill, if |
Meeting 2021-12-09:
|
prototype
?prototype
property of Temporal types should not be writable
Turns out the problem isn't with the core polyfill. It's a problem with the wrapper code used to load the polyfill into the Test262 tests (it also affects the docs where you can run Temporal code in the browser console). The core polyfill code correctly sets |
I dug into this more, and it turns out that Test262 isn't affected either, because the polyfill code run by Test262 is not transpiled . The root cause is how Babel transpiles the ES // Babel transpiles `class` into simple functions
var babelClass = function Foo() {};
Object.getOwnPropertyDescriptor(babelClass, 'prototype').writable;
// => true
var es6Class = class Bar {};
Object.getOwnPropertyDescriptor(es6Class, 'prototype').writable;
// => false Babel issue (open since 2015): babel/babel#2025 For the non-prod polyfill in the browser playground it's relatively straightforward to work around this in the wrapper code that loads the polyfill into the playground. For prod pollyfills, we may need to figure out a more general solution, or only transpile to ES6+, or perhaps just live with it. Given above, is it still worth adding Test262 tests to verify that the prototype's descriptor is |
test262 should certainly be verifying it, otherwise browsers etc might implement it wrong. |
Looks like there's been a lot of progress on this PR today. Thanks @nicolo-ribaudo and @ljharb! |
This PR fixes tc39#1965: 1. For Intl.DateTimeFormat, sets `writeable: false` on `prototype` because it's created using `function` (which has a writeable `prototype`, unlike `class` which is not writeable). 2. For Temporal classes, there's a Babel bug that causes prototypes to be writeable (babel/babel#2025) and this PR works around it.
I just pushed #1974 to fix this issue. Note that the polyfill's Intl.DateTimeFormat implementation had a writeable prototype regardless of Babel or not; it's also fixed in the same PR. |
This PR fixes tc39#1965: 1. For Intl.DateTimeFormat, sets `writeable: false` on `prototype` because it's created using `function` (which has a writeable `prototype`, unlike `class` which is not writeable). 2. For Temporal classes, there's a Babel bug that causes prototypes to be writeable (babel/babel#2025) and this PR works around it.
This PR fixes #1965: 1. For Intl.DateTimeFormat, sets `writeable: false` on `prototype` because it's created using `function` (which has a writeable `prototype`, unlike `class` which is not writeable). 2. For Temporal classes, there's a Babel bug that causes prototypes to be writeable (babel/babel#2025) and this PR works around it.
Question about monkeypatching: do we allow users to use
setPrototypeOf
on Temporal objects to replace the entire prototype of our of our types? And, if so, then when internal methods create new Temporal instances, then is it expected that we'd be using the original prototype object or the user's monkeypatched prototype object? The polyfill currently does not disallow usingsetPrototypeOf
, FWIW.I'm asking because I was looking at this code in the polyfill and was wondering if it should instead be using the original prototype from GetIntrinsic or not:
proposal-temporal/polyfill/lib/ecmascript.mjs
Lines 1418 to 1420 in f2405e1
Should this code actually be this?
The text was updated successfully, but these errors were encountered: