Skip to content

Commit 554823c

Browse files
committed
[Fix] node < 0.11 has an own nonconfigurable slice property; use it
- node < 0.9 has no `slice` function at all
1 parent 4966b02 commit 554823c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"rules": {
77
"id-length": 0,
8+
"max-params": 0,
89
"max-statements": 0,
910
"multiline-comment-style": 0,
1011
"new-cap": [2, {

polyfill.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
'use strict';
22

3+
var callBind = require('call-bind');
4+
35
var implementation = require('./implementation');
46

7+
var ownSlice = typeof ArrayBuffer === 'function' && new ArrayBuffer(0).slice;
8+
var ownSliceBound = ownSlice && callBind(ownSlice);
9+
var ownSliceWrapper = ownSliceBound && function slice(start, end) {
10+
/* eslint no-invalid-this: 0 */
11+
if (arguments.length < 2) {
12+
return ownSliceBound(this, arguments.length > 0 ? start : 0);
13+
}
14+
return ownSliceBound(this, start, end);
15+
};
16+
517
module.exports = function getPolyfill() {
6-
return (typeof ArrayBuffer === 'function' && ArrayBuffer.prototype.slice) || implementation;
18+
return (typeof ArrayBuffer === 'function' && ArrayBuffer.prototype.slice)
19+
|| ownSliceWrapper
20+
|| implementation;
721
};

0 commit comments

Comments
 (0)