mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-17 10:52:13 +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
|
||||
/// Notation (JSON)](https://json.org/) and converting values to JSON. It
|
||||
/// can't be called or constructed, and aside from its two method
|
||||
/// properties, it has no interesting functionality of its own.
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub type JSON;
|
||||
/// The `JSON` object contains methods for parsing [JavaScript Object
|
||||
/// Notation (JSON)](https://json.org/) and converting values to JSON. It
|
||||
/// can't be called or constructed, and aside from its two method
|
||||
/// properties, it has no interesting functionality of its own.
|
||||
#[allow(non_snake_case)]
|
||||
pub mod JSON {
|
||||
use super::*;
|
||||
|
||||
// JSON
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
/// The `JSON.parse()` method parses a JSON string, constructing the
|
||||
/// JavaScript value or object described by the string.
|
||||
///
|
||||
/// [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>;
|
||||
|
||||
/// 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)
|
||||
#[wasm_bindgen(catch, static_method_of = JSON)]
|
||||
#[wasm_bindgen(catch, js_namespace = JSON)]
|
||||
pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// [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>;
|
||||
|
||||
/// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
|
||||
@ -3120,13 +3120,14 @@ extern "C" {
|
||||
/// white space is used.
|
||||
///
|
||||
/// [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(
|
||||
obj: &JsValue,
|
||||
replacer: &JsValue,
|
||||
space: &JsValue,
|
||||
) -> Result<JsString, JsValue>;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// JsString
|
||||
|
@ -198,15 +198,3 @@ fn stringify_with_replacer_and_space_error() {
|
||||
let err_msg: String = From::from(err.message());
|
||||
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