LibJS: Dont try to serialize symbol-keyed properties

As per the specification: "All Symbol-keyed properties will be
completely ignored, even when using the replacer function."
This commit is contained in:
Idan Horowitz 2021-04-16 13:02:51 +03:00 committed by Linus Groh
parent fff7aceb9d
commit 223472c57f
Notes: sideshowbarker 2024-07-18 20:15:36 +09:00
2 changed files with 9 additions and 0 deletions

View file

@ -215,6 +215,8 @@ String JSONObject::serialize_json_object(GlobalObject& global_object, StringifyS
Vector<String> property_strings;
auto process_property = [&](const PropertyName& key) {
if (key.is_symbol())
return;
auto serialized_property_string = serialize_json_property(global_object, state, key, &object);
if (vm.exception())
return;

View file

@ -43,6 +43,13 @@ describe("correct behavior", () => {
Object.defineProperty(o, "baz", { value: "qux", enumerable: false });
expect(JSON.stringify(o)).toBe('{"foo":"bar"}');
});
test("ignores symbol properties", () => {
let o = { foo: "bar" };
let sym = Symbol("baz");
o[sym] = "qux";
expect(JSON.stringify(o)).toBe('{"foo":"bar"}');
});
});
describe("errors", () => {