Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Safely call defineProperty when setting array length. #273

Merged
merged 3 commits into from
Apr 20, 2017
Merged

Safely call defineProperty when setting array length. #273

merged 3 commits into from
Apr 20, 2017

Conversation

spencercarnage
Copy link
Contributor

Ran into this error on FF 20 so I figured we could wrap it in a try catch so allow for more tolerant browsers to take advantage of it while keeping those that do not from failing completely. If there is another preferred strategy for handling it, I'm more than happy to implement it. Thanks!

Older browsers, such as Firefox 22 and below, throw `new InternalError("defining the length property on an array is not currently supported")` when trying to set the length with `defineProperty` so a try catch will allow for those that do support it to use it, while those that don't fail due to the error.
wrap setting array length in try catch
// "Freeze" the array so no new elements can be added
defineProperty(subset, 'length', { writable: false });

// Wrap in try catch for older browsers that don't support setting length of
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reference in the spec about this particular operation (https://tc39.github.io/ecma402/#sec-supportedlocales), maybe we can just remove it all together. Not sure why was it added.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try running the unit tests with this operation removed. If everything passes, we can remove it. Otherwise I will be fine with the try/catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the lint errors and ran the tests. All of the unit tests passed but I did get a failure when trying to run Sauce Labs.

throw new Error('Could not start Sauce Tunnel');

More than happy to update my MR or implement an alternative.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's fine, that's saucelab script. Update the PR and I will merge it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caridy updated.

Copy link
Collaborator

@caridy caridy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considering another alternative...

@caridy caridy merged commit e93b114 into andyearnshaw:master Apr 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants