forked from lxe/node-weak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the
isWeakRef()
C++ check (TooTallNate#88)
* Add currently-failing test case for issue TooTallNate#83. * Add a test to make sure that `isWeakRef()` works as expected. This also effectively checks the low-level native code for same, which is used extensively. * Make the use of internal fields more "symbolic." * Add a second internal field to weak ref proxies. This is used to hold a pointer which is unique to the module, and is checked as part of the process of determining whether a value is a weak ref, in `isWeakRef()`. This additional check will work assuming the lack of ill intent of other native code, but it is susceptible to "gaming" by malicious native code. That said, it is nonetheless an improvement in correctness over the old version of the check, and all bets are off with native code anyway. * Better guard.
- Loading branch information
1 parent
1c3b037
commit ed95b7d
Showing
3 changed files
with
49 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var assert = require('assert'); | ||
var weak = require('../') | ||
|
||
describe('promise', function () { | ||
if (!global.Promise) { | ||
// Version of JS without `Promise`; nothing to do. | ||
return; | ||
} | ||
|
||
it('should not mistake a promise for a weak reference', function () { | ||
var p = new Promise(function () {}); | ||
assert(!weak.isWeakRef(p)); | ||
}); | ||
}) |