Add initial support and tests for JSON

This commit is contained in:
Andrew Chin
2018-08-09 20:54:13 -04:00
parent 9a1147d61b
commit 23cb0ea656
3 changed files with 95 additions and 0 deletions

View File

@ -2663,6 +2663,31 @@ extern "C" {
pub fn validate(bufferSource: &JsValue) -> Result<bool, JsValue>;
}
// JSON
#[wasm_bindgen]
extern "C" {
#[derive(Clone, Debug)]
pub type JSON;
/// The `JSON.parse()` method parses a JSON string, constructing the
/// JavaScript value or object described by the string.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
#[wasm_bindgen(catch, static_method_of = JSON)]
pub fn parse(text: &str) -> Result<JsValue, JsValue>;
/// The JSON.stringify() method converts a JavaScript value to a JSON string,
/// optionally replacing values if a replacer function is specified or
/// optionally including only the specified properties if a replacer array is
/// specified.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
#[wasm_bindgen(static_method_of = JSON)]
pub fn stringify(obj: &JsValue) -> JsString;
}
// JsString
#[wasm_bindgen]
extern "C" {