bindings for encodeURIComponent

This commit is contained in:
Alexander Kryvomaz 2018-07-01 15:59:12 +03:00
parent 0f07dd9048
commit 609bf34d60
2 changed files with 33 additions and 2 deletions

View File

@ -49,8 +49,8 @@ extern "C" {
#[wasm_bindgen(catch, js_name = decodeURI)]
pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
/// The decodeURIComponent() function decodes a Uniform Resource Identifier (URI)
/// component previously created by encodeURIComponent or by a similar routine.
/// The decodeURIComponent() function decodes a Uniform Resource Identifier (URI) component
/// previously created by encodeURIComponent or by a similar routine.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent
#[wasm_bindgen(catch, js_name = decodeURIComponent)]
@ -66,6 +66,15 @@ extern "C" {
#[wasm_bindgen(js_name = encodeURI)]
pub fn encode_uri(decoded: &str) -> JsString;
/// The encodeURIComponent() function encodes a Uniform Resource Identifier (URI) component
/// by replacing each instance of certain characters by one, two, three, or four escape sequences
/// representing the UTF-8 encoding of the character
/// (will only be four escape sequences for characters composed of two "surrogate" characters).
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
#[wasm_bindgen(js_name = encodeURIComponent)]
pub fn encode_uri_component(decoded: &str) -> JsString;
/// The `eval()` function evaluates JavaScript code represented as a string.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval

View File

@ -96,6 +96,28 @@ fn encode_uri() {
.test();
}
#[test]
fn encode_uri_component() {
project()
.file(
"src/lib.rs",
r#"
#![feature(proc_macro, wasm_custom_section)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
use wasm_bindgen::js;
#[wasm_bindgen]
pub fn test() {
let x = js::encode_uri_component("?x=шеллы");
assert_eq!(String::from(x), "%3Fx%3D%D1%88%D0%B5%D0%BB%D0%BB%D1%8B");
}
"#,
)
.test();
}
#[test]
fn eval() {
project()