Skip to content

Commit

Permalink
Fixed ExportType() for Date objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Oct 19, 2021
1 parent d99e4b8 commit 00bb30d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions date.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package goja

import (
"math"
"reflect"
"time"
)

Expand Down Expand Up @@ -135,6 +136,10 @@ func (d *dateObject) toPrimitive() Value {
return d.toPrimitiveString()
}

func (d *dateObject) exportType() reflect.Type {
return typeTime
}

func (d *dateObject) export(*objectExportCtx) interface{} {
if d.isSet() {
return d.time()
Expand Down
11 changes: 11 additions & 0 deletions date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,14 @@ func TestDateToJSON(t *testing.T) {
`
testScript1(SCRIPT, intToValue(1), t)
}

func TestDateExportType(t *testing.T) {
vm := New()
v, err := vm.RunString(`new Date()`)
if err != nil {
t.Fatal(err)
}
if typ := v.ExportType(); typ != typeTime {
t.Fatal(typ)
}
}

0 comments on commit 00bb30d

Please sign in to comment.