Use Reflect::set instead of javascript helper

This commit is contained in:
Andrew Chin 2018-08-10 14:33:21 -04:00
parent f5203bba8a
commit 1092816652
2 changed files with 1 additions and 12 deletions

View File

@ -1,4 +0,0 @@
exports.set_in_object = function(obj, name, value) {
obj[name] = value;
};

View File

@ -1,15 +1,8 @@
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen(module = "tests/wasm/JSON.js")]
extern {
fn set_in_object(obj: &Object, name: &str, value: &JsValue);
}
#[wasm_bindgen_test]
fn parse_array() {
@ -79,7 +72,7 @@ fn stringify() {
fn stringify_error() {
let func = Function::new_no_args("throw new Error(\"rust really rocks\")");
let obj = Object::new();
set_in_object(&obj, "toJSON", &JsValue::from(func));
Reflect::set(obj.as_ref(), &JsValue::from("toJSON"), func.as_ref());
let result = JSON::stringify(&JsValue::from(obj));
assert!(result.is_err());