Merge pull request #683 from eminence/json

Add initial support and tests for JSON
This commit is contained in:
Nick Fitzgerald
2018-08-10 13:27:40 -07:00
committed by GitHub
3 changed files with 110 additions and 0 deletions

View File

@ -2683,6 +2683,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(catch, static_method_of = JSON)]
pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
}
// JsString
#[wasm_bindgen]
extern "C" {