Skip to content
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

Fix ArrayBuffer.prototype.byteLength for iOS 10 #203

Merged
merged 1 commit into from Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.js
@@ -1,3 +1,5 @@
import './js/ios10Fix';

import {polyfillGlobal} from 'react-native/Libraries/Utilities/PolyfillFunctions';

import {name, version} from './package.json';
Expand Down
24 changes: 24 additions & 0 deletions js/ios10Fix.js
@@ -0,0 +1,24 @@
/**
* There's a bug happening on iOS 10 where `ArrayBuffer.prototype.byteLength`
* is not defined, but present on the object returned by the function/constructor
* See https://github.com/charpeni/react-native-url-polyfill/issues/190
* */

import {Platform} from 'react-native';

const majorVersionIOS = parseInt(Platform.Version, 10);

if (Platform.OS === 'ios' && majorVersionIOS === 10) {
if (
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength') == null
) {
// eslint-disable-next-line no-extend-native
Object.defineProperty(ArrayBuffer.prototype, 'byteLength', {
configurable: true,
enumerable: false,
get() {
return null;
},
});
}
}