-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't polyfill Temporal and Intl onto the global object
In order to avoid breaking the web when Temporal is shipped, don't polyfill onto the global object. We don't want any `if (typeof Temporal === undefined)` checks in the wild until browsers actually start shipping Temporal. We do still need it on the global object for the browser playground and the test262 tests, so we now have two separate entry points to the library: index.mjs and shim.mjs. Closes: #778
- Loading branch information
Showing
3 changed files
with
37 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,10 @@ | ||
// This entry point treats Temporal as a library, and does not polyfill it onto | ||
// the global object. | ||
// This is in order to avoid breaking the web in the future, if the polyfill | ||
// gains wide adoption before the API is finalized. We do not want checks such | ||
// as `if (typeof Temporal === 'undefined')` in the wild, until browsers start | ||
// shipping the finalized API. | ||
|
||
import * as Temporal from './temporal.mjs'; | ||
import * as Intl from './intl.mjs'; | ||
|
||
Object.defineProperty(globalThis, 'Temporal', { | ||
value: {}, | ||
writable: true, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
copy(globalThis.Temporal, Temporal); | ||
copy(globalThis.Intl, Intl); | ||
|
||
function copy(target, source) { | ||
for (const prop of Object.getOwnPropertyNames(source)) { | ||
Object.defineProperty(target, prop, { | ||
value: source[prop], | ||
writable: true, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
} | ||
} | ||
|
||
export { Temporal, Intl }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This is an alternate entry point that polyfills Temporal onto the global | ||
// object. This is used only for the browser playground and the test262 tests. | ||
// See the note in index.mjs. | ||
|
||
import * as Temporal from './temporal.mjs'; | ||
import * as Intl from './intl.mjs'; | ||
|
||
Object.defineProperty(globalThis, 'Temporal', { | ||
value: {}, | ||
writable: true, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
copy(globalThis.Temporal, Temporal); | ||
copy(globalThis.Intl, Intl); | ||
|
||
function copy(target, source) { | ||
for (const prop of Object.getOwnPropertyNames(source)) { | ||
Object.defineProperty(target, prop, { | ||
value: source[prop], | ||
writable: true, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
} | ||
} | ||
|
||
export { Temporal, Intl }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters