Closed Bug 1542462 Opened 5 years ago Closed 5 years ago

Make JS::CompileFunction handle both UTF-8 and UTF-16

Categories

(Core :: JavaScript Engine, task)

task
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla68
Tracking Status
firefox68 --- fixed

People

(Reporter: Waldo, Assigned: Waldo)

Details

Attachments

(2 files)

Right now JS::CompileFunction only handles UTF-16, and there's a separate JS::CompileFunctionUtf8 to handle UTF-8. There really ought be two identically-named overloads that differ only in the type of a SourceText<Unit>& srcBuf argument.

My initial aim here was -- because JS::CompileFunctionUtf8 is only used by test code -- to make it directly handle UTF-8 without inflating. Unfortunately, after I'd dived in some, I realized the guts of the algorithm currently revolve around consing up function syntax into a StringBuilder forced into ensureTwoByteChars(). While this can be fixed, it gets a little messy -- because then you need a builder-like thing for UTF-8 if you really are going to have a fully UTF-8 string at the end. And StringBuilder is mostly supposed to hide its internal encoding -- it's just a thing to let you create JS strings, and it doesn't have a way to forcibly constrain its contents to be UTF-8 data only.

So for now, just rejigger the algorithm so that at least copying the function body into that StringBuilder is the only part of the algorithm not shared by both JS::CompileFunction overloads, at end of day. Maybe sometime there'll be a StringBuilder with fixed encoding that we can use to make this never need to use UTF-16, but for now, eh.

Pushed by jwalden@mit.edu:
https://hg.mozilla.org/integration/autoland/rev/832f2c3814d3
Rename JS::CompileFunctionUtf8 to JS::CompileFunction, and make it take JS::SourceText<mozilla::Utf8Unit>.  r=arai
https://hg.mozilla.org/integration/autoland/rev/b91d37d3c813
Implement both JS::CompileFunction (for UTF-8 and UTF-16) in clearer fashion, and don't prematurely inflate the user-provided function body source.  r=arai
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: