Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .tc39_test262_checkout.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh -e
# this is just the commit it was last tested with
sha=cb4a6c8074671c00df8cbc17a620c0f9462b312a
sha=3af36bec45bd4f72d4b57366653578e1e4dafef7

mkdir -p testdata/test262
cd testdata/test262
Expand Down
84 changes: 42 additions & 42 deletions builtin_date.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,219 +684,219 @@ func _dateSetMilliseconds(year, mon, day, hours, min, sec int64, t time.Time, ca
func (r *Runtime) dateproto_setMilliseconds(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
n := call.Argument(0).ToNumber()
if tv == timeUnset {
return _NaN
}
if IsNaN(n) {
d.unset()
return _NaN
}
msec := n.ToInteger()
sec := d.msec / 1e3
sec := tv / 1e3
var ok bool
sec, msec, ok = _norm(sec, msec, 1e3)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(sec*1e3 + msec)
} else {
return _NaN
}
return d.setTimeMs(sec*1e3 + msec)
}
panic(r.NewTypeError("Method Date.prototype.setMilliseconds is called on incompatible receiver"))
}

func (r *Runtime) dateproto_setUTCMilliseconds(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
n := call.Argument(0).ToNumber()
if tv == timeUnset {
return _NaN
}
if IsNaN(n) {
d.unset()
return _NaN
}
msec := n.ToInteger()
sec := d.msec / 1e3
sec := tv / 1e3
var ok bool
sec, msec, ok = _norm(sec, msec, 1e3)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(sec*1e3 + msec)
} else {
return _NaN
}
return d.setTimeMs(sec*1e3 + msec)
}
panic(r.NewTypeError("Method Date.prototype.setUTCMilliseconds is called on incompatible receiver"))
}

func (r *Runtime) dateproto_setSeconds(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
t, ok := _dateSetFullYear(d.time(), call, -5, false)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(timeToMsec(t))
} else {
if tv == timeUnset {
return _NaN
}
return d.setTimeMs(timeToMsec(t))
}
panic(r.NewTypeError("Method Date.prototype.setSeconds is called on incompatible receiver"))
}

func (r *Runtime) dateproto_setUTCSeconds(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
t, ok := _dateSetFullYear(d.timeUTC(), call, -5, true)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(timeToMsec(t))
} else {
if tv == timeUnset {
return _NaN
}
return d.setTimeMs(timeToMsec(t))
}
panic(r.NewTypeError("Method Date.prototype.setUTCSeconds is called on incompatible receiver"))
}

func (r *Runtime) dateproto_setMinutes(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
t, ok := _dateSetFullYear(d.time(), call, -4, false)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(timeToMsec(t))
} else {
if tv == timeUnset {
return _NaN
}
return d.setTimeMs(timeToMsec(t))
}
panic(r.NewTypeError("Method Date.prototype.setMinutes is called on incompatible receiver"))
}

func (r *Runtime) dateproto_setUTCMinutes(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
t, ok := _dateSetFullYear(d.timeUTC(), call, -4, true)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(timeToMsec(t))
} else {
if tv == timeUnset {
return _NaN
}
return d.setTimeMs(timeToMsec(t))
}
panic(r.NewTypeError("Method Date.prototype.setUTCMinutes is called on incompatible receiver"))
}

func (r *Runtime) dateproto_setHours(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
t, ok := _dateSetFullYear(d.time(), call, -3, false)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(timeToMsec(t))
} else {
if tv == timeUnset {
return _NaN
}
return d.setTimeMs(timeToMsec(t))
}
panic(r.NewTypeError("Method Date.prototype.setHours is called on incompatible receiver"))
}

func (r *Runtime) dateproto_setUTCHours(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
t, ok := _dateSetFullYear(d.timeUTC(), call, -3, true)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(timeToMsec(t))
} else {
if tv == timeUnset {
return _NaN
}
return d.setTimeMs(timeToMsec(t))
}
panic(r.NewTypeError("Method Date.prototype.setUTCHours is called on incompatible receiver"))
}

func (r *Runtime) dateproto_setDate(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
t, ok := _dateSetFullYear(d.time(), limitCallArgs(call, 1), -2, false)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(timeToMsec(t))
} else {
if tv == timeUnset {
return _NaN
}
return d.setTimeMs(timeToMsec(t))
}
panic(r.NewTypeError("Method Date.prototype.setDate is called on incompatible receiver"))
}

func (r *Runtime) dateproto_setUTCDate(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
t, ok := _dateSetFullYear(d.timeUTC(), limitCallArgs(call, 1), -2, true)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(timeToMsec(t))
} else {
if tv == timeUnset {
return _NaN
}
return d.setTimeMs(timeToMsec(t))
}
panic(r.NewTypeError("Method Date.prototype.setUTCDate is called on incompatible receiver"))
}

