Pārlūkot izejas kodu

Ensure the argument coercion in Date setters happens before the check for the date being unset. Upgraded tc39 tests.

Dmitry Panov 3 gadi atpakaļ
vecāks
revīzija
3c02223f61
4 mainītis faili ar 81 papildinājumiem un 79 dzēšanām
  1. 3 1
      .tc39_test262_checkout.sh
  2. 1 1
      README.md
  3. 76 76
      builtin_date.go
  4. 1 1
      tc39_test.go

+ 3 - 1
.tc39_test262_checkout.sh

@@ -1,5 +1,7 @@
 #!/bin/sh
-sha=26f1f4567ee7e33163d961c867d689173cbb9065 # this is just the commit it was last tested with
+# this is just the commit it was last tested with
+sha=e87b0048c402479df1d9cb391fb86620cf3200fd
+
 mkdir -p testdata/test262
 cd testdata/test262
 git init

+ 1 - 1
README.md

@@ -17,7 +17,7 @@ Features
 
  * Full ECMAScript 5.1 support (including regex and strict mode).
  * Passes nearly all [tc39 tests](https://github.com/tc39/test262) for the features implemented so far. The goal is to
-   pass all of them. Note, the current working commit is https://github.com/tc39/test262/commit/26f1f4567ee7e33163d961c867d689173cbb9065.
+   pass all of them. See .tc39_test262_checkout.sh for the latest working commit id.
  * Capable of running Babel, Typescript compiler and pretty much anything written in ES5.
  * Sourcemaps.
  * Most of ES6 functionality, still work in progress, see https://github.com/dop251/goja/milestone/1?closed=1

+ 76 - 76
builtin_date.go

@@ -682,20 +682,20 @@ 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 {
+		n := call.Argument(0).ToNumber()
+		if IsNaN(n) {
+			d.unset()
+			return _NaN
+		}
+		msec := n.ToInteger()
+		sec := d.msec / 1e3
+		var ok bool
+		sec, msec, ok = _norm(sec, msec, 1e3)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			n := call.Argument(0).ToNumber()
-			if IsNaN(n) {
-				d.unset()
-				return _NaN
-			}
-			msec := n.ToInteger()
-			sec := d.msec / 1e3
-			var ok bool
-			sec, msec, ok = _norm(sec, msec, 1e3)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(sec*1e3 + msec)
 		} else {
 			return _NaN
@@ -707,20 +707,20 @@ func (r *Runtime) dateproto_setMilliseconds(call FunctionCall) Value {
 func (r *Runtime) dateproto_setUTCMilliseconds(call FunctionCall) Value {
 	obj := r.toObject(call.This)
 	if d, ok := obj.self.(*dateObject); ok {
+		n := call.Argument(0).ToNumber()
+		if IsNaN(n) {
+			d.unset()
+			return _NaN
+		}
+		msec := n.ToInteger()
+		sec := d.msec / 1e3
+		var ok bool
+		sec, msec, ok = _norm(sec, msec, 1e3)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			n := call.Argument(0).ToNumber()
-			if IsNaN(n) {
-				d.unset()
-				return _NaN
-			}
-			msec := n.ToInteger()
-			sec := d.msec / 1e3
-			var ok bool
-			sec, msec, ok = _norm(sec, msec, 1e3)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(sec*1e3 + msec)
 		} else {
 			return _NaN
@@ -732,12 +732,12 @@ func (r *Runtime) dateproto_setUTCMilliseconds(call FunctionCall) Value {
 func (r *Runtime) dateproto_setSeconds(call FunctionCall) Value {
 	obj := r.toObject(call.This)
 	if d, ok := obj.self.(*dateObject); ok {
+		t, ok := _dateSetFullYear(d.time(), call, -5, false)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			t, ok := _dateSetFullYear(d.time(), call, -5, false)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(timeToMsec(t))
 		} else {
 			return _NaN
@@ -749,12 +749,12 @@ func (r *Runtime) dateproto_setSeconds(call FunctionCall) Value {
 func (r *Runtime) dateproto_setUTCSeconds(call FunctionCall) Value {
 	obj := r.toObject(call.This)
 	if d, ok := obj.self.(*dateObject); ok {
+		t, ok := _dateSetFullYear(d.timeUTC(), call, -5, true)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			t, ok := _dateSetFullYear(d.timeUTC(), call, -5, true)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(timeToMsec(t))
 		} else {
 			return _NaN
@@ -766,12 +766,12 @@ func (r *Runtime) dateproto_setUTCSeconds(call FunctionCall) Value {
 func (r *Runtime) dateproto_setMinutes(call FunctionCall) Value {
 	obj := r.toObject(call.This)
 	if d, ok := obj.self.(*dateObject); ok {
+		t, ok := _dateSetFullYear(d.time(), call, -4, false)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			t, ok := _dateSetFullYear(d.time(), call, -4, false)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(timeToMsec(t))
 		} else {
 			return _NaN
@@ -783,12 +783,12 @@ func (r *Runtime) dateproto_setMinutes(call FunctionCall) Value {
 func (r *Runtime) dateproto_setUTCMinutes(call FunctionCall) Value {
 	obj := r.toObject(call.This)
 	if d, ok := obj.self.(*dateObject); ok {
+		t, ok := _dateSetFullYear(d.timeUTC(), call, -4, true)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			t, ok := _dateSetFullYear(d.timeUTC(), call, -4, true)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(timeToMsec(t))
 		} else {
 			return _NaN
@@ -800,12 +800,12 @@ func (r *Runtime) dateproto_setUTCMinutes(call FunctionCall) Value {
 func (r *Runtime) dateproto_setHours(call FunctionCall) Value {
 	obj := r.toObject(call.This)
 	if d, ok := obj.self.(*dateObject); ok {
+		t, ok := _dateSetFullYear(d.time(), call, -3, false)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			t, ok := _dateSetFullYear(d.time(), call, -3, false)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(timeToMsec(t))
 		} else {
 			return _NaN
@@ -817,12 +817,12 @@ func (r *Runtime) dateproto_setHours(call FunctionCall) Value {
 func (r *Runtime) dateproto_setUTCHours(call FunctionCall) Value {
 	obj := r.toObject(call.This)
 	if d, ok := obj.self.(*dateObject); ok {
+		t, ok := _dateSetFullYear(d.timeUTC(), call, -3, true)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			t, ok := _dateSetFullYear(d.timeUTC(), call, -3, true)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(timeToMsec(t))
 		} else {
 			return _NaN
@@ -834,12 +834,12 @@ func (r *Runtime) dateproto_setUTCHours(call FunctionCall) Value {
 func (r *Runtime) dateproto_setDate(call FunctionCall) Value {
 	obj := r.toObject(call.This)
 	if d, ok := obj.self.(*dateObject); ok {
+		t, ok := _dateSetFullYear(d.time(), limitCallArgs(call, 1), -2, false)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			t, ok := _dateSetFullYear(d.time(), limitCallArgs(call, 1), -2, false)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(timeToMsec(t))
 		} else {
 			return _NaN
@@ -851,12 +851,12 @@ func (r *Runtime) dateproto_setDate(call FunctionCall) Value {
 func (r *Runtime) dateproto_setUTCDate(call FunctionCall) Value {
 	obj := r.toObject(call.This)
 	if d, ok := obj.self.(*dateObject); ok {
+		t, ok := _dateSetFullYear(d.timeUTC(), limitCallArgs(call, 1), -2, true)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			t, ok := _dateSetFullYear(d.timeUTC(), limitCallArgs(call, 1), -2, true)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(timeToMsec(t))
 		} else {
 			return _NaN
@@ -868,12 +868,12 @@ func (r *Runtime) dateproto_setUTCDate(call FunctionCall) Value {
 func (r *Runtime) dateproto_setMonth(call FunctionCall) Value {
 	obj := r.toObject(call.This)
 	if d, ok := obj.self.(*dateObject); ok {
+		t, ok := _dateSetFullYear(d.time(), limitCallArgs(call, 2), -1, false)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			t, ok := _dateSetFullYear(d.time(), limitCallArgs(call, 2), -1, false)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(timeToMsec(t))
 		} else {
 			return _NaN
@@ -885,12 +885,12 @@ func (r *Runtime) dateproto_setMonth(call FunctionCall) Value {
 func (r *Runtime) dateproto_setUTCMonth(call FunctionCall) Value {
 	obj := r.toObject(call.This)
 	if d, ok := obj.self.(*dateObject); ok {
+		t, ok := _dateSetFullYear(d.timeUTC(), limitCallArgs(call, 2), -1, true)
+		if !ok {
+			d.unset()
+			return _NaN
+		}
 		if d.isSet() {
-			t, ok := _dateSetFullYear(d.timeUTC(), limitCallArgs(call, 2), -1, true)
-			if !ok {
-				d.unset()
-				return _NaN
-			}
 			return d.setTimeMs(timeToMsec(t))
 		} else {
 			return _NaN

+ 1 - 1
tc39_test.go

@@ -727,7 +727,7 @@ func TestTC39(t *testing.T) {
 	}
 
 	if _, err := os.Stat(tc39BASE); err != nil {
-		t.Skipf("If you want to run tc39 tests, download them from https://github.com/tc39/test262 and put into %s. The current working commit is ddfe24afe3043388827aa220ef623b8540958bbd. (%v)", tc39BASE, err)
+		t.Skipf("If you want to run tc39 tests, download them from https://github.com/tc39/test262 and put into %s. See .tc39_test262_checkout.sh for the latest working commit id. (%v)", tc39BASE, err)
 	}
 
 	ctx := &tc39TestCtx{