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(core): panic on big string allocation #7395

Merged
merged 3 commits into from
Sep 9, 2020

Conversation

bartlomieju
Copy link
Member

Fixes #6649

@bartlomieju bartlomieju changed the title fix: panic on big string allocation fix(core): panic on big string allocation Sep 8, 2020
Copy link
Member

@piscisaureus piscisaureus left a comment

Choose a reason for hiding this comment

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

Hmmm

Good to see this fixed but IMO returning an empty string is a really weird response - why not throw a RangeTypeError?

I actually wonder if this might be a bug in Chrome rather than intentional behavior. I could see that happen because of a weird quirk in the v8 api, which is that when a V8 API function returns an empty MaybeLocal this always means a JS exception was thrown. With one exception: v8::String::new() can also return an empy MaybeLocal but in that case it just means the string was too long.

@piscisaureus
Copy link
Member

piscisaureus commented Sep 8, 2020

@bartlomieju
Copy link
Member Author

Hmmm

Good to see this fixed but IMO returning an empty string is a really weird response - why not throw a RangeTypeError?

I actually wonder if this might be a bug in Chrome rather than intentional behavior. I could see that happen because of a weird quirk in the v8 api, which is that when a V8 API function returns an empty MaybeLocal this always means a JS exception was thrown. With one exception: v8::String::new() can also return an empy MaybeLocal but in that case it just means the string was too long.

Spec: https://encoding.spec.whatwg.org/#dom-textdecoder-decode

@piscisaureus thanks for pointing this, indeed spec suggests to use TypeError. I think it's better solution that silently ignoring the error and returning empty string. I've updated the PR.

Copy link
Member

@piscisaureus piscisaureus left a comment

Choose a reason for hiding this comment

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

Had a change of heart, switched it to RangeError after all, and made some minor tweaks to the doc comment.
Now it looks good to me.

@bartlomieju bartlomieju merged commit 25053f9 into denoland:master Sep 9, 2020
@bartlomieju bartlomieju deleted the fix_big_string_allocation branch September 9, 2020 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

thread 'main' panicked on TextDecoder().decode()
2 participants