Skip to content

Commit

Permalink
fix(ses): Relax hardened typed array test to be insensitive to bugfix…
Browse files Browse the repository at this point in the history
… between Node.js 14 and 16 (#1048)

Fixes: #1045
  • Loading branch information
kriskowal committed Feb 3, 2022
1 parent daf1d66 commit e12508d
Showing 1 changed file with 52 additions and 27 deletions.
79 changes: 52 additions & 27 deletions packages/ses/test/test-make-hardener.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,20 @@ test('harden typed arrays', t => {

t.is(h(a), a, `harden ${TypedArray}`);
t.truthy(Object.isSealed(a));
t.deepEqual(
{
value: a[0],
writable: true, // Note that indexes of typed arrays are exceptionally writable for hardened objects.
configurable: false,
enumerable: true,
},
Object.getOwnPropertyDescriptor(a, '0'),
const descriptor = Object.getOwnPropertyDescriptor(a, '0');
t.is(descriptor.value, a[0]);
// Fails in Node.js 14 and earlier due to an engine bug:
// t.is(descriptor.configurable, true, 'hardened typed array indexed property remains configurable');
// Note that indexes of typed arrays are exceptionally writable for hardened objects.
t.is(
descriptor.writable,
true,
'hardened typed array indexed property is writable',
);
t.is(
descriptor.enumerable,
true,
'hardened typed array indexed property is enumerable',
);
}
});
Expand All @@ -103,26 +109,44 @@ test('harden typed arrays and their expandos', t => {
t.is(h(a), a);
t.truthy(Object.isSealed(a));

t.deepEqual(
{
value: 0,
writable: true, // Note that indexes of typed arrays are exceptionally writable for hardened objects.
configurable: false,
enumerable: true,
},
Object.getOwnPropertyDescriptor(a, '0'),
);
{
const descriptor = Object.getOwnPropertyDescriptor(a, '0');
t.is(descriptor.value, 0);
// Fails in Node.js 14 and earlier due to an engine bug:
// t.is(descriptor.configurable, true, 'typed array indexed property is configurable');
// Note that indexes of typed arrays are exceptionally writable for hardened objects:
t.is(
descriptor.writable,
true,
'hardened typed array indexed property is writable',
);
t.is(
descriptor.enumerable,
true,
'hardened typed array indexed property is enumerable',
);
}

t.deepEqual(
{
// @ts-ignore
value: a.x,
writable: false,
configurable: false,
enumerable: true,
},
Object.getOwnPropertyDescriptor(a, 'x'),
);
{
const descriptor = Object.getOwnPropertyDescriptor(a, 'x');
// @ts-ignore
t.is(descriptor.value, a.x);
t.is(
descriptor.configurable,
false,
'hardened typed array indexed property is configurable',
);
t.is(
descriptor.writable,
false,
'hardened typed array expando is not writable',
);
t.is(
descriptor.enumerable,
true,
'hardened typed array expando is enumerable',
);
}

// @ts-ignore
t.truthy(Object.isFrozen(a.x));
Expand All @@ -142,6 +166,7 @@ test('hardening makes writable properties readonly even if non-configurable', t
enumerable: false,
});
h(o);

t.deepEqual(
{
value: 10,
Expand Down

0 comments on commit e12508d

Please sign in to comment.