|
@@ -2,6 +2,7 @@ package goja
|
|
|
|
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
|
+ "errors"
|
|
"strings"
|
|
"strings"
|
|
"testing"
|
|
"testing"
|
|
"time"
|
|
"time"
|
|
@@ -78,6 +79,24 @@ func TestEOFWrapping(t *testing.T) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+type testMarshalJSONErrorStruct struct {
|
|
|
|
+ e error
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *testMarshalJSONErrorStruct) MarshalJSON() ([]byte, error) {
|
|
|
|
+ return nil, s.e
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestMarshalJSONError(t *testing.T) {
|
|
|
|
+ vm := New()
|
|
|
|
+ v := testMarshalJSONErrorStruct{e: errors.New("test error")}
|
|
|
|
+ vm.Set("v", &v)
|
|
|
|
+ _, err := vm.RunString("JSON.stringify(v)")
|
|
|
|
+ if !errors.Is(err, v.e) {
|
|
|
|
+ t.Fatalf("Unexpected error: %v", err)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
func BenchmarkJSONStringify(b *testing.B) {
|
|
func BenchmarkJSONStringify(b *testing.B) {
|
|
b.StopTimer()
|
|
b.StopTimer()
|
|
vm := New()
|
|
vm := New()
|