From 71f657d5743287d34f09b3c68ba9dd67737ab71f Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Sun, 12 Sep 2021 17:25:15 +0300 Subject: [PATCH] Update goja to latest stable fixes #2131 and #2133 --- go.mod | 2 +- go.sum | 6 +- .../github.com/dop251/goja/compiler_expr.go | 2 +- vendor/github.com/dop251/goja/date.go | 95 ++++++++++++------- vendor/github.com/dop251/goja/date_parser.go | 9 +- .../github.com/dop251/goja/object_goslice.go | 2 +- .../dop251/goja/object_goslice_reflect.go | 4 +- vendor/modules.txt | 2 +- 8 files changed, 77 insertions(+), 45 deletions(-) diff --git a/go.mod b/go.mod index 81819d0416e..4abc7f6fde1 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/PuerkitoBio/goquery v1.6.1 github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5 github.com/andybalholm/brotli v1.0.3 - github.com/dop251/goja v0.0.0-20210817151038-07a7fd9355b4 + github.com/dop251/goja v0.0.0-20210912140721-ac5354e9a820 github.com/fatih/color v1.12.0 github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 // indirect github.com/golang/protobuf v1.4.3 diff --git a/go.sum b/go.sum index bd1d70e2eb4..62ebeb7e457 100644 --- a/go.sum +++ b/go.sum @@ -56,10 +56,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 h1:Izz0+t1Z5nI16/II7vuEo/nHjodOg0p7+OiDpjX5t1E= github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= -github.com/dop251/goja v0.0.0-20210810150349-acd0507c3d6f h1:mVrhVJhSSVE4RGV9PLwRsIQ1e6o0sGg0jim4Vj6OPs0= -github.com/dop251/goja v0.0.0-20210810150349-acd0507c3d6f/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= -github.com/dop251/goja v0.0.0-20210817151038-07a7fd9355b4 h1:c6+6EmiSboC79bkEtZGQhpeEWP1lzHuHpr1tPdISdYo= -github.com/dop251/goja v0.0.0-20210817151038-07a7fd9355b4/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= +github.com/dop251/goja v0.0.0-20210912140721-ac5354e9a820 h1:wZTJ4xyi5333660PqmXHwYqvDf/NkRcKKmNo+eHd7qw= +github.com/dop251/goja v0.0.0-20210912140721-ac5354e9a820/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= diff --git a/vendor/github.com/dop251/goja/compiler_expr.go b/vendor/github.com/dop251/goja/compiler_expr.go index 030e021c7c1..aca5940769f 100644 --- a/vendor/github.com/dop251/goja/compiler_expr.go +++ b/vendor/github.com/dop251/goja/compiler_expr.go @@ -1150,7 +1150,7 @@ func (e *compiledFunctionLiteral) emitGetter(putOnStack bool) { e.c.p.code[enterFunc2Mark] = ef2 } } - if emitArgsRestMark != -1 { + if emitArgsRestMark != -1 && s.argsInStash { e.c.p.code[emitArgsRestMark] = createArgsRestStash } } else { diff --git a/vendor/github.com/dop251/goja/date.go b/vendor/github.com/dop251/goja/date.go index 66ac80b5138..aa8ef62b1b4 100644 --- a/vendor/github.com/dop251/goja/date.go +++ b/vendor/github.com/dop251/goja/date.go @@ -24,51 +24,80 @@ type dateObject struct { msec int64 } +type dateLayoutDesc struct { + layout string + dateOnly bool +} + var ( - dateLayoutList = []string{ - "2006-01-02T15:04:05Z0700", - "2006-01-02T15:04:05", - "2006-01-02", - "2006-01-02 15:04:05", - time.RFC1123, - time.RFC1123Z, - dateTimeLayout, - time.UnixDate, - time.ANSIC, - time.RubyDate, - "Mon, 02 Jan 2006 15:04:05 GMT-0700 (MST)", - "Mon, 02 Jan 2006 15:04:05 -0700 (MST)", - - "2006", - "2006-01", - - "2006T15:04", - "2006-01T15:04", - "2006-01-02T15:04", - - "2006T15:04:05", - "2006-01T15:04:05", - - "2006T15:04Z0700", - "2006-01T15:04Z0700", - "2006-01-02T15:04Z0700", - - "2006T15:04:05Z0700", - "2006-01T15:04:05Z0700", + dateLayoutsNumeric = []dateLayoutDesc{ + {layout: "2006-01-02T15:04:05Z0700"}, + {layout: "2006-01-02T15:04:05"}, + {layout: "2006-01-02", dateOnly: true}, + {layout: "2006-01-02 15:04:05"}, + + {layout: "2006", dateOnly: true}, + {layout: "2006-01", dateOnly: true}, + + {layout: "2006T15:04"}, + {layout: "2006-01T15:04"}, + {layout: "2006-01-02T15:04"}, + + {layout: "2006T15:04:05"}, + {layout: "2006-01T15:04:05"}, + + {layout: "2006T15:04Z0700"}, + {layout: "2006-01T15:04Z0700"}, + {layout: "2006-01-02T15:04Z0700"}, + + {layout: "2006T15:04:05Z0700"}, + {layout: "2006-01T15:04:05Z0700"}, + } + + dateLayoutsAlpha = []dateLayoutDesc{ + {layout: time.RFC1123}, + {layout: time.RFC1123Z}, + {layout: dateTimeLayout}, + {layout: time.UnixDate}, + {layout: time.ANSIC}, + {layout: time.RubyDate}, + {layout: "Mon, _2 Jan 2006 15:04:05 GMT-0700 (MST)"}, + {layout: "Mon, _2 Jan 2006 15:04:05 -0700 (MST)"}, + {layout: "Jan _2, 2006", dateOnly: true}, } ) func dateParse(date string) (time.Time, bool) { var t time.Time var err error - for _, layout := range dateLayoutList { - t, err = parseDate(layout, date, time.UTC) + var layouts []dateLayoutDesc + if len(date) > 0 { + first := date[0] + if first <= '9' && (first >= '0' || first == '-' || first == '+') { + layouts = dateLayoutsNumeric + } else { + layouts = dateLayoutsAlpha + } + } else { + return time.Time{}, false + } + for _, desc := range layouts { + var defLoc *time.Location + if desc.dateOnly { + defLoc = time.UTC + } else { + defLoc = time.Local + } + t, err = parseDate(desc.layout, date, defLoc) if err == nil { break } } + if err != nil { + return time.Time{}, false + } unix := timeToMsec(t) - return t, err == nil && unix >= -maxTime && unix <= maxTime + return t, unix >= -maxTime && unix <= maxTime } func (r *Runtime) newDateObject(t time.Time, isSet bool, proto *Object) *Object { diff --git a/vendor/github.com/dop251/goja/date_parser.go b/vendor/github.com/dop251/goja/date_parser.go index 0841cf40e10..f8360532929 100644 --- a/vendor/github.com/dop251/goja/date_parser.go +++ b/vendor/github.com/dop251/goja/date_parser.go @@ -5,6 +5,8 @@ package goja // - 6-digit extended years are supported in place of long year (2006) in the form of +123456 // - Timezone formats tolerate colons, e.g. -0700 will parse -07:00 // - Short week day will also parse long week day +// - Short month ("Jan") will also parse long month ("January") +// - Long day ("02") will also parse short day ("2"). // - Timezone in brackets, "(MST)", will match any string in brackets (e.g. "(GMT Standard Time)") // - If offset is not set and timezone name is unknown, an error is returned // - If offset and timezone name are both set the offset takes precedence and the resulting Location will be FixedZone("", offset) @@ -133,7 +135,10 @@ func parseDate(layout, value string, defaultLocation *time.Location) (time.Time, } case stdMonth: - month, value, err = lookup(shortMonthNames, value) + month, value, err = lookup(longMonthNames, value) + if err != nil { + month, value, err = lookup(shortMonthNames, value) + } month++ case stdLongMonth: month, value, err = lookup(longMonthNames, value) @@ -155,7 +160,7 @@ func parseDate(layout, value string, defaultLocation *time.Location) (time.Time, if std == stdUnderDay && len(value) > 0 && value[0] == ' ' { value = value[1:] } - day, value, err = getnum(value, std == stdZeroDay) + day, value, err = getnum(value, false) if day < 0 { // Note that we allow any one- or two-digit day here. rangeErrString = "day" diff --git a/vendor/github.com/dop251/goja/object_goslice.go b/vendor/github.com/dop251/goja/object_goslice.go index 0c2b2322b31..47d392b957b 100644 --- a/vendor/github.com/dop251/goja/object_goslice.go +++ b/vendor/github.com/dop251/goja/object_goslice.go @@ -187,7 +187,7 @@ func (o *objectGoSlice) hasOwnPropertyStr(name unistring.String) bool { if idx := strToIdx64(name); idx >= 0 { return idx < int64(len(*o.data)) } - return false + return name == "length" } func (o *objectGoSlice) defineOwnPropertyIdx(idx valueInt, descr PropertyDescriptor, throw bool) bool { diff --git a/vendor/github.com/dop251/goja/object_goslice_reflect.go b/vendor/github.com/dop251/goja/object_goslice_reflect.go index 658c65f9b5e..9c9ea1f46a3 100644 --- a/vendor/github.com/dop251/goja/object_goslice_reflect.go +++ b/vendor/github.com/dop251/goja/object_goslice_reflect.go @@ -196,7 +196,7 @@ func (o *objectGoSliceReflect) setForeignIdx(idx valueInt, val, receiver Value, } func (o *objectGoSliceReflect) setForeignStr(name unistring.String, val, receiver Value, throw bool) (bool, bool) { - return o._setForeignStr(name, trueValIfPresent(o._hasStr(name)), val, receiver, throw) + return o._setForeignStr(name, trueValIfPresent(o.hasOwnPropertyStr(name)), val, receiver, throw) } func (o *objectGoSliceReflect) hasOwnPropertyIdx(idx valueInt) bool { @@ -204,7 +204,7 @@ func (o *objectGoSliceReflect) hasOwnPropertyIdx(idx valueInt) bool { } func (o *objectGoSliceReflect) hasOwnPropertyStr(name unistring.String) bool { - if o._hasStr(name) { + if o._hasStr(name) || name == "length" { return true } return o.objectGoReflect._has(name.String()) diff --git a/vendor/modules.txt b/vendor/modules.txt index 1b23402dd8a..67e40e20d9b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -20,7 +20,7 @@ github.com/davecgh/go-spew/spew # github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 github.com/dlclark/regexp2 github.com/dlclark/regexp2/syntax -# github.com/dop251/goja v0.0.0-20210817151038-07a7fd9355b4 +# github.com/dop251/goja v0.0.0-20210912140721-ac5354e9a820 ## explicit github.com/dop251/goja github.com/dop251/goja/ast