[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var test = require('tape');
|
---|
| 4 |
|
---|
| 5 | var callBound = require('../callBound');
|
---|
| 6 |
|
---|
| 7 | test('callBound', function (t) {
|
---|
| 8 | // static primitive
|
---|
| 9 | t.equal(callBound('Array.length'), Array.length, 'Array.length yields itself');
|
---|
| 10 | t.equal(callBound('%Array.length%'), Array.length, '%Array.length% yields itself');
|
---|
| 11 |
|
---|
| 12 | // static non-function object
|
---|
| 13 | t.equal(callBound('Array.prototype'), Array.prototype, 'Array.prototype yields itself');
|
---|
| 14 | t.equal(callBound('%Array.prototype%'), Array.prototype, '%Array.prototype% yields itself');
|
---|
| 15 | t.equal(callBound('Array.constructor'), Array.constructor, 'Array.constructor yields itself');
|
---|
| 16 | t.equal(callBound('%Array.constructor%'), Array.constructor, '%Array.constructor% yields itself');
|
---|
| 17 |
|
---|
| 18 | // static function
|
---|
| 19 | t.equal(callBound('Date.parse'), Date.parse, 'Date.parse yields itself');
|
---|
| 20 | t.equal(callBound('%Date.parse%'), Date.parse, '%Date.parse% yields itself');
|
---|
| 21 |
|
---|
| 22 | // prototype primitive
|
---|
| 23 | t.equal(callBound('Error.prototype.message'), Error.prototype.message, 'Error.prototype.message yields itself');
|
---|
| 24 | t.equal(callBound('%Error.prototype.message%'), Error.prototype.message, '%Error.prototype.message% yields itself');
|
---|
| 25 |
|
---|
| 26 | // prototype function
|
---|
| 27 | t.notEqual(callBound('Object.prototype.toString'), Object.prototype.toString, 'Object.prototype.toString does not yield itself');
|
---|
| 28 | t.notEqual(callBound('%Object.prototype.toString%'), Object.prototype.toString, '%Object.prototype.toString% does not yield itself');
|
---|
| 29 | t.equal(callBound('Object.prototype.toString')(true), Object.prototype.toString.call(true), 'call-bound Object.prototype.toString calls into the original');
|
---|
| 30 | t.equal(callBound('%Object.prototype.toString%')(true), Object.prototype.toString.call(true), 'call-bound %Object.prototype.toString% calls into the original');
|
---|
| 31 |
|
---|
| 32 | t['throws'](
|
---|
| 33 | function () { callBound('does not exist'); },
|
---|
| 34 | SyntaxError,
|
---|
| 35 | 'nonexistent intrinsic throws'
|
---|
| 36 | );
|
---|
| 37 | t['throws'](
|
---|
| 38 | function () { callBound('does not exist', true); },
|
---|
| 39 | SyntaxError,
|
---|
| 40 | 'allowMissing arg still throws for unknown intrinsic'
|
---|
| 41 | );
|
---|
| 42 |
|
---|
| 43 | t.test('real but absent intrinsic', { skip: typeof WeakRef !== 'undefined' }, function (st) {
|
---|
| 44 | st['throws'](
|
---|
| 45 | function () { callBound('WeakRef'); },
|
---|
| 46 | TypeError,
|
---|
| 47 | 'real but absent intrinsic throws'
|
---|
| 48 | );
|
---|
| 49 | st.equal(callBound('WeakRef', true), undefined, 'allowMissing arg avoids exception');
|
---|
| 50 | st.end();
|
---|
| 51 | });
|
---|
| 52 |
|
---|
| 53 | t.end();
|
---|
| 54 | });
|
---|