Skip to content

Commit f767225

Browse files
committed
Fix possible panic during internalization/externalization of time.Time/Date.
Fixes #279 (initial report). The internalization/externalization code only checks if the time package is present and assumes time.Unix and time.Time are available if so. Previously, it was possible for time package to be present, but either time.Unix or time.Time were not (due to dead code elimination), causing possible panics. In time package itself, ensure time.Unix func and time.Time struct it returns are always included (despite DCE) to prevent that from happening.
1 parent 3a4538f commit f767225

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compiler/natives/time/time.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
"github.com/gopherjs/gopherjs/js"
1010
)
1111

12+
// Make sure time.Unix func and time.Time struct it returns are always included with this package (despite DCE),
13+
// because they're needed for internalization/externalization of time.Time/Date. See issue https://github.com/gopherjs/gopherjs/issues/279.
14+
func init() {
15+
// avoid dead code elimination
16+
var _ Time = Unix(0, 0)
17+
}
18+
1219
type runtimeTimer struct {
1320
i int32
1421
when int64

0 commit comments

Comments
 (0)