1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 01:27:42 +00:00

LibJS: Accept symbol property in the in operator

This is used by discord.com and allowed by the specification:
https://tc39.es/ecma262/#sec-relational-operators-runtime-semantics-evaluation
This commit is contained in:
Idan Horowitz 2021-04-17 01:46:48 +03:00 committed by Linus Groh
parent 7744048d0f
commit 586f10b6e1
2 changed files with 5 additions and 3 deletions

View file

@ -1020,10 +1020,10 @@ Value in(GlobalObject& global_object, Value lhs, Value rhs)
global_object.vm().throw_exception<TypeError>(global_object, ErrorType::InOperatorWithObject); global_object.vm().throw_exception<TypeError>(global_object, ErrorType::InOperatorWithObject);
return {}; return {};
} }
auto lhs_string = lhs.to_string(global_object); auto lhs_string_or_symbol = StringOrSymbol::from_value(global_object, lhs);
if (global_object.vm().exception()) if (global_object.vm().exception())
return {}; return {};
return Value(rhs.as_object().has_property(lhs_string)); return Value(rhs.as_object().has_property(lhs_string_or_symbol));
} }
Value instance_of(GlobalObject& global_object, Value lhs, Value rhs) Value instance_of(GlobalObject& global_object, Value lhs, Value rhs)

View file

@ -1,10 +1,12 @@
test("in operator with objects", () => { test("in operator with objects", () => {
const o = { foo: "bar", bar: undefined }; const sym = Symbol();
const o = { foo: "bar", bar: undefined, [sym]: "qux" };
expect("" in o).toBeFalse(); expect("" in o).toBeFalse();
expect("foo" in o).toBeTrue(); expect("foo" in o).toBeTrue();
expect("bar" in o).toBeTrue(); expect("bar" in o).toBeTrue();
expect("baz" in o).toBeFalse(); expect("baz" in o).toBeFalse();
expect("toString" in o).toBeTrue(); expect("toString" in o).toBeTrue();
expect(sym in o).toBeTrue();
}); });
test("in operator with arrays", () => { test("in operator with arrays", () => {