mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-22 12:42:14 +00:00
Transform JSON into a namespace
This commit is contained in:
parent
75c2971ab9
commit
62b7d3e3c4
@ -3066,28 +3066,28 @@ pub mod WebAssembly {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSON
|
|
||||||
#[wasm_bindgen]
|
|
||||||
extern "C" {
|
|
||||||
/// The `JSON` object contains methods for parsing [JavaScript Object
|
/// The `JSON` object contains methods for parsing [JavaScript Object
|
||||||
/// Notation (JSON)](https://json.org/) and converting values to JSON. It
|
/// Notation (JSON)](https://json.org/) and converting values to JSON. It
|
||||||
/// can't be called or constructed, and aside from its two method
|
/// can't be called or constructed, and aside from its two method
|
||||||
/// properties, it has no interesting functionality of its own.
|
/// properties, it has no interesting functionality of its own.
|
||||||
#[wasm_bindgen(extends = Object)]
|
#[allow(non_snake_case)]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
pub mod JSON {
|
||||||
pub type JSON;
|
use super::*;
|
||||||
|
|
||||||
|
// JSON
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
/// The `JSON.parse()` method parses a JSON string, constructing the
|
/// The `JSON.parse()` method parses a JSON string, constructing the
|
||||||
/// JavaScript value or object described by the string.
|
/// JavaScript value or object described by the string.
|
||||||
///
|
///
|
||||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
|
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
|
||||||
#[wasm_bindgen(catch, static_method_of = JSON)]
|
#[wasm_bindgen(catch, js_namespace = JSON)]
|
||||||
pub fn parse(text: &str) -> Result<JsValue, JsValue>;
|
pub fn parse(text: &str) -> Result<JsValue, JsValue>;
|
||||||
|
|
||||||
/// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
|
/// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
|
||||||
///
|
///
|
||||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
|
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
|
||||||
#[wasm_bindgen(catch, static_method_of = JSON)]
|
#[wasm_bindgen(catch, js_namespace = JSON)]
|
||||||
pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
|
pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
|
||||||
|
|
||||||
/// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
|
/// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
|
||||||
@ -3099,7 +3099,7 @@ extern "C" {
|
|||||||
/// of the object are included in the resulting JSON string.
|
/// of the object are included in the resulting JSON string.
|
||||||
///
|
///
|
||||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
|
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
|
||||||
#[wasm_bindgen(catch, static_method_of = JSON, js_name = stringify)]
|
#[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
|
||||||
pub fn stringify_with_replacer(obj: &JsValue, replacer: &JsValue) -> Result<JsString, JsValue>;
|
pub fn stringify_with_replacer(obj: &JsValue, replacer: &JsValue) -> Result<JsString, JsValue>;
|
||||||
|
|
||||||
/// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
|
/// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
|
||||||
@ -3120,7 +3120,7 @@ extern "C" {
|
|||||||
/// white space is used.
|
/// white space is used.
|
||||||
///
|
///
|
||||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
|
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
|
||||||
#[wasm_bindgen(catch, static_method_of = JSON, js_name = stringify)]
|
#[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
|
||||||
pub fn stringify_with_replacer_and_space(
|
pub fn stringify_with_replacer_and_space(
|
||||||
obj: &JsValue,
|
obj: &JsValue,
|
||||||
replacer: &JsValue,
|
replacer: &JsValue,
|
||||||
@ -3128,6 +3128,7 @@ extern "C" {
|
|||||||
) -> Result<JsString, JsValue>;
|
) -> Result<JsString, JsValue>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// JsString
|
// JsString
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
|
@ -198,15 +198,3 @@ fn stringify_with_replacer_and_space_error() {
|
|||||||
let err_msg: String = From::from(err.message());
|
let err_msg: String = From::from(err.message());
|
||||||
assert!(err_msg.contains("rust really rocks"));
|
assert!(err_msg.contains("rust really rocks"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
|
||||||
fn json_extends() {
|
|
||||||
#[wasm_bindgen]
|
|
||||||
extern "C" {
|
|
||||||
#[wasm_bindgen(js_name = JSON)]
|
|
||||||
static json: JSON;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert!(json.is_instance_of::<Object>());
|
|
||||||
let _: &Object = json.as_ref();
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user