GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — node-api: do not crash on module version mismatch · nodejs/node@8d904b4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_api.cc
  • test/node-api/test_module_version_mismatch
    • binding.gyp
    • test.js
    • test_module_version_mismatch.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_api.cc‎

Copy file name to clipboardExpand all lines: src/node_api.cc
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ void napi_module_register_by_symbol(v8::Local<v8::Object> exports,
790790
// Create a new napi_env for this specific module.
791791
napi_env env =
792792
node_napi_env__::New(context, module_filename, module_api_version);
793+
// `module_api_version` is not supported.
794+
if (env == nullptr) return;
793795

794796
napi_value _exports = nullptr;
795797
env->CallIntoModule([&](napi_env env) {
Collapse file

‎test/node-api/test_module_version_mismatch/binding.gyp‎

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'test_module_version_mismatch',
5+
'sources': [ 'test_module_version_mismatch.c' ],
6+
# One below NAPI_VERSION_EXPERIMENTAL, so it is always above
7+
# NODE_API_SUPPORTED_VERSION_MAX and never becomes a real version, but is
8+
# not the experimental value the version check deliberately allows.
9+
'defines': [ 'NAPI_VERSION=2147483646' ]
10+
}
11+
]
12+
}
Collapse file

‎test/node-api/test_module_version_mismatch/test.js‎

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
const common = require('../../common');
3+
const assert = require('assert');
4+
5+
// An add-on that requires a newer Node-API version than this binary supports
6+
// must be rejected with an error that `require()` can catch, rather than
7+
// crashing the process.
8+
assert.throws(
9+
() => require(`./build/${common.buildType}/test_module_version_mismatch`),
10+
/requires Node-API version 2147483646, but this version of Node\.js only supports version \d+ add-ons\./);
Collapse file

‎test/node-api/test_module_version_mismatch/test_module_version_mismatch.c‎

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <node_api.h>
2+
3+
// This add-on declares a Node-API version that no build supports, so loading it
4+
// must fail with an error -- not a crash.
5+
NAPI_MODULE_INIT() {
6+
return exports;
7+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.