Browse Source

fix json.stringify symbol handling (#535)

pull/538/head
n14little 4 years ago committed by GitHub
parent
commit
f957eacbae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      boa/src/builtins/json/tests.rs
  2. 4
      boa/src/builtins/value/mod.rs

3
boa/src/builtins/json/tests.rs

@ -54,8 +54,6 @@ fn json_stringify_remove_function_values_from_objects() {
} }
#[test] #[test]
#[ignore]
// there is a bug for setting a symbol as a field's value
fn json_stringify_remove_symbols_from_objects() { fn json_stringify_remove_symbols_from_objects() {
let realm = Realm::create(); let realm = Realm::create();
let mut engine = Interpreter::new(realm); let mut engine = Interpreter::new(realm);
@ -152,7 +150,6 @@ fn json_stringify_array_converts_function_to_null() {
} }
#[test] #[test]
#[ignore]
fn json_stringify_array_converts_symbol_to_null() { fn json_stringify_array_converts_symbol_to_null() {
let realm = Realm::create(); let realm = Realm::create();
let mut engine = Interpreter::new(realm); let mut engine = Interpreter::new(realm);

4
boa/src/builtins/value/mod.rs

@ -260,7 +260,7 @@ impl Value {
for k in obj.borrow().properties().keys() { for k in obj.borrow().properties().keys() {
if k != "length" { if k != "length" {
let value = self.get_field(k.to_string()); let value = self.get_field(k.to_string());
if value.is_undefined() || value.is_function() { if value.is_undefined() || value.is_function() || value.is_symbol() {
arr.push(JSONValue::Null); arr.push(JSONValue::Null);
} else { } else {
arr.push(self.get_field(k.to_string()).to_json(interpreter)?); arr.push(self.get_field(k.to_string()).to_json(interpreter)?);
@ -273,7 +273,7 @@ impl Value {
for k in obj.borrow().properties().keys() { for k in obj.borrow().properties().keys() {
let key = k.clone(); let key = k.clone();
let value = self.get_field(k.to_string()); let value = self.get_field(k.to_string());
if !value.is_undefined() && !value.is_function() { if !value.is_undefined() && !value.is_function() && !value.is_symbol() {
new_obj.insert(key.to_string(), value.to_json(interpreter)?); new_obj.insert(key.to_string(), value.to_json(interpreter)?);
} }
} }

Loading…
Cancel
Save