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

Use UTF-8 versions of Compile/Execute for scripts #27331

Closed
jdm opened this issue Jul 20, 2020 · 7 comments
Closed

Use UTF-8 versions of Compile/Execute for scripts #27331

jdm opened this issue Jul 20, 2020 · 7 comments

Comments

@jdm
Copy link
Member

@jdm jdm commented Jul 20, 2020

This will avoid having to encode them as UTF-16 first.

@avr1254
Copy link
Contributor

@avr1254 avr1254 commented Jul 25, 2020

@highfive:assignme

@avr1254
Copy link
Contributor

@avr1254 avr1254 commented Jul 25, 2020

@jdm Maybe this would be an interesting challenge to take on!

@atouchet atouchet added the C-assigned label Jul 26, 2020
@avr1254
Copy link
Contributor

@avr1254 avr1254 commented Jul 26, 2020

@jdm Can you tell me a little more about the issue? I'm assuming you don't mean going through every script and changing the encoding to UTF-8.

@jdm
Copy link
Member Author

@jdm jdm commented Jul 27, 2020

@avr1254 In

assert!(CompileOffThread(
*cx,
options.ptr as *const _,
&mut transform_u16_to_source_text(&context.utf16_chars) as *mut _,
Some(off_thread_compilation_callback),
Box::into_raw(context) as *mut c_void,
and
compiled_script.set(Compile1(
*cx,
options.ptr,
&mut transform_str_to_source_text(text_code),
));
, we pass UTF-16 bytes to the Compile1 and CompileOffThread spidermonkey APIs. The original bytes we receive from the network are UTF-8 bytes, so we have to encode the bytes as UTF-16 in order to do this. I propose that we call the spidermonkey APIs that accept UTF-8 bytes instead, so we don't have to do the UTF-8->UTF-16 conversion at all.

https://doc.servo.org/mozjs/jsapi/fn.Compile1.html
https://doc.servo.org/mozjs/jsapi/fn.CompileOffThread1.html

@avr1254
Copy link
Contributor

@avr1254 avr1254 commented Jul 28, 2020

@jdm Isn't the second example already using UTF-8 instead of UTF-16?

@jdm
Copy link
Member Author

@jdm jdm commented Jul 28, 2020

You're right!

@jdm
Copy link
Member Author

@jdm jdm commented Jul 28, 2020

Aha, here's the other case that I was thinking of:

rooted!(in(*global.get_cx()) let mut module_script = CompileModule(
*global.get_cx(),
compile_options.ptr,
&mut transform_u16_to_source_text(&module),
));

bors-servo added a commit that referenced this issue Jul 28, 2020
Removed unnecessary conversion from UTF-8 to UTF-16

<!-- Please describe your changes on the following line: -->
Changed Spidermonkey API calls to remove need for UTF-16 conversion.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #27331 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because they simply optimize existing code for speed.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.