Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing methods to Nan::Maybe<T> (#852)
* Add missing methods to Nan::Maybe<T> Nan::Maybe<T> was an alias for v8::Maybe<T> with most Node.js versions but that's problematic because v8::Maybe<T> has grown new methods over time that are missing in older versions. From now on we use our custom Maybe<T> implementation with all Node.js versions. This commit also adds the following missing methods: * Maybe<T>::Check() const * Maybe<T>::To(T*) const * Maybe<T>::ToChecked() const Fixes: #851 * Fix cpplint warnings. The code base is now `make lint`-clean again.
- Loading branch information
1 parent
8b2b384
commit 4e96248
Showing
13 changed files
with
155 additions
and
77 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
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,39 @@ | ||
/********************************************************************* | ||
* NAN - Native Abstractions for Node.js | ||
* | ||
* Copyright (c) 2019 NAN contributors | ||
* | ||
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md> | ||
********************************************************************/ | ||
|
||
#include <nan.h> | ||
|
||
using namespace Nan; // NOLINT(build/namespaces) | ||
|
||
NAN_METHOD(Test) { | ||
info.GetReturnValue().Set(false); | ||
{ | ||
Maybe<int> mb = Nothing<int>(); | ||
if (mb.IsJust()) return; | ||
if (!mb.IsNothing()) return; | ||
if (mb.To(NULL)) return; | ||
} | ||
{ | ||
Maybe<int> mb = Just(42); | ||
if (!mb.IsJust()) return; | ||
if (mb.IsNothing()) return; | ||
if (42 != mb.FromJust()) return; | ||
if (42 != mb.ToChecked()) return; | ||
mb.Check(); | ||
int v; | ||
if (!mb.To(&v)) return; | ||
if (42 != v) return; | ||
} | ||
info.GetReturnValue().Set(true); | ||
} | ||
|
||
NAN_MODULE_INIT(Init) { | ||
SetMethod(target, "test", Test); | ||
} | ||
|
||
NODE_MODULE(maybe, Init) |
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
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,16 @@ | ||
/********************************************************************* | ||
* NAN - Native Abstractions for Node.js | ||
* | ||
* Copyright (c) 2019 NAN contributors | ||
* | ||
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md> | ||
********************************************************************/ | ||
|
||
const test = require('tap').test | ||
, testRoot = require('path').resolve(__dirname, '..') | ||
, bindings = require('bindings')({ module_root: testRoot, bindings: 'maybe' }) | ||
|
||
test('maybe', function (t) { | ||
t.plan(1); | ||
t.ok(bindings.test()); | ||
}); |