Skip to content

Commit 35d9d66

Browse files
JckXiamhdawson
authored andcommitted
test: add test covg for handle and escapehandle scopes
PR-URL: #1263 Reviewed-By: Michael Dawson <[email protected]
1 parent 0213134 commit 35d9d66

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

test/handlescope.cc

+26
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ Value createScope(const CallbackInfo& info) {
1313
return String::New(info.Env(), "scope");
1414
}
1515

16+
Value createScopeFromExisting(const CallbackInfo& info) {
17+
{
18+
napi_handle_scope scope;
19+
napi_open_handle_scope(info.Env(), &scope);
20+
HandleScope scope_existing(info.Env(), scope);
21+
String::New(scope_existing.Env(), "inner-existing-scope");
22+
}
23+
return String::New(info.Env(), "existing_scope");
24+
}
25+
1626
Value escapeFromScope(const CallbackInfo& info) {
1727
Value result;
1828
{
@@ -22,6 +32,18 @@ Value escapeFromScope(const CallbackInfo& info) {
2232
return result;
2333
}
2434

35+
Value escapeFromExistingScope(const CallbackInfo& info) {
36+
Value result;
37+
{
38+
napi_escapable_handle_scope scope;
39+
napi_open_escapable_handle_scope(info.Env(), &scope);
40+
EscapableHandleScope scope_existing(info.Env(), scope);
41+
result = scope_existing.Escape(
42+
String::New(scope_existing.Env(), "inner-existing-scope"));
43+
}
44+
return result;
45+
}
46+
2547
#define LOOP_MAX 1000000
2648
Value stressEscapeFromScope(const CallbackInfo& info) {
2749
Value result;
@@ -52,7 +74,11 @@ Object InitHandleScope(Env env) {
5274
Object exports = Object::New(env);
5375

5476
exports["createScope"] = Function::New(env, createScope);
77+
exports["createScopeFromExisting"] =
78+
Function::New(env, createScopeFromExisting);
5579
exports["escapeFromScope"] = Function::New(env, escapeFromScope);
80+
exports["escapeFromExistingScope"] =
81+
Function::New(env, escapeFromExistingScope);
5682
exports["stressEscapeFromScope"] = Function::New(env, stressEscapeFromScope);
5783
exports["doubleEscapeFromScope"] = Function::New(env, doubleEscapeFromScope);
5884

test/handlescope.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ module.exports = require('./common').runTest(test);
66

77
function test (binding) {
88
assert.strictEqual(binding.handlescope.createScope(), 'scope');
9+
assert.strictEqual(binding.handlescope.createScopeFromExisting(), 'existing_scope');
910
assert.strictEqual(binding.handlescope.escapeFromScope(), 'inner-scope');
11+
assert.strictEqual(binding.handlescope.escapeFromExistingScope(), 'inner-existing-scope');
1012
assert.strictEqual(binding.handlescope.stressEscapeFromScope(), 'inner-scope999999');
1113
assert.throws(() => binding.handlescope.doubleEscapeFromScope(),
1214
Error,

0 commit comments

Comments
 (0)