Skip to content

Commit

Permalink
[Fix] shim: properly install when already present
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed May 5, 2022
1 parent 4f54d5e commit f580b50
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
10 changes: 5 additions & 5 deletions shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ var define = require('define-properties');

module.exports = function shimObjectHasOwn() {
var polyfill = getPolyfill();
define(Object, { hasOwn: polyfill }, {
values: function testObjectHasOwn() {
return Object.hasOwn !== polyfill;
}
});
define(
Object,
{ hasOwn: polyfill },
{ hasOwn: function () { return Object.hasOwn !== polyfill; } }
);
return polyfill;
};
10 changes: 2 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
'use strict';

var hasOwn = require('../');
var index = require('../');
var test = require('tape');
var runTests = require('./tests');

test('as a function', function (t) {
t.test('bad array/this value', function (st) {
st['throws'](function () { hasOwn(undefined); }, TypeError, 'undefined is not an object');
st['throws'](function () { hasOwn(null); }, TypeError, 'null is not an object');
st.end();
});

runTests(hasOwn, t);
runTests(index, t);

t.end();
});
8 changes: 4 additions & 4 deletions test/index.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import parseInt, * as parseIntModule from 'object.hasown';
import index, * as Module from 'object.hasown';
import test from 'tape';
import runTests from './tests.js';

test('as a function', (t) => {
runTests(parseInt, t);
runTests(index, t);

t.end();
});

test('named exports', async (t) => {
t.deepEqual(
Object.keys(parseIntModule).sort(),
Object.keys(Module).sort(),
['default', 'shim', 'getPolyfill', 'implementation'].sort(),
'has expected named exports',
);

const { shim, getPolyfill, implementation } = parseIntModule;
const { shim, getPolyfill, implementation } = Module;
t.equal((await import('object.hasown/shim')).default, shim, 'shim named export matches deep export');
t.equal((await import('object.hasown/implementation')).default, implementation, 'implementation named export matches deep export');
t.equal((await import('object.hasown/polyfill')).default, getPolyfill, 'getPolyfill named export matches deep export');
Expand Down

0 comments on commit f580b50

Please sign in to comment.