all: replace uses of ioutil with io and os (#24869)

This commit is contained in:
Håvard Anda Estensen
2022-05-16 11:59:35 +02:00
committed by GitHub
parent 330e53fbb9
commit 07508ac0e9
97 changed files with 203 additions and 257 deletions
+3 -3
View File
@@ -23,8 +23,8 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"time"
"github.com/dop251/goja"
@@ -254,7 +254,7 @@ func (re *JSRE) Stop(waitForCallbacks bool) {
// Exec(file) loads and runs the contents of a file
// if a relative path is given, the jsre's assetPath is used
func (re *JSRE) Exec(file string) error {
code, err := ioutil.ReadFile(common.AbsolutePath(re.assetPath, file))
code, err := os.ReadFile(common.AbsolutePath(re.assetPath, file))
if err != nil {
return err
}
@@ -320,7 +320,7 @@ func (re *JSRE) Compile(filename string, src string) (err error) {
func (re *JSRE) loadScript(call Call) (goja.Value, error) {
file := call.Argument(0).ToString().String()
file = common.AbsolutePath(re.assetPath, file)
source, err := ioutil.ReadFile(file)
source, err := os.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("Could not read file %s: %v", file, err)
}
+1 -2
View File
@@ -17,7 +17,6 @@
package jsre
import (
"io/ioutil"
"os"
"path"
"reflect"
@@ -43,7 +42,7 @@ func (no *testNativeObjectBinding) TestMethod(call goja.FunctionCall) goja.Value
func newWithTestJS(t *testing.T, testjs string) *JSRE {
dir := t.TempDir()
if testjs != "" {
if err := ioutil.WriteFile(path.Join(dir, "test.js"), []byte(testjs), os.ModePerm); err != nil {
if err := os.WriteFile(path.Join(dir, "test.js"), []byte(testjs), os.ModePerm); err != nil {
t.Fatal("cannot create test.js:", err)
}
}