Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for AsyncContext (Stage 2) #3874

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f1fb4c0
Add tests for AsyncContext (Stage 2)
andreubotella Jul 18, 2023
350da74
Fix lints
andreubotella Jul 18, 2023
987a0c8
Add AsyncContext feature
andreubotella Jul 18, 2023
6cac352
Merge branch 'main' into async-context
andreubotella Aug 1, 2023
ee29d94
Add some missing AsyncContext.Variable tests
andreubotella Aug 1, 2023
0b59f33
Add more generator tests for context propagation
andreubotella Aug 1, 2023
aa0acfc
Merge branch 'main' into async-context
andreubotella Oct 25, 2023
a4375d1
Merge branch 'main' into async-context
andreubotella Nov 24, 2023
75b86a4
Merge branch 'main' into async-context
andreubotella Jan 25, 2024
6f3c8ee
Add `run` tests based on code review suggestions
andreubotella Jan 25, 2024
8e4ac00
Fix lint warnings
andreubotella Jan 25, 2024
3319cc4
Fix undefined this tests to use strict mode on the callback.
andreubotella Jan 25, 2024
c696583
Merge branch 'main' into async-context
andreubotella Feb 22, 2024
26f2a84
Add and fix various tests per review suggestions
andreubotella Feb 21, 2024
7f263a4
Fix proto, proc, etc. tests
andreubotella Feb 22, 2024
73a6c61
Fix proxy trap bug
andreubotella Feb 22, 2024
5a62a14
Add tests for `AsyncContext.Snapshot.wrap`
andreubotella Jan 26, 2024
2b7cfeb
Fix lint errors
andreubotella Feb 23, 2024
7b6c6c4
Merge branch 'main' into async-context
andreubotella Mar 6, 2024
60385ae
Update FinalizationRegistry test to construction time
andreubotella Mar 6, 2024
b4801be
Remove todo now that tc39/proposal-async-context#69 is merged
andreubotella Mar 6, 2024
f356f3c
Update tests for wrap's name and length properties to match tc39/prop…
andreubotella May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ promise-with-resolvers
# https://github.com/tc39/proposal-set-methods
set-methods

# AsyncContext
# https://github.com/tc39/proposal-async-context
AsyncContext

## Standard language features
#
# Language features that have been included in a published version of the
Expand Down
16 changes: 16 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot-constructor
description: >
The AsyncContext.Snapshot constructor is the %AsyncContext.Snapshot%
intrinsic object and the initial value of the Snapshot property of the
%AsyncContext% object.
features: [AsyncContext]
---*/

assert.sameValue(
typeof AsyncContext.Snapshot, 'function',
'typeof AsyncContext.Snapshot is function'
);
11 changes: 11 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/instance-extensible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot
description: Instances of AsyncContext.Snapshot are extensible
features: [AsyncContext]
---*/

var asyncSnapshot = new AsyncContext.Snapshot();
assert.sameValue(Object.isExtensible(asyncSnapshot), true);
20 changes: 20 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/instance-prototype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot.prototype
description: >
The initial value of AsyncContext.Snapshot.prototype is the
AsyncContext.Snapshot prototype object.
includes: [propertyHelper.js]
features: [AsyncContext]
---*/

assert.sameValue(
AsyncContext.Snapshot.prototype.isPrototypeOf(new AsyncContext.Snapshot()), true,
'AsyncContext.Snapshot.prototype.isPrototypeOf(new AsyncContext.Snapshot()) returns true'
);

verifyNotEnumerable(AsyncContext.Snapshot, 'prototype');
verifyNotWritable(AsyncContext.Snapshot, 'prototype');
verifyNotConfigurable(AsyncContext.Snapshot, 'prototype');
16 changes: 16 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/internal-prototype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-properties-of-the-asynccontext-snapshot-constructor
description: >
The AsyncContext.Snapshot constructor has a [[Prototype]] internal slot whose
value is %Function.prototype%.
features: [AsyncContext]
---*/

