зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1151899 - rust-url-capi error code changes; r=manishearth
MozReview-Commit-ID: AHwbkgGifmr --HG-- extra : rebase_source : 82e96b565d44f9f742454ccf2198603d85f0f79c
This commit is contained in:
Родитель
ad4478f15e
Коммит
16bb40f323
|
@ -1,3 +1,7 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use url::ParseError;
|
||||
|
||||
pub trait ErrorCode {
|
||||
|
@ -13,40 +17,29 @@ impl<T: ErrorCode> ErrorCode for Result<(), T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl ErrorCode for () {
|
||||
fn error_code(&self) -> i32 {
|
||||
return -1;
|
||||
impl ErrorCode for Result<(), ()> {
|
||||
fn error_code(&self) -> i32 {
|
||||
match *self {
|
||||
Ok(_) => 0,
|
||||
Err(_) => -255,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ErrorCode for ParseError {
|
||||
fn error_code(&self) -> i32 {
|
||||
return -1;
|
||||
// match *self {
|
||||
// ParseError::EmptyHost => -1,
|
||||
// ParseError::InvalidScheme => -2,
|
||||
// ParseError::InvalidPort => -3,
|
||||
// ParseError::InvalidIpv6Address => -4,
|
||||
// ParseError::InvalidDomainCharacter => -5,
|
||||
// ParseError::InvalidCharacter => -6,
|
||||
// ParseError::InvalidBackslash => -7,
|
||||
// ParseError::InvalidPercentEncoded => -8,
|
||||
// ParseError::InvalidAtSymbolInUser => -9,
|
||||
// ParseError::ExpectedTwoSlashes => -10,
|
||||
// ParseError::ExpectedInitialSlash => -11,
|
||||
// ParseError::NonUrlCodePoint => -12,
|
||||
// ParseError::RelativeUrlWithScheme => -13,
|
||||
// ParseError::RelativeUrlWithoutBase => -14,
|
||||
// ParseError::RelativeUrlWithNonRelativeBase => -15,
|
||||
// ParseError::NonAsciiDomainsNotSupportedYet => -16,
|
||||
// ParseError::CannotSetJavascriptFragment => -17,
|
||||
// ParseError::CannotSetPortWithFileLikeScheme => -18,
|
||||
// ParseError::CannotSetUsernameWithNonRelativeScheme => -19,
|
||||
// ParseError::CannotSetPasswordWithNonRelativeScheme => -20,
|
||||
// ParseError::CannotSetHostPortWithNonRelativeScheme => -21,
|
||||
// ParseError::CannotSetHostWithNonRelativeScheme => -22,
|
||||
// ParseError::CannotSetPortWithNonRelativeScheme => -23,
|
||||
// ParseError::CannotSetPathWithNonRelativeScheme => -24,
|
||||
// }
|
||||
match *self {
|
||||
ParseError::EmptyHost => -1,
|
||||
ParseError::InvalidPort => -2,
|
||||
ParseError::InvalidIpv6Address => -3,
|
||||
ParseError::InvalidDomainCharacter => -4,
|
||||
ParseError::IdnaError => -5,
|
||||
ParseError::InvalidIpv4Address => -6,
|
||||
ParseError::RelativeUrlWithoutBase => -7,
|
||||
ParseError::RelativeUrlWithCannotBeABaseBase => -8,
|
||||
ParseError::SetHostOnCannotBeABaseUrl => -9,
|
||||
ParseError::Overflow => -10,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
extern crate url;
|
||||
use url::{Url, ParseError, ParseOptions};
|
||||
use url::quirks;
|
||||
|
@ -320,7 +324,9 @@ pub unsafe extern "C" fn rusturl_set_path(urlptr: rusturl_ptr, path: *mut libc::
|
|||
None => return ParseError::InvalidDomainCharacter.error_code() // utf-8 failed
|
||||
};
|
||||
|
||||
quirks::set_pathname(url, path_).error_code()
|
||||
quirks::set_pathname(url, path_);
|
||||
NSError::OK.error_code()
|
||||
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -336,7 +342,8 @@ pub unsafe extern "C" fn rusturl_set_query(urlptr: rusturl_ptr, query: *mut libc
|
|||
None => return ParseError::InvalidDomainCharacter.error_code() // utf-8 failed
|
||||
};
|
||||
|
||||
quirks::set_search(url, query_).error_code()
|
||||
quirks::set_search(url, query_);
|
||||
NSError::OK.error_code()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -352,7 +359,8 @@ pub unsafe extern "C" fn rusturl_set_fragment(urlptr: rusturl_ptr, fragment: *mu
|
|||
None => return ParseError::InvalidDomainCharacter.error_code() // utf-8 failed
|
||||
};
|
||||
|
||||
quirks::set_hash(url, fragment_).error_code()
|
||||
quirks::set_hash(url, fragment_);
|
||||
NSError::OK.error_code()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -475,3 +483,7 @@ pub unsafe extern "C" fn rusturl_relative_spec(urlptr1: rusturl_ptr, urlptr2: ru
|
|||
return cont.assign(&buffer);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sizeof_rusturl() -> size_t {
|
||||
mem::size_of::<Url>()
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef __RUST_URL_CAPI
|
||||
#define __RUST_URL_CAPI
|
||||
#include <stdlib.h>
|
||||
|
@ -38,8 +42,10 @@ int32_t rusturl_resolve(rusturl_ptr url, const char *relative, size_t len, void*
|
|||
int32_t rusturl_common_base_spec(rusturl_ptr url1, rusturl_ptr url2, void*);
|
||||
int32_t rusturl_relative_spec(rusturl_ptr url1, rusturl_ptr url2, void*);
|
||||
|
||||
size_t sizeof_rusturl();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __RUST_URL_CAPI
|
||||
#endif // __RUST_URL_CAPI
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
extern crate libc;
|
||||
use libc::size_t;
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
|
Загрузка…
Ссылка в новой задаче