Skip to content

Commit

Permalink
Goja async await (#2830)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov authored Jan 9, 2023
1 parent 8ebf51f commit 8418147
Show file tree
Hide file tree
Showing 35 changed files with 1,499 additions and 578 deletions.
2 changes: 1 addition & 1 deletion cmd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ func TestAbortedByScriptSetupErrorWithDependency(t *testing.T) {
rootPath += "c:/"
}
assert.Contains(t, stdOut, `level=error msg="Error: baz\n\tat baz (`+rootPath+`test/bar.js:6:9(3))\n\tat `+
rootPath+`test/bar.js:3:3(3)\n\tat setup (`+rootPath+`test/test.js:5:3(9))\n\tat native\n" hint="script exception"`)
rootPath+`test/bar.js:3:3(3)\n\tat setup (`+rootPath+`test/test.js:5:3(9))\n" hint="script exception"`)
assert.Contains(t, stdOut, `level=debug msg="Sending test finished" output=cloud ref=111 run_status=7 tainted=false`)
assert.Contains(t, stdOut, "bogus summary")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration_tests/eventloop/eventloop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export default function() {
}
require.Equal(t, []string{
"setTimeout 1 was stopped because the VU iteration was interrupted",
"just error\n\tat /script.js:13:4(15)\n\tat native\n", "1",
"just error\n\tat /script.js:13:4(15)\n", "1",
}, msgs)
})
}
4 changes: 2 additions & 2 deletions core/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ func TestSetupException(t *testing.T) {
var exception errext.Exception
require.ErrorAs(t, err, &exception)
require.Equal(t, "Error: baz\n\tat baz (file:///bar.js:6:16(3))\n"+
"\tat file:///bar.js:3:8(3)\n\tat setup (file:///script.js:4:2(4))\n\tat native\n",
"\tat file:///bar.js:3:8(3)\n\tat setup (file:///script.js:4:2(4))\n",
err.Error())
}
}
Expand Down Expand Up @@ -940,7 +940,7 @@ func TestVuInitException(t *testing.T) {

var exception errext.Exception
require.ErrorAs(t, err, &exception)
assert.Equal(t, "Error: oops in 2\n\tat file:///script.js:10:9(29)\n\tat native\n", err.Error())
assert.Equal(t, "Error: oops in 2\n\tat file:///script.js:10:9(29)\n", err.Error())

var errWithHint errext.HasHint
require.ErrorAs(t, err, &errWithHint)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/PuerkitoBio/goquery v1.8.0
github.com/Soontao/goHttpDigestClient v0.0.0-20170320082612-6d28bb1415c5
github.com/andybalholm/brotli v1.0.4
github.com/dop251/goja v0.0.0-20221106173738-3b8a68ca89b4
github.com/dop251/goja v0.0.0-20221229151140-b95230a9dbad
github.com/fatih/color v1.13.0
github.com/golang/protobuf v1.5.2
github.com/gorilla/websocket v1.5.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnm
github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja v0.0.0-20221003171542-5ea1285e6c91/go.mod h1:yRkwfj0CBpOGre+TwBsqPV0IH0Pk73e4PXJOeNDboGs=
github.com/dop251/goja v0.0.0-20221106173738-3b8a68ca89b4 h1:arM6Tq1Ba+a9FWuq3S6Qgrfd5MD0slQdMnCKI2VclFg=
github.com/dop251/goja v0.0.0-20221106173738-3b8a68ca89b4/go.mod h1:yRkwfj0CBpOGre+TwBsqPV0IH0Pk73e4PXJOeNDboGs=
github.com/dop251/goja v0.0.0-20221229151140-b95230a9dbad h1:EikyYzLzjRNW8lz9VAIUcmrwDAU6PsMRnwblYXb6Ysg=
github.com/dop251/goja v0.0.0-20221229151140-b95230a9dbad/go.mod h1:yRkwfj0CBpOGre+TwBsqPV0IH0Pk73e4PXJOeNDboGs=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
4 changes: 2 additions & 2 deletions js/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestNewBundle(t *testing.T) {
_, err := getSimpleBundle(t, "/script.js", `throw new Error("aaaa");`)
exception := new(scriptException)
require.ErrorAs(t, err, &exception)
require.EqualError(t, err, "Error: aaaa\n\tat file:///script.js:2:7(3)\n\tat native\n")
require.EqualError(t, err, "Error: aaaa\n\tat file:///script.js:2:7(3)\n")
})
t.Run("InvalidExports", func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestNewBundle(t *testing.T) {
{
"BigInt", "base",
`module.exports.default = function() {}; BigInt(1231412444)`,
"ReferenceError: BigInt is not defined\n\tat file:///script.js:2:47(7)\n\tat native\n",
"ReferenceError: BigInt is not defined\n\tat file:///script.js:2:47(7)\n",
},
}

Expand Down
25 changes: 22 additions & 3 deletions js/eventloop/eventloop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func TestEventLoopRejectSyntaxError(t *testing.T) {
return err
})
loop.WaitOnRegistered()
require.EqualError(t, err, "Uncaught (in promise) ReferenceError: some is not defined\n\tat <eval>:1:30(1)\n\tat native\n")
require.EqualError(t, err, "Uncaught (in promise) ReferenceError: some is not defined\n\tat <eval>:1:30(1)\n")
}