assert.sameValue(
Function.prototype.isPrototypeOf(AsyncContext.Snapshot),
true,
'Function.prototype.isPrototypeOf(AsyncContext.Snapshot) returns true'
);
12 changes: 12 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/is-a-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot-constructor
description: The AsyncContext.Snapshot constructor implements [[Construct]]
includes: [isConstructor.js]
features: [AsyncContext, Reflect.construct]
---*/

assert.sameValue(isConstructor(AsyncContext.Snapshot), true, 'isConstructor(AsyncContext.Snapshot) must return true');
new AsyncContext.Snapshot();
16 changes: 16 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot
description: AsyncContext.Snapshot.length property descriptor
includes: [propertyHelper.js]
features: [AsyncContext]
---*/

verifyProperty(AsyncContext.Snapshot, 'length', {
value: 0,
writable: false,
enumerable: false,
configurable: true
});
15 changes: 15 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot
description: AsyncContext.Snapshot.name value and descriptor
includes: [propertyHelper.js]
features: [AsyncContext]
---*/

assert.sameValue(AsyncContext.Snapshot.name, 'Snapshot', 'The value of AsyncContext.Snapshot.name is "Snapshot"');

verifyNotEnumerable(AsyncContext.Snapshot, 'name');
verifyNotWritable(AsyncContext.Snapshot, 'name');
verifyConfigurable(AsyncContext.Snapshot, 'name');
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot.prototype-@@tostringtag
description: >
`Symbol.toStringTag` property descriptor
info: |
The initial value of the @@toStringTag property is the String value
"AsyncContext.Snapshot".

This property has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [AsyncContext, Symbol.toStringTag]
---*/

assert.sameValue(AsyncContext.Snapshot.prototype[Symbol.toStringTag], 'AsyncContext.Snapshot');

verifyNotEnumerable(AsyncContext.Snapshot.prototype, Symbol.toStringTag);
verifyNotWritable(AsyncContext.Snapshot.prototype, Symbol.toStringTag);
verifyConfigurable(AsyncContext.Snapshot.prototype, Symbol.toStringTag);
19 changes: 19 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/prototype/constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot.prototype.constructor
description: AsyncContext.Snapshot.prototype.constructor value and descriptor
info: |
The initial value of AsyncContext.Snapshot.prototype.constructor is
%AsyncContext.Snapshot%.
includes: [propertyHelper.js]
features: [AsyncContext]
---*/

assert.sameValue(AsyncContext.Snapshot.prototype.constructor, AsyncContext.Snapshot);
assert.sameValue((new AsyncContext.Snapshot()).constructor, AsyncContext.Snapshot);

verifyNotEnumerable(AsyncContext.Snapshot.prototype, 'constructor');
verifyWritable(AsyncContext.Snapshot.prototype, 'constructor');
verifyConfigurable(AsyncContext.Snapshot.prototype, 'constructor');
16 changes: 16 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/prototype/descriptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot.prototype
description: AsyncContext.Snapshot.prototype property attributes.
info: |
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: false }.
includes: [propertyHelper.js]
features: [AsyncContext]
---*/

verifyNotEnumerable(AsyncContext.Snapshot, 'prototype');
verifyNotWritable(AsyncContext.Snapshot, 'prototype');
verifyNotConfigurable(AsyncContext.Snapshot, 'prototype');
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot.prototype.run
description: >
Calls the first parameter as a function, passing any arguments after the
first to it.
info: |
AsyncContext.Snapshot.prototype.run ( func, ...args )

4. Let result be Completion(Call(func, undefined, args)).
...
6. Return result.
features: [AsyncContext]
---*/

const asyncSnapshot = new AsyncContext.Snapshot();

const obj = {};
const symbol = Symbol();

let called = false;

asyncSnapshot.run(callback, 42, "bar", obj, symbol);

assert(called, 'The `callback` function was called.');

