Skip to content

Commit 54ef0fd

Browse files
codebytereBridgeAR
authored andcommitted
test: --force-context-aware cli flag
PR-URL: #29631 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 6bfe8f4 commit 54ef0fd

File tree

6 files changed

+36
-1
lines changed

6 files changed

+36
-1
lines changed

doc/api/cli.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ Silence all process warnings (including deprecations).
444444
added: REPLACEME
445445
-->
446446

447-
Disable loading non-context-aware native addons.
447+
Disable loading native addons that are not [context-aware][].
448448

449449
### `--openssl-config=file`
450450
<!-- YAML
@@ -1293,3 +1293,4 @@ greater than `4` (its current default value). For more information, see the
12931293
[experimental ECMAScript Module]: esm.html#esm_resolve_hook
12941294
[libuv threadpool documentation]: http://docs.libuv.org/en/latest/threadpool.html
12951295
[remote code execution]: https://www.owasp.org/index.php/Code_Injection
1296+
[context-aware]: addons.html#addons_context_aware_addons
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <node.h>
2+
#include <v8.h>
3+
4+
void init(v8::Local<v8::Object> exports) {}
5+
6+
NODE_MODULE(NODE_GYP_MODULE_NAME, init)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'sources': [ 'binding.cc' ],
6+
'includes': ['../common.gypi'],
7+
}
8+
]
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
const common = require('../../common');
3+
4+
require(`./build/${common.buildType}/binding`);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
const common = require('../../common');
3+
const childProcess = require('child_process');
4+
const assert = require('assert');
5+
const path = require('path');
6+
7+
const mod = path.join('test', 'addons', 'force-context-aware', 'index.js');
8+
9+
const execString = `"${process.execPath}" --force-context-aware ./${mod}`;
10+
childProcess.exec(execString, common.mustCall((err) => {
11+
const errMsg = 'Loading non context-aware native modules has been disabled';
12+
assert.strictEqual(err.message.includes(errMsg), true);
13+
}));

test/addons/zlib-binding/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Flags: --force-context-aware
2+
13
'use strict';
24

35
const common = require('../../common');

0 commit comments

Comments
 (0)