|
12 | 12 | using namespace Nan; // NOLINT(build/namespaces)
|
13 | 13 |
|
14 | 14 | static Persistent<v8::String> persistentTest1;
|
| 15 | +static Persistent<v8::String> persistentTest2; |
15 | 16 |
|
16 | 17 | NAN_METHOD(Save1) {
|
17 | 18 | persistentTest1.Reset(info[0].As<v8::String>());
|
@@ -55,6 +56,39 @@ NAN_METHOD(PassGlobal) {
|
55 | 56 | info.GetReturnValue().Set(passer(New(42)));
|
56 | 57 | }
|
57 | 58 |
|
| 59 | +NAN_METHOD(EmptyPersistent) { |
| 60 | + persistentTest2.Reset(New("value").ToLocalChecked()); |
| 61 | + bool b1 = !persistentTest2.IsEmpty(); |
| 62 | + persistentTest2.Empty(); // this will leak, never do it |
| 63 | + info.GetReturnValue().Set(b1 && persistentTest2.IsEmpty()); |
| 64 | +} |
| 65 | + |
| 66 | +NAN_METHOD(EmptyGlobal) { |
| 67 | + Global<v8::String> g(New("value").ToLocalChecked()); |
| 68 | + bool b1 = !g.IsEmpty(); |
| 69 | + g.Empty(); // this will leak, never do it |
| 70 | + info.GetReturnValue().Set(b1 && g.IsEmpty()); |
| 71 | +} |
| 72 | + |
| 73 | +NAN_METHOD(MoveConstructGlobal) { |
| 74 | + Global<v8::String> g(Global<v8::String>(New("value").ToLocalChecked())); |
| 75 | + info.GetReturnValue().Set(!g.IsEmpty()); |
| 76 | +} |
| 77 | + |
| 78 | +NAN_METHOD(CopyConstructGlobal) { |
| 79 | + Persistent<v8::String> p(New("value").ToLocalChecked()); |
| 80 | + bool b1 = !p.IsEmpty(); |
| 81 | + Global<v8::String> g(p); |
| 82 | + bool b2 = !p.IsEmpty(); |
| 83 | + p.Reset(); |
| 84 | + info.GetReturnValue().Set(b1 && b2 && !g.IsEmpty()); |
| 85 | +} |
| 86 | + |
| 87 | +NAN_METHOD(MoveAssignGlobal) { |
| 88 | + Global<v8::String> g = passer(New("value").ToLocalChecked()); |
| 89 | + info.GetReturnValue().Set(!g.IsEmpty()); |
| 90 | +} |
| 91 | + |
58 | 92 | NAN_MODULE_INIT(Init) {
|
59 | 93 | Set(target
|
60 | 94 | , New<v8::String>("save1").ToLocalChecked()
|
@@ -88,6 +122,31 @@ NAN_MODULE_INIT(Init) {
|
88 | 122 | , GetFunction(New<v8::FunctionTemplate>(PassGlobal))
|
89 | 123 | .ToLocalChecked()
|
90 | 124 | );
|
| 125 | + Set(target |
| 126 | + , New<v8::String>("emptyPersistent").ToLocalChecked() |
| 127 | + , GetFunction(New<v8::FunctionTemplate>(EmptyPersistent)) |
| 128 | + .ToLocalChecked() |
| 129 | + ); |
| 130 | + Set(target |
| 131 | + , New<v8::String>("emptyGlobal").ToLocalChecked() |
| 132 | + , GetFunction(New<v8::FunctionTemplate>(EmptyGlobal)) |
| 133 | + .ToLocalChecked() |
| 134 | + ); |
| 135 | + Set(target |
| 136 | + , New<v8::String>("moveConstructGlobal").ToLocalChecked() |
| 137 | + , GetFunction(New<v8::FunctionTemplate>(MoveConstructGlobal)) |
| 138 | + .ToLocalChecked() |
| 139 | + ); |
| 140 | + Set(target |
| 141 | + , New<v8::String>("copyConstructGlobal").ToLocalChecked() |
| 142 | + , GetFunction(New<v8::FunctionTemplate>(CopyConstructGlobal)) |
| 143 | + .ToLocalChecked() |
| 144 | + ); |
| 145 | + Set(target |
| 146 | + , New<v8::String>("moveAssignGlobal").ToLocalChecked() |
| 147 | + , GetFunction(New<v8::FunctionTemplate>(MoveAssignGlobal)) |
| 148 | + .ToLocalChecked() |
| 149 | + ); |
91 | 150 | }
|
92 | 151 |
|
93 | 152 | NODE_MODULE(persistent, Init)
|
0 commit comments