Skip to content

Commit 790de9f

Browse files
Gabriel Schulhofmhdawson
authored andcommitted
Use old-style functions and use safe-buffer
* err => {} notation doesn't work on Node 4. * Use Buffer.alloc polyfill from safe-buffer PR-URL: #122 Fixes: #120 Reviewed-By: Michael Dawson <[email protected]>
1 parent a870338 commit 790de9f

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
],
1616
"dependencies": {},
1717
"description": "Node.js API (N-API)",
18-
"devDependencies": {},
18+
"devDependencies": {
19+
"safe-buffer": "^5.1.1"
20+
},
1921
"directories": {},
2022
"homepage": "https://github.com/nodejs/node-addon-api",
2123
"license": "MIT",

test/buffer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const buildType = process.config.target_defaults.default_configuration;
33
const assert = require('assert');
44
const testUtil = require('./testUtil');
5+
const safeBuffer = require('safe-buffer');
56

67
test(require(`./build/${buildType}/binding.node`));
78
test(require(`./build/${buildType}/binding_noexcept.node`));
@@ -14,7 +15,7 @@ function test(binding) {
1415
binding.buffer.checkBuffer(test);
1516
assert.ok(test instanceof Buffer);
1617

17-
const test2 = Buffer.alloc(test.length);
18+
const test2 = safeBuffer.Buffer.alloc(test.length);
1819
test.copy(test2);
1920
binding.buffer.checkBuffer(test2);
2021
},

test/error.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ test(`./build/${buildType}/binding_noexcept.node`);
1414
function test(bindingPath) {
1515
const binding = require(bindingPath);
1616

17-
assert.throws(() => binding.error.throwApiError('test'), err => {
17+
assert.throws(() => binding.error.throwApiError('test'), function(err) {
1818
return err instanceof Error && err.message.includes('Invalid');
1919
});
2020

21-
assert.throws(() => binding.error.throwJSError('test'), err => {
21+
assert.throws(() => binding.error.throwJSError('test'), function(err) {
2222
return err instanceof Error && err.message === 'test';
2323
});
2424

25-
assert.throws(() => binding.error.throwTypeError('test'), err => {
25+
assert.throws(() => binding.error.throwTypeError('test'), function(err) {
2626
return err instanceof TypeError && err.message === 'test';
2727
});
2828

29-
assert.throws(() => binding.error.throwRangeError('test'), err => {
29+
assert.throws(() => binding.error.throwRangeError('test'), function(err) {
3030
return err instanceof RangeError && err.message === 'test';
3131
});
3232

@@ -35,7 +35,7 @@ function test(bindingPath) {
3535
() => {
3636
throw new TypeError('test');
3737
}),
38-
err => {
38+
function(err) {
3939
return err instanceof TypeError && err.message === 'test' && !err.caught;
4040
});
4141

@@ -44,7 +44,7 @@ function test(bindingPath) {
4444
() => {
4545
throw new TypeError('test');
4646
}),
47-
err => {
47+
function(err) {
4848
return err instanceof TypeError && err.message === 'test' && err.caught;
4949
});
5050

@@ -57,11 +57,11 @@ function test(bindingPath) {
5757
() => { throw new TypeError('test'); });
5858
assert.strictEqual(msg, 'test');
5959

60-
assert.throws(() => binding.error.throwErrorThatEscapesScope('test'), err => {
60+
assert.throws(() => binding.error.throwErrorThatEscapesScope('test'), function(err) {
6161
return err instanceof Error && err.message === 'test';
6262
});
6363

64-
assert.throws(() => binding.error.catchAndRethrowErrorThatEscapesScope('test'), err => {
64+
assert.throws(() => binding.error.catchAndRethrowErrorThatEscapesScope('test'), function(err) {
6565
return err instanceof Error && err.message === 'test' && err.caught;
6666
});
6767

0 commit comments

Comments
 (0)