8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cd30154 commit 4827421Copy full SHA for 4827421
test/addons-napi/test_general/testInstanceOf.js
@@ -9,6 +9,11 @@ const assert = require('assert');
9
const addon = require(`./build/${common.buildType}/test_general`);
10
const path = require('path');
11
12
+// This test depends on a number of V8 tests.
13
+const v8TestsDir = path.resolve(__dirname, '..', '..', '..', 'deps', 'v8',
14
+ 'test', 'mjsunit');
15
+const v8TestsDirExists = fs.existsSync(v8TestsDir);
16
+
17
// The following assert functions are referenced by v8's unit tests
18
// See for instance deps/v8/test/mjsunit/instanceof.js
19
// eslint-disable-next-line no-unused-vars
@@ -34,27 +39,30 @@ function assertThrows(statement) {
34
39
}
35
40
36
41
function testFile(fileName) {
37
- const contents = fs.readFileSync(fileName, { encoding: 'utf8' });
38
- eval(contents.replace(/[(]([^\s(]+)\s+instanceof\s+([^)]+)[)]/g,
- '(addon.doInstanceOf($1, $2))'));
42
+ try {
43
+ const contents = fs.readFileSync(fileName, { encoding: 'utf8' });
44
+ eval(contents.replace(/[(]([^\s(]+)\s+instanceof\s+([^)]+)[)]/g,
45
+ '(addon.doInstanceOf($1, $2))'));
46
+ } catch (err) {
47
+ // This test depends on V8 test files, which may not exist in downloaded
48
+ // archives. Emit a warning if the tests cannot be found instead of failing.
49
+ if (err.code === 'ENOENT' && !v8TestsDirExists)
50
+ process.emitWarning(`test file ${fileName} does not exist.`);
51
+ else
52
+ throw err;
53
+ }
54
55
-testFile(
- path.join(path.resolve(__dirname, '..', '..', '..',
- 'deps', 'v8', 'test', 'mjsunit'),
- 'instanceof.js'));
- 'instanceof-2.js'));
56
+testFile(path.join(v8TestsDir, 'instanceof.js'));
57
+testFile(path.join(v8TestsDir, 'instanceof-2.js'));
58
59
// We can only perform this test if we have a working Symbol.hasInstance
60
if (typeof Symbol !== 'undefined' && 'hasInstance' in Symbol &&
61
typeof Symbol.hasInstance === 'symbol') {
62
63
function compareToNative(theObject, theConstructor) {
64
assert.strictEqual(addon.doInstanceOf(theObject, theConstructor),
- (theObject instanceof theConstructor));
65
+ (theObject instanceof theConstructor));
66
67
68
function MyClass() {}