-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ses): Do not get confused by well-known look-alikes
- Loading branch information
Showing
2 changed files
with
86 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import test from 'ava'; | ||
import '../index.js'; | ||
import whitelistIntrinsics from '../src/whitelist-intrinsics.js'; | ||
|
||
// eslint-disable-next-line no-eval | ||
if (!eval.toString().includes('native code')) { | ||
throw new TypeError('Module "esm" enabled: aborting'); | ||
} | ||
|
||
test('whitelistIntrinsics - Well-known symbols', t => { | ||
const SymbolIterator = Symbol('Symbol.iterator'); | ||
const RogueSymbolIterator = Symbol('Symbol.iterator'); | ||
const ArrayProto = { [RogueSymbolIterator]() {} }; | ||
const intrinsics = Object.freeze({ | ||
__proto__: null, | ||
Symbol: { | ||
__proto__: Function.prototype, | ||
// Well-known symbol under test | ||
iterator: SymbolIterator, | ||
// Needed symbol found on %FunctionPrototype% | ||
hasInstance: Symbol.hasInstance, | ||
}, | ||
Array: { | ||
__proto__: Function.prototype, | ||
prototype: ArrayProto, | ||
}, | ||
// Required intrinsics | ||
'%ArrayPrototype%': ArrayProto, | ||
'%FunctionPrototype%': Function.prototype, | ||
// Yes, this is clearly not inert | ||
'%InertFunction%': Function.prototype.constructor, | ||
'%ObjectPrototype%': Object.prototype, | ||
Object, | ||
}); | ||
whitelistIntrinsics(intrinsics, () => {}); | ||
t.is( | ||
ArrayProto[RogueSymbolIterator], | ||
undefined, | ||
`Well-known Symbol look-alike should have been removed`, | ||
); | ||
}); |