Skip to content

Commit c3de100

Browse files
committed
use Node.js assert API directly
1 parent 1bd8b19 commit c3de100

File tree

2 files changed

+28
-53
lines changed

2 files changed

+28
-53
lines changed
Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This test is adopted from V8's test suite.
2+
// See deps/v8/test/mjsunit/instanceof.js in Node.js source repository.
3+
//
14
// Copyright 2008 the V8 project authors. All rights reserved.
25
// Redistribution and use in source and binary forms, with or without
36
// modification, are permitted provided that the following conditions are
@@ -30,35 +33,11 @@ const common = require('../../common');
3033
const addon = require(`./build/${common.buildType}/test_general`);
3134
const assert = require('assert');
3235

33-
// The following assert functions are referenced by v8's unit tests
34-
// See for instance deps/v8/test/mjsunit/instanceof.js
35-
36-
function assertTrue(assertion) {
37-
return assert.strictEqual(assertion, true);
38-
}
39-
40-
41-
function assertFalse(assertion) {
42-
assert.strictEqual(assertion, false);
43-
}
44-
45-
46-
function assertEquals(leftHandSide, rightHandSide) {
47-
assert.strictEqual(leftHandSide, rightHandSide);
48-
}
49-
50-
51-
function assertThrows(statement) {
52-
assert.throws(function() {
53-
eval(statement);
54-
}, Error);
55-
}
36+
assert.ok(addon.doInstanceOf({}, Object));
37+
assert.ok(addon.doInstanceOf([], Object));
5638

57-
assertTrue(addon.doInstanceOf({}, Object));
58-
assertTrue(addon.doInstanceOf([], Object));
59-
60-
assertFalse(addon.doInstanceOf({}, Array));
61-
assertTrue(addon.doInstanceOf([], Array));
39+
assert.ok(!addon.doInstanceOf({}, Array));
40+
assert.ok(addon.doInstanceOf([], Array));
6241

6342
function TestChains() {
6443
const A = {};
@@ -69,24 +48,23 @@ function TestChains() {
6948

7049
function F() { }
7150
F.prototype = A;
72-
assertTrue(addon.doInstanceOf(C, F));
73-
assertTrue(addon.doInstanceOf(B, F));
74-
assertFalse(addon.doInstanceOf(A, F));
51+
assert.ok(addon.doInstanceOf(C, F));
52+
assert.ok(addon.doInstanceOf(B, F));
53+
assert.ok(!addon.doInstanceOf(A, F));
7554

7655
F.prototype = B;
77-
assertTrue(addon.doInstanceOf(C, F));
78-
assertFalse(addon.doInstanceOf(B, F));
79-
assertFalse(addon.doInstanceOf(A, F));
56+
assert.ok(addon.doInstanceOf(C, F));
57+
assert.ok(!addon.doInstanceOf(B, F));
58+
assert.ok(!addon.doInstanceOf(A, F));
8059

8160
F.prototype = C;
82-
assertFalse(addon.doInstanceOf(C, F));
83-
assertFalse(addon.doInstanceOf(B, F));
84-
assertFalse(addon.doInstanceOf(A, F));
61+
assert.ok(!addon.doInstanceOf(C, F));
62+
assert.ok(!addon.doInstanceOf(B, F));
63+
assert.ok(!addon.doInstanceOf(A, F));
8564
}
8665

8766
TestChains();
8867

89-
9068
function TestExceptions() {
9169
function F() { }
9270
const items = [ 1, new Number(42),
@@ -104,19 +82,21 @@ function TestExceptions() {
10482
try {
10583
if (addon.doInstanceOf(items[i], items[j])) instanceofs++;
10684
} catch (e) {
107-
assertTrue(addon.doInstanceOf(e, TypeError));
85+
assert.ok(addon.doInstanceOf(e, TypeError));
10886
exceptions++;
10987
}
11088
}
11189
}
112-
assertEquals(10, instanceofs);
113-
assertEquals(88, exceptions);
90+
assert.strictEqual(instanceofs, 10);
91+
assert.strictEqual(exceptions, 88);
11492

11593
// Make sure to throw an exception if the function prototype
11694
// isn't a proper JavaScript object.
11795
function G() { }
11896
G.prototype = undefined;
119-
assertThrows('addon.doInstanceOf({}, G)');
97+
assert.throws(function() {
98+
addon.doInstanceOf({}, G);
99+
}, Error);
120100
}
121101

122102
TestExceptions();

test/js-native-api/test_general/testV8Instanceof2.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This test is adopted from V8's test suite.
2+
// See deps/v8/test/mjsunit/instanceof-2.js in Node.js source repository.
3+
//
14
// Copyright 2010 the V8 project authors. All rights reserved.
25
// Redistribution and use in source and binary forms, with or without
36
// modification, are permitted provided that the following conditions are
@@ -30,14 +33,6 @@ const common = require('../../common');
3033
const addon = require(`./build/${common.buildType}/test_general`);
3134
const assert = require('assert');
3235

33-
function assertTrue(assertion) {
34-
return assert.strictEqual(assertion, true);
35-
}
36-
37-
function assertEquals(leftHandSide, rightHandSide) {
38-
assert.strictEqual(leftHandSide, rightHandSide);
39-
}
40-
4136
const except = 'exception';
4237

4338
let correct_answer_index = 0;
@@ -307,10 +302,10 @@ for (let i = 0; i < 256; i++) {
307302
function InstanceTest(x, func) {
308303
try {
309304
const answer = addon.doInstanceOf(x, func);
310-
assertEquals(correct_answers[correct_answer_index], answer);
305+
assert.strictEqual(correct_answers[correct_answer_index], answer);
311306
} catch (e) {
312-
assertTrue(/prototype/.test(e));
313-
assertEquals(correct_answers[correct_answer_index], except);
307+
assert.ok(/prototype/.test(e));
308+
assert.strictEqual(correct_answers[correct_answer_index], except);
314309
}
315310
correct_answer_index++;
316311
}

0 commit comments

Comments
 (0)