func TestEventLoopRejectGoError(t *testing.T) {
Expand All @@ -194,7 +194,7 @@ func TestEventLoopRejectGoError(t *testing.T) {
return err
})
loop.WaitOnRegistered()
require.EqualError(t, err, "Uncaught (in promise) GoError: some error\n\tat go.k6.io/k6/js/eventloop_test.TestEventLoopRejectGoError.func1 (native)\n\tat <eval>:1:30(1)\n\tat native\n")
require.EqualError(t, err, "Uncaught (in promise) GoError: some error\n\tat go.k6.io/k6/js/eventloop_test.TestEventLoopRejectGoError.func1 (native)\n\tat <eval>:1:31(2)\n")
}

func TestEventLoopRejectThrow(t *testing.T) {
Expand All @@ -211,5 +211,24 @@ func TestEventLoopRejectThrow(t *testing.T) {
return err
})
loop.WaitOnRegistered()
require.EqualError(t, err, "Uncaught (in promise) GoError: throw error\n\tat go.k6.io/k6/js/eventloop_test.TestEventLoopRejectThrow.func1 (native)\n\tat <eval>:1:30(1)\n\tat native\n")
require.EqualError(t, err, "Uncaught (in promise) GoError: throw error\n\tat go.k6.io/k6/js/eventloop_test.TestEventLoopRejectThrow.func1 (native)\n\tat <eval>:1:31(2)\n")
}

func TestEventLoopAsyncAwait(t *testing.T) {
t.Parallel()
vu := &modulestest.VU{RuntimeField: goja.New()}
loop := eventloop.New(vu)
err := loop.Start(func() error {
_, err := vu.Runtime().RunString(`
async function a() {
some.error.here
}
Promise.resolve().then(async () => {
await a();
})
`)
return err
})
loop.WaitOnRegistered()
require.EqualError(t, err, "Uncaught (in promise) ReferenceError: some is not defined\n\tat a (<eval>:3:13(1))\n\tat <eval>:6:20(2)\n")
}
10 changes: 5 additions & 5 deletions js/initcontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestInitContextRequire(t *testing.T) {
require.NoError(t, afero.WriteFile(fs, "/file.js", []byte(`throw new Error("aaaa")`), 0o755))
_, err := getSimpleBundle(t, "/script.js", `import "/file.js"; export default function() {}`, fs)
assert.EqualError(t, err,
"Error: aaaa\n\tat file:///file.js:2:7(3)\n\tat go.k6.io/k6/js.(*InitContext).Require-fm (native)\n\tat file:///script.js:1:0(14)\n\tat native\n")
"Error: aaaa\n\tat file:///file.js:2:7(3)\n\tat go.k6.io/k6/js.(*InitContext).Require-fm (native)\n\tat file:///script.js:1:0(15)\n")
})

