Skip to content

Execute the IE TypedArray polyfill directly #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

@jamesdbrock Bugfix for purs bundle 0.14.4. https://github.com/purescript-contrib/purescript-arraybuffer/issues/34

## v11.0.0

Jorge Acereda has graciously donated this package to __purescript-contrib__.
Expand Down
23 changes: 13 additions & 10 deletions src/Data/ArrayBuffer/Typed.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
"use strict";



// Lightweight polyfill for ie - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Methods_Polyfill
function polyFill () {
var typedArrayTypes =
// Lightweight polyfill for IE
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Methods_Polyfill
//
// Can we trust that this FFI code gets called exactly once? I think so, but
// I can't find a reference for that.
{
// var is not block scoped, but there is no way to scope this block inside
// a function in such a way that the function will not be dead-code-eliminated.
// https://github.com/purescript-contrib/purescript-arraybuffer/issues/34
var _typedArrayTypes =
[ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array
, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array
];

for (var k in typedArrayTypes) {
for (var k in _typedArrayTypes) {
for (var v in Array.prototype) {
if (Array.prototype.hasOwnProperty(v) && !typedArrayTypes[k].prototype.hasOwnProperty(v))
typedArrayTypes[k].prototype[v] = Array.prototype[v];
if (Array.prototype.hasOwnProperty(v) && !_typedArrayTypes[k].prototype.hasOwnProperty(v))
_typedArrayTypes[k].prototype[v] = Array.prototype[v];
}
}
};

polyFill();

// module Data.ArrayBuffer.Typed

exports.buffer = function buffer (v) {
Expand Down
1 change: 1 addition & 0 deletions src/Data/ArrayBuffer/Typed.purs
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,4 @@ compare a b = Prelude.compare <$> toArray a <*> toArray b
-- | Equality test for typed arrays.
eq :: forall a t. TypedArray a t => Eq t => ArrayView a -> ArrayView a -> Effect Boolean
eq a b = Prelude.eq <$> toArray a <*> toArray b