Browse Source

Removed the usage of deprecated ioutil package. Bumped minimum Go version to 1.16.

Dmitry Panov 3 years ago
parent
commit
85e2e6106c
8 changed files with 20 additions and 19 deletions
  1. 1 1
      .github/workflows/main.yml
  2. 1 1
      README.md
  3. 3 3
      compiler_test.go
  4. 1 1
      go.mod
  5. 4 4
      goja/main.go
  6. 2 2
      parser/parser.go
  7. 2 2
      parser/statement.go
  8. 6 5
      tc39_test.go

+ 1 - 1
.github/workflows/main.yml

@@ -4,7 +4,7 @@ jobs:
   test:
   test:
     strategy:
     strategy:
       matrix:
       matrix:
-        go-version: [1.14.x, 1.x]
+        go-version: [1.16.x, 1.x]
         os: [ubuntu-latest]
         os: [ubuntu-latest]
         arch: ["", "386"]
         arch: ["", "386"]
       fail-fast: false
       fail-fast: false

+ 1 - 1
README.md

@@ -10,7 +10,7 @@ performance.
 
 
 This project was largely inspired by [otto](https://github.com/robertkrimen/otto).
 This project was largely inspired by [otto](https://github.com/robertkrimen/otto).
 
 
-Minimum required Go version is 1.14.
+Minimum required Go version is 1.16.
 
 
 Features
 Features
 --------
 --------

+ 3 - 3
compiler_test.go

@@ -1,7 +1,7 @@
 package goja
 package goja
 
 
 import (
 import (
-	"io/ioutil"
+	"os"
 	"sync"
 	"sync"
 	"testing"
 	"testing"
 )
 )
@@ -5550,7 +5550,7 @@ func TestThisResolutionWithStackVar(t *testing.T) {
 
 
 /*
 /*
 func TestBabel(t *testing.T) {
 func TestBabel(t *testing.T) {
-	src, err := ioutil.ReadFile("babel7.js")
+	src, err := os.ReadFile("babel7.js")
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -5566,7 +5566,7 @@ func TestBabel(t *testing.T) {
 }*/
 }*/
 
 
 func BenchmarkCompile(b *testing.B) {
 func BenchmarkCompile(b *testing.B) {
-	data, err := ioutil.ReadFile("testdata/S15.10.2.12_A1_T1.js")
+	data, err := os.ReadFile("testdata/S15.10.2.12_A1_T1.js")
 	if err != nil {
 	if err != nil {
 		b.Fatal(err)
 		b.Fatal(err)
 	}
 	}

+ 1 - 1
go.mod

@@ -1,6 +1,6 @@
 module github.com/dop251/goja
 module github.com/dop251/goja
 
 
-go 1.14
+go 1.16
 
 
 require (
 require (
 	github.com/dlclark/regexp2 v1.7.0
 	github.com/dlclark/regexp2 v1.7.0

+ 4 - 4
goja/main.go

@@ -5,7 +5,7 @@ import (
 	"encoding/binary"
 	"encoding/binary"
 	"flag"
 	"flag"
 	"fmt"
 	"fmt"
-	"io/ioutil"
+	"io"
 	"log"
 	"log"
 	"math/rand"
 	"math/rand"
 	"os"
 	"os"
@@ -23,9 +23,9 @@ var timelimit = flag.Int("timelimit", 0, "max time to run (in seconds)")
 
 
 func readSource(filename string) ([]byte, error) {
 func readSource(filename string) ([]byte, error) {
 	if filename == "" || filename == "-" {
 	if filename == "" || filename == "-" {
-		return ioutil.ReadAll(os.Stdin)
+		return io.ReadAll(os.Stdin)
 	}
 	}
-	return ioutil.ReadFile(filename)
+	return os.ReadFile(filename)
 }
 }
 
 
 func load(vm *goja.Runtime, call goja.FunctionCall) goja.Value {
 func load(vm *goja.Runtime, call goja.FunctionCall) goja.Value {
@@ -71,7 +71,7 @@ func run() error {
 	})
 	})
 
 
 	vm.Set("readFile", func(name string) (string, error) {
 	vm.Set("readFile", func(name string) (string, error) {
-		b, err := ioutil.ReadFile(name)
+		b, err := os.ReadFile(name)
 		if err != nil {
 		if err != nil {
 			return "", err
 			return "", err
 		}
 		}

+ 2 - 2
parser/parser.go

@@ -36,7 +36,7 @@ import (
 	"bytes"
 	"bytes"
 	"errors"
 	"errors"
 	"io"
 	"io"
-	"io/ioutil"
+	"os"
 
 
 	"github.com/dop251/goja/ast"
 	"github.com/dop251/goja/ast"
 	"github.com/dop251/goja/file"
 	"github.com/dop251/goja/file"
@@ -147,7 +147,7 @@ func ReadSource(filename string, src interface{}) ([]byte, error) {
 		}
 		}
 		return nil, errors.New("invalid source")
 		return nil, errors.New("invalid source")
 	}
 	}
-	return ioutil.ReadFile(filename)
+	return os.ReadFile(filename)
 }
 }
 
 
 // ParseFile parses the source code of a single JavaScript/ECMAScript source file and returns
 // ParseFile parses the source code of a single JavaScript/ECMAScript source file and returns

+ 2 - 2
parser/statement.go

@@ -3,7 +3,7 @@ package parser
 import (
 import (
 	"encoding/base64"
 	"encoding/base64"
 	"fmt"
 	"fmt"
-	"io/ioutil"
+	"os"
 	"strings"
 	"strings"
 
 
 	"github.com/dop251/goja/ast"
 	"github.com/dop251/goja/ast"
@@ -840,7 +840,7 @@ func (self *_parser) parseSourceMap() *sourcemap.Consumer {
 					data, err = self.opts.sourceMapLoader(sourceURL.String())
 					data, err = self.opts.sourceMapLoader(sourceURL.String())
 				} else {
 				} else {
 					if sourceURL.Scheme == "" || sourceURL.Scheme == "file" {
 					if sourceURL.Scheme == "" || sourceURL.Scheme == "file" {
-						data, err = ioutil.ReadFile(sourceURL.Path)
+						data, err = os.ReadFile(sourceURL.Path)
 					} else {
 					} else {
 						err = fmt.Errorf("unsupported source map URL scheme: %s", sourceURL.Scheme)
 						err = fmt.Errorf("unsupported source map URL scheme: %s", sourceURL.Scheme)
 					}
 					}

+ 6 - 5
tc39_test.go

@@ -3,8 +3,7 @@ package goja
 import (
 import (
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
-	"gopkg.in/yaml.v2"
-	"io/ioutil"
+	"io"
 	"os"
 	"os"
 	"path"
 	"path"
 	"sort"
 	"sort"
@@ -12,6 +11,8 @@ import (
 	"sync"
 	"sync"
 	"testing"
 	"testing"
 	"time"
 	"time"
+
+	"gopkg.in/yaml.v2"
 )
 )
 
 
 const (
 const (
@@ -412,7 +413,7 @@ func parseTC39File(name string) (*tc39Meta, string, error) {
 	}
 	}
 	defer f.Close()
 	defer f.Close()
 
 
-	b, err := ioutil.ReadAll(f)
+	b, err := io.ReadAll(f)
 	if err != nil {
 	if err != nil {
 		return nil, "", err
 		return nil, "", err
 	}
 	}
@@ -652,7 +653,7 @@ func (ctx *tc39TestCtx) compile(base, name string) (*Program, error) {
 		}
 		}
 		defer f.Close()
 		defer f.Close()
 
 
-		b, err := ioutil.ReadAll(f)
+		b, err := io.ReadAll(f)
 		if err != nil {
 		if err != nil {
 			return nil, err
 			return nil, err
 		}
 		}
@@ -710,7 +711,7 @@ func (ctx *tc39TestCtx) runTC39Script(name, src string, includes []string, vm *R
 }
 }
 
 
 func (ctx *tc39TestCtx) runTC39Tests(name string) {
 func (ctx *tc39TestCtx) runTC39Tests(name string) {
-	files, err := ioutil.ReadDir(path.Join(ctx.base, name))
+	files, err := os.ReadDir(path.Join(ctx.base, name))
 	if err != nil {
 	if err != nil {
 		ctx.t.Fatal(err)
 		ctx.t.Fatal(err)
 	}
 	}