imports := map[string]struct {
Expand Down Expand Up @@ -589,7 +589,7 @@ export default function(){
require.Error(t, err)
exception := new(goja.Exception)
require.ErrorAs(t, err, &exception)
require.Equal(t, exception.String(), "exception in line 2\n\tat f2 (file:///module1.js:2:4(2))\n\tat file:///script.js:5:4(3)\n\tat native\n")
require.Equal(t, exception.String(), "exception in line 2\n\tat f2 (file:///module1.js:2:4(2))\n\tat file:///script.js:5:4(3)\n")
}

func TestSourceMapsExternal(t *testing.T) {
Expand Down Expand Up @@ -620,7 +620,7 @@ export default function () {
require.Error(t, err)
exception := new(goja.Exception)
require.ErrorAs(t, err, &exception)
require.Equal(t, "cool is cool\n\tat webpack:///./test1.ts:2:4(2)\n\tat webpack:///./test1.ts:5:4(3)\n\tat file:///script.js:4:2(4)\n\tat native\n", exception.String())
require.Equal(t, "cool is cool\n\tat webpack:///./test1.ts:2:4(2)\n\tat webpack:///./test1.ts:5:4(3)\n\tat file:///script.js:4:2(4)\n", exception.String())
}

func TestSourceMapsExternalExtented(t *testing.T) {
Expand Down Expand Up @@ -654,7 +654,7 @@ export default function () {
require.ErrorAs(t, err, &exception)
// TODO figure out why those are not the same as the one in the previous test TestSourceMapsExternal
// likely settings in the transpilers
require.Equal(t, "cool is cool\n\tat webpack:///./test1.ts:2:4(2)\n\tat r (webpack:///./test1.ts:5:4(3))\n\tat file:///script.js:4:2(4)\n\tat native\n", exception.String())
require.Equal(t, "cool is cool\n\tat webpack:///./test1.ts:2:4(2)\n\tat r (webpack:///./test1.ts:5:4(3))\n\tat file:///script.js:4:2(4)\n", exception.String())
}

func TestSourceMapsExternalExtentedInlined(t *testing.T) {
Expand Down Expand Up @@ -685,7 +685,7 @@ export default function () {
require.ErrorAs(t, err, &exception)
// TODO figure out why those are not the same as the one in the previous test TestSourceMapsExternal
// likely settings in the transpilers
require.Equal(t, "cool is cool\n\tat webpack:///./test1.ts:2:4(2)\n\tat r (webpack:///./test1.ts:5:4(3))\n\tat file:///script.js:4:2(4)\n\tat native\n", exception.String())
require.Equal(t, "cool is cool\n\tat webpack:///./test1.ts:2:4(2)\n\tat r (webpack:///./test1.ts:5:4(3))\n\tat file:///script.js:4:2(4)\n", exception.String())
}

func TestImportModificationsAreConsistentBetweenFiles(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion js/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestRunnerNew(t *testing.T) {
t.Run("Invalid", func(t *testing.T) {
t.Parallel()
_, err := getSimpleRunner(t, "/script.js", `blarg`)
assert.EqualError(t, err, "ReferenceError: blarg is not defined\n\tat file:///script.js:2:1(1)\n\tat native\n")
assert.EqualError(t, err, "ReferenceError: blarg is not defined\n\tat file:///script.js:2:1(1)\n")
})
}

Expand Down
6 changes: 4 additions & 2 deletions js/tc39/breaking_test_errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"test/annexB/built-ins/RegExp/RegExp-leading-escape-BMP.js-strict:true": "test/annexB/built-ins/RegExp/RegExp-leading-escape-BMP.js: Test262Error: Code unit: d800 Expected SameValue(«\\\\\\ud800», «\\�») to be true <at omitted>",
"test/annexB/built-ins/RegExp/RegExp-trailing-escape-BMP.js-strict:true": "test/annexB/built-ins/RegExp/RegExp-trailing-escape-BMP.js: Test262Error: Code unit: d800 Expected SameValue(«a\\\\\\ud800», «a\\�») to be true <at omitted>",
"test/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid-u.js-strict:true": "test/annexB/built-ins/RegExp/prototype/compile/pattern-string-invalid-u.js: Test262Error: invalid pattern: { Expected a SyntaxError to be thrown but no exception was thrown at all <at omitted>",
"test/built-ins/AsyncArrowFunction/is-a-constructor.js-strict:true": "test/built-ins/AsyncArrowFunction/is-a-constructor.js: SyntaxError: harness/hidden-constructors.js: Unexpected token (16:65)\n 14 | var AsyncArrowFunction = Object.getPrototypeOf(async () => {}).constructor;\n 15 | var AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;\n> 16 | var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;\n | ^\n 17 | var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;\n 18 | <at omitted>",
"test/built-ins/AsyncFunction/AsyncFunction-is-subclass.js-strict:true": "test/built-ins/AsyncFunction/AsyncFunction-is-subclass.js: Test262Error: Prototype of constructor is Function Expected SameValue(«function () { [native code] }», «function Function() { [native code] }») to be true <at omitted>",
"test/built-ins/AsyncFunction/is-a-constructor.js-strict:true": "test/built-ins/AsyncFunction/is-a-constructor.js: SyntaxError: harness/hidden-constructors.js: Unexpected token (16:65)\n 14 | var AsyncArrowFunction = Object.getPrototypeOf(async () => {}).constructor;\n 15 | var AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;\n> 16 | var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;\n | ^\n 17 | var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;\n 18 | <at omitted>",
"test/built-ins/Date/UTC/fp-evaluation-order.js-strict:true": "test/built-ins/Date/UTC/fp-evaluation-order.js: Test262Error: order of operations / precision in MakeTime Expected SameValue(«29256», «29312») to be true <at omitted>",
"test/built-ins/Function/internals/Construct/base-ctor-revoked-proxy.js-strict:true": "test/built-ins/Function/internals/Construct/base-ctor-revoked-proxy.js: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all <at omitted>",
"test/built-ins/Object/seal/seal-bigint64array.js-strict:true": "test/built-ins/Object/seal/seal-bigint64array.js: ReferenceError: BigInt64Array is not defined <at omitted>",
Expand Down Expand Up @@ -35,9 +38,8 @@
"test/language/expressions/class/elements/class-name-static-initializer-default-export.js-strict:true": "test/language/expressions/class/elements/class-name-static-initializer-default-export.js: SyntaxError: test/language/expressions/class/elements/class-name-static-initializer-default-export.js: Unexpected token (25:13)\n 23 | \n 24 | export default class {\n> 25 | static f = (className = this.name);\n | ^\n 26 | }\n 27 | \n 28 | assert.sameValue(className, \"default\"); <at omitted>",
"test/language/expressions/class/elements/private-getter-is-not-a-own-property.js-strict:true": "test/language/expressions/class/elements/private-getter-is-not-a-own-property.js: TypeError: Object has no member '__lookupGetter__' <at omitted>",
"test/language/expressions/class/elements/private-setter-is-not-a-own-property.js-strict:true": "test/language/expressions/class/elements/private-setter-is-not-a-own-property.js: TypeError: Object has no member '__lookupSetter__' <at omitted>",
"test/language/expressions/class/heritage-arrow-function.js-strict:true": "test/language/expressions/class/heritage-arrow-function.js: test/language/expressions/class/heritage-arrow-function.js: Line 30:36 Unexpected token => (and 4 more errors)",
"test/language/expressions/object/cpn-obj-lit-computed-property-name-from-integer-separators.js-strict:true": "test/language/expressions/object/cpn-obj-lit-computed-property-name-from-integer-separators.js: SyntaxError: test/language/expressions/object/cpn-obj-lit-computed-property-name-from-integer-separators.js: Identifier directly after number (29:4)\n 27 | \n 28 | let o = {\n> 29 | [1_2_3_4_5_6_7_8]: 1_2_3_4_5_6_7_8\n | ^\n 30 | };\n 31 | \n 32 | assert.sameValue( <at omitted>",
"test/language/expressions/object/method-definition/object-method-returns-promise.js-strict:true": "test/language/expressions/object/method-definition/object-method-returns-promise.js: test/language/expressions/object/method-definition/object-method-returns-promise.js: Line 12:9 Unexpected identifier (and 4 more errors)",
"test/language/expressions/optional-chaining/iteration-statement-for-await-of.js-strict:true": "test/language/expressions/optional-chaining/iteration-statement-for-await-of.js: SyntaxError: test/language/expressions/optional-chaining/iteration-statement-for-await-of.js: Unexpected token, expected ( (31:6)\n 29 | async function checkAssertions() {\n 30 | let count = 0;\n> 31 | for await (const num of obj?.iterable) {\n | ^\n 32 | count += num;\n 33 | }\n 34 | assert.sameValue(3, count); <at omitted>",
"test/language/expressions/optional-chaining/member-expression.js-strict:true": "test/language/expressions/optional-chaining/member-expression.js: SyntaxError: test/language/expressions/optional-chaining/member-expression.js: Unexpected token (18:23)\n 16 | // IdentifierReference\n 17 | const a = {b: 22};\n> 18 | assert.sameValue(22, a?.b);\n | ^\n 19 | // this\n 20 | function fn () {\n 21 | return this?.a <at omitted>",
"test/language/identifiers/part-unicode-14.0.0-class-escaped.js-strict:true": "test/language/identifiers/part-unicode-14.0.0-class-escaped.js: SyntaxError: test/language/identifiers/part-unicode-14.0.0-class-escaped.js: Unexpected character '#' (20:2)\n 18 | \n 19 | class _ {\n> 20 | #_\\u0898\\u0899\\u089A\\u089B\\u089C\\u089D\\u089E\\u089F\\u08CA\\u08CB\\u08CC\\u08CD\\u08CE\\u08CF\\u08D0\\u08D1\\u08D2\\u0C3C\\u1715\\u180F\\u1AC1\\u1AC2\\u1AC3\\u1AC4\\u1AC5\\u1AC6\\u1AC7\\u1AC8\\u1AC9\\u1ACA\\u1ACB\\u1ACC\\u1ACD\\u1ACE\\u1DFA\\u{10F82}\\u{10F83}\\u{10F84}\\u{10F85}\\u{11070}\\u{11073}\\u{11074}\\u{110C2}\\u{16AC0}\\u{16AC1}\\u{16AC2}\\u{16AC3}\\u{16AC4}\\u{16AC5}\\u{16AC6}\\u{16AC7}\\u{16AC8}\\u{16AC9}\\u{1CF00}\\u{1CF01}\\u{1CF02}\\u{1CF03}\\u{1CF04}\\u{1CF05}\\u{1CF06}\\u{1CF07}\\u{1CF08}\\u{1CF09}\\u{1CF0A}\\u{1CF0B}\\u{1CF0C}\\u{1CF0D}\\u{1CF0E}\\u{1CF0F}\\u{1CF10}\\u{1CF11}\\u{1CF12}\\u{1CF13}\\u{1CF14}\\u{1CF15}\\u{1CF16}\\u{1CF17}\\u{1CF18}\\u{1CF19}\\u{1CF1A}\\u{1CF1B}\\u{1CF1C}\\u{1CF1D}\\u{1CF1E}\\u{1CF1F}\\u{1CF20}\\u{1CF21}\\u{1CF22}\\u{1CF23}\\u{1CF24}\\u{1CF25}\\u{1CF26}\\u{1CF27}\\u{1CF28}\\u{1CF29}\\u{1CF2A}\\u{1CF2B}\\u{1CF2C}\\u{1CF2D}\\u{1CF30}\\u{1CF31}\\u{1CF32}\\u{1CF33}\\u{1CF34}\\u{1CF35}\\u{1CF36}\\u{1CF37}\\u{1CF38}\\u{1CF39}\\u{1CF3A}\\u{1CF3B}\\u{1CF3C}\\u{1CF3D}\\u{1CF3E}\\u{1CF3F}\\u{1CF40}\\u{1CF41}\\u{1CF42}\\u{1CF43}\\u{1CF44}\\u{1CF45}\\u{1CF46}\\u{1E2AE};\n | ^\n 21 | };\n 22 | <at omitted>",
"test/language/identifiers/part-unicode-14.0.0-class.js-strict:true": "test/language/identifiers/part-unicode-14.0.0-class.js: SyntaxError: test/language/identifiers/part-unicode-14.0.0-class.js: Unexpected character '#' (17:2)\n 15 | \n 16 | class _ {\n> 17 | #_఼᜕࢙࢚࢛࣏࣐࣑࣒࢘࢜࢝࢞࢟࣊࣋࣌࣍࣎᠏𑁰᷺᫃᫄᫊𐾃𐾅᫁᫂᫅᫆᫇᫈᫉᫋ᫌᫍᫎ𐾂𐾄𑁳𑁴𑃂𖫀𖫁𖫂𖫃𖫄𖫅𖫆𖫇𖫈𖫉𜼀𜼁𜼂𜼃𜼄𜼅𜼆𜼇𜼈𜼉𜼊𜼋𜼌𜼍𜼎𜼏𜼐𜼑𜼒𜼓𜼔𜼕𜼖𜼗𜼘𜼙𜼚𜼛𜼜𜼝𜼞𜼟𜼠𜼡𜼢𜼣𜼤𜼥𜼦𜼧𜼨𜼩𜼪𜼫𜼬𜼭𜼰𜼱𜼲𜼳𜼴𜼵𜼶𜼷𜼸𜼹𜼺𜼻𜼼𜼽𜼾𜼿𜽀𜽁𜽂𜽃𜽄𜽅𜽆𞊮;\n | ^\n 18 | };\n 19 | <at omitted>",
Expand Down
Loading

0 comments on commit 8418147

Please sign in to comment.