(binding)
| 9 | }); |
| 10 | |
| 11 | function test (binding) { |
| 12 | assert.strictEqual(binding.emptyConstructor(true), true); |
| 13 | assert.strictEqual(binding.emptyConstructor(false), false); |
| 14 | |
| 15 | let obj = {}; |
| 16 | assert.deepStrictEqual(binding.voidCallback(obj), undefined); |
| 17 | assert.deepStrictEqual(obj, { foo: 'bar' }); |
| 18 | |
| 19 | assert.deepStrictEqual(binding.valueCallback(), { foo: 'bar' }); |
| 20 | |
| 21 | /* eslint-disable-next-line new-cap */ |
| 22 | assert.strictEqual(new binding.newTargetCallback(), binding.newTargetCallback); |
| 23 | assert.strictEqual(binding.newTargetCallback(), undefined); |
| 24 | |
| 25 | let args = null; |
| 26 | let ret = null; |
| 27 | let receiver = null; |
| 28 | function testFunction () { |
| 29 | receiver = this; |
| 30 | args = [].slice.call(arguments); |
| 31 | return ret; |
| 32 | } |
| 33 | function testConstructor () { |
| 34 | args = [].slice.call(arguments); |
| 35 | } |
| 36 | |
| 37 | function makeCallbackTestFunction (receiver, expectedOne, expectedTwo, expectedThree) { |
| 38 | return function callback (one, two, three) { |
| 39 | assert.strictEqual(this, receiver); |
| 40 | assert.strictEqual(one, expectedOne); |
| 41 | assert.strictEqual(two, expectedTwo); |
| 42 | assert.strictEqual(three, expectedThree); |
| 43 | }; |
| 44 | } |
| 45 | |
| 46 | ret = 4; |
| 47 | assert.strictEqual(binding.callWithArgs(testFunction, 1, 2, 3), 4); |
| 48 | assert.strictEqual(receiver, undefined); |
| 49 | assert.deepStrictEqual(args, [1, 2, 3]); |
| 50 | |
| 51 | ret = 5; |
| 52 | assert.strictEqual(binding.callWithVector(testFunction, 2, 3, 4), 5); |
| 53 | assert.strictEqual(receiver, undefined); |
| 54 | assert.deepStrictEqual(args, [2, 3, 4]); |
| 55 | |
| 56 | ret = 5; |
| 57 | assert.strictEqual(binding.callWithVectorUsingCppWrapper(testFunction, 2, 3, 4), 5); |
| 58 | assert.strictEqual(receiver, undefined); |
| 59 | assert.deepStrictEqual(args, [2, 3, 4]); |
| 60 | |
| 61 | ret = 6; |
| 62 | assert.strictEqual(binding.callWithReceiverAndArgs(testFunction, obj, 3, 4, 5), 6); |
| 63 | assert.deepStrictEqual(receiver, obj); |
| 64 | assert.deepStrictEqual(args, [3, 4, 5]); |
| 65 | |
| 66 | ret = 7; |
| 67 | assert.strictEqual(binding.callWithReceiverAndVector(testFunction, obj, 4, 5, 6), 7); |
| 68 | assert.deepStrictEqual(receiver, obj); |
no test coverage detected