-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,44 @@ | ||
/** | ||
* Test basic callback identity properties when dynamic callback patcher is involved. | ||
*/ | ||
|
||
const assert = require('tools/assertCallbacks'); | ||
|
||
function cb() { | ||
console.log('cb!'); | ||
} | ||
|
||
var storedCb; | ||
|
||
/** | ||
* dbux disable | ||
*/ | ||
function nativeCallStore(cb) { | ||
assert.patched(cb); | ||
storedCb = cb; | ||
} | ||
|
||
/** | ||
* dbux disable | ||
*/ | ||
function nativeCallCompare(cb) { | ||
assert.patched(cb); | ||
console.assert(cb === storedCb, '❌ Same callback passed in twice -> should be the same.'); | ||
} | ||
|
||
(async function main() { | ||
setTimeout(cb, 50); | ||
|
||
assert.not.patched(cb); | ||
assert.patched(Array.prototype.slice); | ||
|
||
|
||
/** | ||
* Call function with same cb twice: | ||
* -> it should be recognized as the same cb, or else `removeEventListener` | ||
* and many other callback management mechanisms cannot work correctly. | ||
*/ | ||
nativeCallStore(cb); | ||
nativeCallCompare(cb); | ||
|
||
// TODO: more testing here, with checks for multi-patching | ||
})(); |