mirror of https://github.com/lukechilds/node.git
Browse Source
PR-URL: https://github.com/nodejs/node/pull/15343 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>canary-base
committed by
Michael Dawson
20 changed files with 141 additions and 30 deletions
@ -0,0 +1,8 @@ |
|||
'use strict'; |
|||
const common = require('../../common'); |
|||
const assert = require('assert'); |
|||
|
|||
// Testing api calls for a constructor that defines properties
|
|||
const TestConstructor = |
|||
require(`./build/${common.buildType}/test_constructor_name`); |
|||
assert.strictEqual(TestConstructor.name, 'MyObject'); |
@ -0,0 +1,23 @@ |
|||
#include <node_api.h> |
|||
#include "../common.h" |
|||
|
|||
napi_ref constructor_; |
|||
|
|||
napi_value New(napi_env env, napi_callback_info info) { |
|||
napi_value _this; |
|||
NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &_this, NULL)); |
|||
|
|||
return _this; |
|||
} |
|||
|
|||
napi_value Init(napi_env env, napi_value exports) { |
|||
napi_value cons; |
|||
NAPI_CALL(env, napi_define_class( |
|||
env, "MyObject_Extra", 8, New, NULL, 0, NULL, &cons)); |
|||
|
|||
NAPI_CALL(env, |
|||
napi_create_reference(env, cons, 1, &constructor_)); |
|||
return cons; |
|||
} |
|||
|
|||
NAPI_MODULE(addon, Init) |
@ -0,0 +1,18 @@ |
|||
'use strict'; |
|||
const common = require('../../common'); |
|||
const assert = require('assert'); |
|||
const child_process = require('child_process'); |
|||
const test_fatal = require(`./build/${common.buildType}/test_fatal`); |
|||
|
|||
// Test in a child process because the test code will trigger a fatal error
|
|||
// that crashes the process.
|
|||
if (process.argv[2] === 'child') { |
|||
test_fatal.TestStringLength(); |
|||
return; |
|||
} |
|||
|
|||
const p = child_process.spawnSync( |
|||
process.execPath, [ '--napi-modules', __filename, 'child' ]); |
|||
assert.ifError(p.error); |
|||
assert.ok(p.stderr.toString().includes( |
|||
'FATAL ERROR: test_fatal::Test fatal message')); |
Loading…
Reference in new issue