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');
3033const addon = require ( `./build/${ common . buildType } /test_general` ) ;
3134const 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
6342function 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
8766TestChains ( ) ;
8867
89-
9068function 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
122102TestExceptions ( ) ;
0 commit comments