mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-23 05:02:13 +00:00
Transform JSON into a namespace
This commit is contained in:
parent
75c2971ab9
commit
62b7d3e3c4
@ -3066,67 +3066,68 @@ pub mod WebAssembly {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSON
|
/// The `JSON` object contains methods for parsing [JavaScript Object
|
||||||
#[wasm_bindgen]
|
/// Notation (JSON)](https://json.org/) and converting values to JSON. It
|
||||||
extern "C" {
|
/// can't be called or constructed, and aside from its two method
|
||||||
/// The `JSON` object contains methods for parsing [JavaScript Object
|
/// properties, it has no interesting functionality of its own.
|
||||||
/// Notation (JSON)](https://json.org/) and converting values to JSON. It
|
#[allow(non_snake_case)]
|
||||||
/// can't be called or constructed, and aside from its two method
|
pub mod JSON {
|
||||||
/// properties, it has no interesting functionality of its own.
|
use super::*;
|
||||||
#[wasm_bindgen(extends = Object)]
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub type JSON;
|
|
||||||
|
|
||||||
/// The `JSON.parse()` method parses a JSON string, constructing the
|
// JSON
|
||||||
/// JavaScript value or object described by the string.
|
#[wasm_bindgen]
|
||||||
///
|
extern "C" {
|
||||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
|
/// The `JSON.parse()` method parses a JSON string, constructing the
|
||||||
#[wasm_bindgen(catch, static_method_of = JSON)]
|
/// JavaScript value or object described by the string.
|
||||||
pub fn parse(text: &str) -> Result<JsValue, JsValue>;
|
///
|
||||||
|
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
|
||||||
|
#[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.
|
/// 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.
|
||||||
///
|
///
|
||||||
/// The `replacer` argument is a function that alters the behavior of the stringification
|
/// The `replacer` argument is a function that alters the behavior of the stringification
|
||||||
/// process, or an array of String and Number objects that serve as a whitelist
|
/// process, or an array of String and Number objects that serve as a whitelist
|
||||||
/// for selecting/filtering the properties of the value object to be included
|
/// for selecting/filtering the properties of the value object to be included
|
||||||
/// in the JSON string. If this value is null or not provided, all properties
|
/// in the JSON string. If this value is null or not provided, all properties
|
||||||
/// 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.
|
||||||
///
|
///
|
||||||
/// The `replacer` argument is a function that alters the behavior of the stringification
|
/// The `replacer` argument is a function that alters the behavior of the stringification
|
||||||
/// process, or an array of String and Number objects that serve as a whitelist
|
/// process, or an array of String and Number objects that serve as a whitelist
|
||||||
/// for selecting/filtering the properties of the value object to be included
|
/// for selecting/filtering the properties of the value object to be included
|
||||||
/// in the JSON string. If this value is null or not provided, all properties
|
/// in the JSON string. If this value is null or not provided, all properties
|
||||||
/// of the object are included in the resulting JSON string.
|
/// of the object are included in the resulting JSON string.
|
||||||
///
|
///
|
||||||
/// The `space` argument is a String or Number object that's used to insert white space into
|
/// The `space` argument is a String or Number object that's used to insert white space into
|
||||||
/// the output JSON string for readability purposes. If this is a Number, it
|
/// the output JSON string for readability purposes. If this is a Number, it
|
||||||
/// indicates the number of space characters to use as white space; this number
|
/// indicates the number of space characters to use as white space; this number
|
||||||
/// is capped at 10 (if it is greater, the value is just 10). Values less than
|
/// is capped at 10 (if it is greater, the value is just 10). Values less than
|
||||||
/// 1 indicate that no space should be used. If this is a String, the string
|
/// 1 indicate that no space should be used. If this is a String, the string
|
||||||
/// (or the first 10 characters of the string, if it's longer than that) is
|
/// (or the first 10 characters of the string, if it's longer than that) is
|
||||||
/// used as white space. If this parameter is not provided (or is null), no
|
/// used as white space. If this parameter is not provided (or is null), no
|
||||||
/// 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,
|
||||||
space: &JsValue,
|
space: &JsValue,
|
||||||
) -> Result<JsString, JsValue>;
|
) -> Result<JsString, JsValue>;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// JsString
|
// JsString
|
||||||
|
@ -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