File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 8383 ]
8484 },
8585 "browser" : {
86+ "vm" : false ,
8687 "node:timers" : false ,
8788 "node:timers/promises" : false ,
8889 "timers" : false ,
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ const vm = require ( "vm" ) ;
4+ const { FakeTimers, assert, refute } = require ( "./helpers/setup-tests" ) ;
5+
6+ describe ( "issue #561 - cross-realm Date passed to setSystemTime" , function ( ) {
7+ let clock ;
8+
9+ before ( function ( ) {
10+ if ( typeof vm . runInNewContext !== "function" ) {
11+ this . skip ( ) ;
12+ }
13+ } ) ;
14+
15+ afterEach ( function ( ) {
16+ if ( clock ) {
17+ clock . uninstall ( ) ;
18+ clock = undefined ;
19+ }
20+ } ) ;
21+
22+ it ( "accepts a Date from another realm" , function ( ) {
23+ clock = FakeTimers . install ( ) ;
24+ const crossRealmDate = vm . runInNewContext (
25+ "new Date('2026-04-02T00:00:00.000Z')" ,
26+ ) ;
27+
28+ refute . exception ( function ( ) {
29+ clock . setSystemTime ( crossRealmDate ) ;
30+ } ) ;
31+
32+ assert . same ( clock . now , crossRealmDate . getTime ( ) ) ;
33+ assert . same ( new Date ( ) . getTime ( ) , crossRealmDate . getTime ( ) ) ;
34+ } ) ;
35+ } ) ;
You can’t perform that action at this time.
0 commit comments