Script: removed a few opts::get()

This commit is contained in:
oneturkmen 2019-06-07 23:38:01 -06:00
parent 57205318c5
commit 42569280e2
17 changed files with 238 additions and 45 deletions

View file

@ -24,7 +24,6 @@ use crate::dom::processinginstruction::ProcessingInstruction;
use crate::dom::text::Text;
use crate::dom::virtualmethods::vtable_for;
use dom_struct::dom_struct;
use servo_config::opts;
use std::cell::Ref;
// https://dom.spec.whatwg.org/#characterdata
@ -122,11 +121,16 @@ impl CharacterDataMethods for CharacterData {
// https://dom.spec.whatwg.org/#dom-characterdata-substringdata
fn SubstringData(&self, offset: u32, count: u32) -> Fallible<DOMString> {
let replace_surrogates = self
.upcast::<Node>()
.owner_doc()
.window()
.replace_surrogates();
let data = self.data.borrow();
// Step 1.
let mut substring = String::new();
let remaining;
match split_at_utf16_code_unit_offset(&data, offset) {
match split_at_utf16_code_unit_offset(&data, offset, replace_surrogates) {
Ok((_, astral, s)) => {
// As if we had split the UTF-16 surrogate pair in half
// and then transcoded that to UTF-8 lossily,
@ -139,7 +143,7 @@ impl CharacterDataMethods for CharacterData {
// Step 2.
Err(()) => return Err(Error::IndexSize),
}
match split_at_utf16_code_unit_offset(remaining, count) {
match split_at_utf16_code_unit_offset(remaining, count, replace_surrogates) {
// Steps 3.
Err(()) => substring = substring + remaining,
// Steps 4.
@ -176,11 +180,16 @@ impl CharacterDataMethods for CharacterData {
fn ReplaceData(&self, offset: u32, count: u32, arg: DOMString) -> ErrorResult {
let mut new_data;
{
let replace_surrogates = self
.upcast::<Node>()
.owner_doc()
.window()
.replace_surrogates();
let data = self.data.borrow();
let prefix;
let replacement_before;
let remaining;
match split_at_utf16_code_unit_offset(&data, offset) {
match split_at_utf16_code_unit_offset(&data, offset, replace_surrogates) {
Ok((p, astral, r)) => {
prefix = p;
// As if we had split the UTF-16 surrogate pair in half
@ -194,7 +203,7 @@ impl CharacterDataMethods for CharacterData {
};
let replacement_after;
let suffix;
match split_at_utf16_code_unit_offset(remaining, count) {
match split_at_utf16_code_unit_offset(remaining, count, replace_surrogates) {
// Steps 3.
Err(()) => {
replacement_after = "";
@ -305,7 +314,11 @@ impl LayoutCharacterDataHelpers for LayoutDom<CharacterData> {
/// Note that the third variant is only ever returned when the `-Z replace-surrogates`
/// command-line option is specified.
/// When it *would* be returned but the option is *not* specified, this function panics.
fn split_at_utf16_code_unit_offset(s: &str, offset: u32) -> Result<(&str, Option<char>, &str), ()> {
fn split_at_utf16_code_unit_offset(
s: &str,
offset: u32,
replace_surrogates: bool,
) -> Result<(&str, Option<char>, &str), ()> {
let mut code_units = 0;
for (i, c) in s.char_indices() {
if code_units == offset {
@ -315,7 +328,7 @@ fn split_at_utf16_code_unit_offset(s: &str, offset: u32) -> Result<(&str, Option
code_units += 1;
if c > '\u{FFFF}' {
if code_units == offset {
if opts::get().replace_surrogates {
if replace_surrogates {
debug_assert_eq!(c.len_utf8(), 4);
return Ok((&s[..i], Some(c), &s[i + c.len_utf8()..]));
}