function callback() {
assert.sameValue(arguments.length, 4);
assert.sameValue(arguments[0], 42);
assert.sameValue(arguments[1], "bar");
assert.sameValue(arguments[2], obj);
assert.sameValue(arguments[3], symbol);
called = true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot.prototype.run
description: >
Throws a TypeError if `this` is not an Object.
info: |
AsyncContext.Snapshot.prototype.run ( func, ...args )

1. Let asyncSnapshot be the this value.
2. Perform ? RequireInternalSlot(asyncSnapshot, [[AsyncSnapshotMapping]]).
...

RequireInternalSlot(O, internalSlot)

1. If O is not an Object, throw a TypeError exception.
...
features: [AsyncContext, Symbol]
---*/

assert.throws(TypeError, function () {
AsyncContext.Snapshot.prototype.run.call(1);
});

assert.throws(TypeError, function () {
AsyncContext.Snapshot.prototype.run.call(true);
});

assert.throws(TypeError, function () {
AsyncContext.Snapshot.prototype.run.call('');
});

assert.throws(TypeError, function () {
AsyncContext.Snapshot.prototype.run.call(null);
});

assert.throws(TypeError, function () {
AsyncContext.Snapshot.prototype.run.call(undefined);
});

assert.throws(TypeError, function () {
AsyncContext.Snapshot.prototype.run.call(Symbol());
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot.prototype.run
description: >
Throws a TypeError if `this` does not have an [[AsyncSnapshotMapping]]
internal slot.
info: |
AsyncContext.Snapshot.prototype.run ( func, ...args )

1. Let asyncContext be the this value.
2. Perform ? RequireInternalSlot(asyncSnapshot, [[AsyncSnapshotMapping]]).
...

RequireInternalSlot(O, internalSlot)

...
2. If O does not have an internalSlot internal slot, throw a TypeError exception.
...
features: [AsyncContext]
---*/

assert.throws(TypeError, function () {
AsyncContext.Snapshot.prototype.run.call({});
});

assert.throws(TypeError, function () {
AsyncContext.Snapshot.prototype.run.call([]);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot.prototype.run
description: >
Throws a TypeError if `this` is an AsyncContext.Variable object.
info: |
AsyncContext.Snapshot.prototype.run ( func, ...args )

1. Let asyncSnapshot be the this value.
2. Perform ? RequireInternalSlot(asyncSnapshot, [[AsyncSnapshotMapping]]).
...

RequireInternalSlot(O, internalSlot)

...
2. If O does not have an internalSlot internal slot, throw a TypeError exception.
...
features: [AsyncContext]
---*/

assert.throws(TypeError, function () {
AsyncContext.Snapshot.prototype.run.call(new AsyncContext.Variable());
});
24 changes: 24 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/prototype/run/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot.prototype.run
description: >
AsyncContext.Snapshot.prototype.run.length value and descriptor.
info: |
AsyncContext.Snapshot.prototype.run ( func, ...args )

17 ECMAScript Standard Built-in Objects

includes: [propertyHelper.js]
features: [AsyncContext]
---*/

assert.sameValue(
AsyncContext.Snapshot.prototype.run.length, 1,
'The value of `AsyncContext.Snapshot.prototype.run.length` is `1`'
);

verifyNotEnumerable(AsyncContext.Snapshot.prototype.run, 'length');
verifyNotWritable(AsyncContext.Snapshot.prototype.run, 'length');
verifyConfigurable(AsyncContext.Snapshot.prototype.run, 'length');
24 changes: 24 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/prototype/run/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2023 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot.prototype.run
description: >
AsyncContext.Snapshot.prototype.run.name value and descriptor.
info: |
AsyncContext.Snapshot.prototype.run ( func, ...args )

17 ECMAScript Standard Built-in Objects

includes: [propertyHelper.js]
features: [AsyncContext]
---*/

assert.sameValue(
AsyncContext.Snapshot.prototype.run.name, 'run',
'The value of `AsyncContext.Snapshot.prototype.run.name` is `"run"`'
);

verifyNotEnumerable(AsyncContext.Snapshot.prototype.run, 'name');
verifyNotWritable(AsyncContext.Snapshot.prototype.run, 'name');
verifyConfigurable(AsyncContext.Snapshot.prototype.run, 'name');
Loading