-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ses): anticipate interator helpers
- Loading branch information
Showing
7 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/ses/test/test-anticipate-async-iterator-helpers-shimmed.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// KLUDGE HAZARD The core-js shims are written as sloppy code | ||
// and so introduce sloppy functions. | ||
import 'core-js/actual/async-iterator/index.js'; | ||
import test from 'ava'; | ||
import '../index.js'; | ||
|
||
// KLUDGE HAZARD only for testing with the sloppy modules of the | ||
// core-js iterator shim. | ||
// We mutate the permits to tolerates the sloppy functions for testing | ||
// by sacrificing security. The caller and arguments properties of | ||
// sloppy functions violate ocap encapsulation rules. | ||
import { AsyncFunctionInstance } from '../src/permits.js'; | ||
|
||
AsyncFunctionInstance.arguments = {}; | ||
AsyncFunctionInstance.caller = {}; | ||
|
||
// Skipped because the core-js shim seems to miss the | ||
// actual %AsyncIteratorPrototype%, | ||
// so it creates a new one, causing us to fail because lockdown correctly | ||
// detects the conflicting definitions. | ||
// TODO report the bug to core-js | ||
test.skip('shimmed async-iterator helpers', t => { | ||
lockdown(); | ||
|
||
const AsyncIteratorHelperPrototype = Object.getPrototypeOf( | ||
AsyncIterator.from([]).take(0), | ||
); | ||
t.assert(Object.isFrozen(AsyncIteratorHelperPrototype)); | ||
|
||
const WrapForValidAsyncIteratorPrototype = Object.getPrototypeOf( | ||
AsyncIterator.from({ async next() { return undefined; } }), | ||
); | ||
t.assert(Object.isFrozen(WrapForValidAsyncIteratorPrototype)); | ||
}); |
42 changes: 42 additions & 0 deletions
42
packages/ses/test/test-anticipate-iterator-helpers-shimmed.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// KLUDGE HAZARD The core-js shims are written as sloppy code | ||
// and so introduce sloppy functions. | ||
import 'core-js/actual/iterator/index.js'; | ||
import test from 'ava'; | ||
import '../index.js'; | ||
|
||
// KLUDGE HAZARD only for testing with the sloppy modules of the | ||
// core-js iterator shim. | ||
// We mutate the permits to tolerates the sloppy functions for testing | ||
// by sacrificing security. The caller and arguments properties of | ||
// sloppy functions violate ocap encapsulation rules. | ||
import { FunctionInstance } from '../src/permits.js'; | ||
|
||
FunctionInstance.arguments = {}; | ||
FunctionInstance.caller = {}; | ||
|
||
test('shimmed iterator helpers', t => { | ||
lockdown(); | ||
|
||
t.deepEqual( | ||
(function* g(i) { | ||
// eslint-disable-next-line no-plusplus | ||
while (true) yield i++; | ||
})(1) | ||
.drop(1) | ||
.take(5) | ||
.filter(it => it % 2) | ||
.map(it => it ** 2) | ||
.toArray(), | ||
[9, 25], | ||
); | ||
|
||
const IteratorHelperPrototype = Object.getPrototypeOf( | ||
Iterator.from([]).take(0), | ||
); | ||
t.assert(Object.isFrozen(IteratorHelperPrototype)); | ||
|
||
const WrapForValidIteratorPrototype = Object.getPrototypeOf( | ||
Iterator.from({ next() {} }), | ||
); | ||
t.assert(Object.isFrozen(WrapForValidIteratorPrototype)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters