Skip to content

Commit 2e0c2e9

Browse files
committed
[Refactor] use define-data-property and has-property-descriptors directly
1 parent 9499206 commit 2e0c2e9

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@
4848
"dependencies": {
4949
"call-bind": "^1.0.8",
5050
"call-bound": "^1.0.2",
51+
"define-data-property": "^1.1.4",
5152
"define-properties": "^1.2.1",
5253
"es-abstract": "^1.23.5",
53-
"es-object-atoms": "^1.0.0"
54+
"es-object-atoms": "^1.0.0",
55+
"has-property-descriptors": "^1.0.2"
5456
},
5557
"devDependencies": {
5658
"@es-shims/api": "^2.5.1",

shim.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
'use strict';
22

3-
var define = require('define-properties');
3+
var supportsDescriptors = require('has-property-descriptors')();
4+
var defineDataProperty = require('define-data-property');
5+
46
var getPolyfill = require('./polyfill');
57

68
module.exports = function shimStringTrim() {
79
var polyfill = getPolyfill();
8-
define(String.prototype, { trim: polyfill }, {
9-
trim: function testTrim() {
10-
return String.prototype.trim !== polyfill;
10+
11+
if (String.prototype.trim !== polyfill) {
12+
if (supportsDescriptors) {
13+
defineDataProperty(String.prototype, 'trim', polyfill, true);
14+
} else {
15+
defineDataProperty(String.prototype, 'trim', polyfill);
1116
}
12-
});
17+
}
18+
1319
return polyfill;
1420
};

0 commit comments

Comments
 (0)