Skip to content

Commit

Permalink
fix arraybuffer polyfill to not error in ie8
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeChampion committed Dec 8, 2021
1 parent 372d401 commit 95d1b47
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions polyfills/ArrayBuffer/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ samsung_mob = "<2"
[install]
module = "js-polyfills"
paths = [ "typedarray.js" ]
postinstall = "update.task.js"
25 changes: 25 additions & 0 deletions polyfills/ArrayBuffer/patch.jsdiff
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/polyfills/ArrayBuffer/polyfill.js b/polyfills/ArrayBuffer/polyfill.js
index a4295ebf..4d6f1441 100644
--- a/polyfills/ArrayBuffer/polyfill.js
+++ b/polyfills/ArrayBuffer/polyfill.js
@@ -117,12 +117,14 @@
if (obj.length > MAX_ARRAY_LENGTH) throw RangeError('Array too large for polyfill');

function makeArrayAccessor(index) {
- Object.defineProperty(obj, index, {
- 'get': function() { return obj._getter(index); },
- 'set': function(v) { obj._setter(index, v); },
- enumerable: true,
- configurable: false
- });
+ try {
+ Object.defineProperty(obj, index, {
+ 'get': function() { return obj._getter(index); },
+ 'set': function(v) { obj._setter(index, v); },
+ enumerable: true,
+ configurable: false
+ });
+ } catch (_){ }
}

var i;
15 changes: 15 additions & 0 deletions polyfills/ArrayBuffer/update.task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-env node */
'use strict';

var fs = require('graceful-fs');
var diff = require('diff');
var process = require('process');
var path = require('path');

var polyfill = fs.readFileSync(path.join(__dirname, './polyfill.js'), 'utf8');
var patch = fs.readFileSync(path.join(__dirname, './patch.jsdiff'), 'utf8');

var patched = diff.applyPatch(polyfill, patch);

if (patched === false) {process.exit(1);}
fs.writeFileSync(path.join(__dirname, './polyfill.js'), patched);

0 comments on commit 95d1b47

Please sign in to comment.