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 16 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,57 @@
// Copyright (C) 2024 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot
description: >
[[Prototype]] defaults to %AsyncContext.Snapshot.prototype% if NewTarget.prototype is not an object.
info: |
AsyncContext.Snapshot ( )

...
3. Let asyncSnapshot be ? OrdinaryCreateFromConstructor(NewTarget, "%AsyncContext.Snapshot.prototype%", « [[AsyncSnapshotMapping]] »).
...
5. Return asyncSnapshot.

OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

...
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
3. Return ObjectCreate(proto, internalSlotsList).

GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )

3. Let proto be ? Get(constructor, 'prototype').
4. If Type(proto) is not Object, then
a. Let realm be ? GetFunctionRealm(constructor).
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
5. Return proto.
features: [AsyncContext, Reflect.construct, Symbol]
---*/

var asyncSnapshot;
function newTarget() { }

newTarget.prototype = undefined;
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), AsyncContext.Snapshot.prototype, 'newTarget.prototype is undefined');

newTarget.prototype = null;
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), AsyncContext.Snapshot.prototype, 'newTarget.prototype is null');

newTarget.prototype = true;
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), AsyncContext.Snapshot.prototype, 'newTarget.prototype is a Boolean');

newTarget.prototype = '';
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), AsyncContext.Snapshot.prototype, 'newTarget.prototype is a String');

newTarget.prototype = Symbol();
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), AsyncContext.Snapshot.prototype, 'newTarget.prototype is a Symbol');

newTarget.prototype = 1;
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), AsyncContext.Snapshot.prototype, 'newTarget.prototype is a Number');
22 changes: 22 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/prop-desc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2024 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: >
Property descriptor of AsyncContext.Snapshot
info: |
17 ECMAScript Standard Built-in Objects:

Every other data property described in clauses 18 through 26 and in Annex B.2
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
includes: [propertyHelper.js]
features: [AsyncContext]
---*/

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

/*---
esid: sec-asynccontext-snapshot
description: Default [[Prototype]] value derived from realm of the newTarget
info: |
AsyncContext.Snapshot ( )

...
3. Let asyncSnapshot be ? OrdinaryCreateFromConstructor(NewTarget, "%AsyncContext.Snapshot.prototype%", « [[AsyncSnapshotMapping]] »).
...
5. Return asyncSnapshot.

OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

...
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
3. Return ObjectCreate(proto, internalSlotsList).

GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )

3. Let proto be ? Get(constructor, 'prototype').
4. If Type(proto) is not Object, then
a. Let realm be ? GetFunctionRealm(constructor).
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
5. Return proto.
features: [AsyncContext, cross-realm, Reflect, Symbol]
---*/

var other = $262.createRealm().global;
var newTarget = new other.Function();
var asyncSnapshot;

newTarget.prototype = undefined;
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), other.AsyncContext.Snapshot.prototype, 'newTarget.prototype is undefined');

newTarget.prototype = null;
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), other.AsyncContext.Snapshot.prototype, 'newTarget.prototype is null');

newTarget.prototype = true;
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), other.AsyncContext.Snapshot.prototype, 'newTarget.prototype is a Boolean');

newTarget.prototype = '';
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), other.AsyncContext.Snapshot.prototype, 'newTarget.prototype is a String');

newTarget.prototype = Symbol();
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), other.AsyncContext.Snapshot.prototype, 'newTarget.prototype is a Symbol');

newTarget.prototype = 1;
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), other.AsyncContext.Snapshot.prototype, 'newTarget.prototype is a Number');

18 changes: 18 additions & 0 deletions test/built-ins/AsyncContext/Snapshot/proto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2024 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 prototype of AsyncContext.Snapshot is %Function.prototype%
info: |
The value of the [[Prototype]] internal slot of the AsyncContext.Snapshot
constructor is the intrinsic object %Function.prototype%.
features: [AsyncContext]
---*/

assert.sameValue(
Object.getPrototypeOf(AsyncContext.Snapshot),
Function.prototype,
'Object.getPrototypeOf(AsyncContext.Snapshot) returns the value of `Function.prototype`'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2024 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot
description: >
Return abrupt from getting the NewTarget prototype
info: |
AsyncContext.Snapshot ( )

...
3. Let asyncSnapshot be ? OrdinaryCreateFromConstructor(NewTarget, "%AsyncContext.Snapshot.prototype%", « [[AsyncSnapshotMapping]] »).
...
5. Return asyncSnapshot.

OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

...
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
3. Return ObjectCreate(proto, internalSlotsList).

GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )

3. Let proto be ? Get(constructor, 'prototype').
features: [AsyncContext, Reflect.construct]
---*/

var calls = 0;
var newTarget = function() {}.bind(null);
Object.defineProperty(newTarget, 'prototype', {
get: function() {
calls += 1;
throw new Test262Error();
}
});

assert.throws(Test262Error, function() {
Reflect.construct(AsyncContext.Snapshot, [], newTarget);
});

assert.sameValue(calls, 1);
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2024 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-asynccontext-snapshot
description: >
The [[Prototype]] internal slot is computed from NewTarget.
info: |
AsyncContext.Snapshot ( )

...
3. Let asyncSnapshot be ? OrdinaryCreateFromConstructor(NewTarget, "%AsyncContext.Snapshot.prototype%", « [[AsyncSnapshotMapping]] »).
...
5. Return asyncSnapshot.

OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

...
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
3. Return ObjectCreate(proto, internalSlotsList).

GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )

3. Let proto be ? Get(constructor, 'prototype').
4. If Type(proto) is not Object, then
a. Let realm be ? GetFunctionRealm(constructor).
b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
5. Return proto.
features: [AsyncContext, Reflect.construct]
---*/

var asyncSnapshot;

asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], Object);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), Object.prototype, 'NewTarget is built-in Object constructor');

var newTarget = function() {}.bind(null);
Object.defineProperty(newTarget, 'prototype', {
get: function() {
return Array.prototype;
}
});
asyncSnapshot = Reflect.construct(AsyncContext.Snapshot, [], newTarget);
assert.sameValue(Object.getPrototypeOf(asyncSnapshot), Array.prototype, 'NewTarget is BoundFunction with accessor');
Loading
Loading