func (r *Runtime) dateproto_setMonth(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
t, ok := _dateSetFullYear(d.time(), limitCallArgs(call, 2), -1, false)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(timeToMsec(t))
} else {
if tv == timeUnset {
return _NaN
}
return d.setTimeMs(timeToMsec(t))
}
panic(r.NewTypeError("Method Date.prototype.setMonth is called on incompatible receiver"))
}

func (r *Runtime) dateproto_setUTCMonth(call FunctionCall) Value {
obj := r.toObject(call.This)
if d, ok := obj.self.(*dateObject); ok {
tv := d.msec
t, ok := _dateSetFullYear(d.timeUTC(), limitCallArgs(call, 2), -1, true)
if !ok {
d.unset()
return _NaN
}
if d.isSet() {
return d.setTimeMs(timeToMsec(t))
} else {
if tv == timeUnset {
return _NaN
}
return d.setTimeMs(timeToMsec(t))
}
panic(r.NewTypeError("Method Date.prototype.setUTCMonth is called on incompatible receiver"))
}
Expand Down
32 changes: 14 additions & 18 deletions builtin_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (r *Runtime) stringproto_localeCompare(call FunctionCall) Value {
func (r *Runtime) stringproto_match(call FunctionCall) Value {
r.checkObjectCoercible(call.This)
regexp := call.Argument(0)
if regexp != _undefined && regexp != _null {
if _, ok := regexp.(*Object); ok {
if matcher := toMethod(r.getV(regexp, SymMatch)); matcher != nil {
return matcher(FunctionCall{
This: regexp,
Expand Down Expand Up @@ -412,14 +412,12 @@ func (r *Runtime) stringproto_match(call FunctionCall) Value {
func (r *Runtime) stringproto_matchAll(call FunctionCall) Value {
r.checkObjectCoercible(call.This)
regexp := call.Argument(0)
if regexp != _undefined && regexp != _null {
if o, ok := regexp.(*Object); ok {
if isRegexp(regexp) {
if o, ok := regexp.(*Object); ok {
flags := nilSafe(o.self.getStr("flags", nil))
r.checkObjectCoercible(flags)
if !strings.Contains(flags.toString().String(), "g") {
panic(r.NewTypeError("RegExp doesn't have global flag set"))
}
flags := nilSafe(o.self.getStr("flags", nil))
r.checkObjectCoercible(flags)
if !strings.Contains(flags.toString().String(), "g") {
panic(r.NewTypeError("RegExp doesn't have global flag set"))
}
}
if matcher := toMethod(r.getV(regexp, SymMatchAll)); matcher != nil {
Expand Down Expand Up @@ -664,7 +662,7 @@ func (r *Runtime) stringproto_replace(call FunctionCall) Value {
r.checkObjectCoercible(call.This)
searchValue := call.Argument(0)
replaceValue := call.Argument(1)
if searchValue != _undefined && searchValue != _null {
if _, ok := searchValue.(*Object); ok {
if replacer := toMethod(r.getV(searchValue, SymReplace)); replacer != nil {
return replacer(FunctionCall{
This: searchValue,
Expand All @@ -689,14 +687,12 @@ func (r *Runtime) stringproto_replaceAll(call FunctionCall) Value {
r.checkObjectCoercible(call.This)
searchValue := call.Argument(0)
replaceValue := call.Argument(1)
if searchValue != _undefined && searchValue != _null {
if o, ok := searchValue.(*Object); ok {
if isRegexp(searchValue) {
if o, ok := searchValue.(*Object); ok {
flags := nilSafe(o.self.getStr("flags", nil))
r.checkObjectCoercible(flags)
if !strings.Contains(flags.toString().String(), "g") {
panic(r.NewTypeError("String.prototype.replaceAll called with a non-global RegExp argument"))
}
flags := nilSafe(o.self.getStr("flags", nil))
r.checkObjectCoercible(flags)
if !strings.Contains(flags.toString().String(), "g") {
panic(r.NewTypeError("String.prototype.replaceAll called with a non-global RegExp argument"))
}
}
if replacer := toMethod(r.getV(searchValue, SymReplace)); replacer != nil {
Expand Down Expand Up @@ -726,7 +722,7 @@ func (r *Runtime) stringproto_replaceAll(call FunctionCall) Value {
func (r *Runtime) stringproto_search(call FunctionCall) Value {
r.checkObjectCoercible(call.This)
regexp := call.Argument(0)
if regexp != _undefined && regexp != _null {
if _, ok := regexp.(*Object); ok {
if searcher := toMethod(r.getV(regexp, SymSearch)); searcher != nil {
return searcher(FunctionCall{
This: regexp,
Expand Down Expand Up @@ -799,7 +795,7 @@ func (r *Runtime) stringproto_split(call FunctionCall) Value {
r.checkObjectCoercible(call.This)
separatorValue := call.Argument(0)
limitValue := call.Argument(1)
if separatorValue != _undefined && separatorValue != _null {
if _, ok := separatorValue.(*Object); ok {
if splitter := toMethod(r.getV(separatorValue, SymSplit)); splitter != nil {
return splitter(FunctionCall{
This: separatorValue,
Expand Down
Loading
Loading