mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:18:12 +00:00
LibJS: Support @@toPrimitive in ToPrimitive abstract operation
Fixes #3961.
This commit is contained in:
parent
f99644e75b
commit
585123127e
5 changed files with 73 additions and 19 deletions
20
Userland/Libraries/LibJS/Tests/custom-@@toPrimitive.js
Normal file
20
Userland/Libraries/LibJS/Tests/custom-@@toPrimitive.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
test("basic functionality", () => {
|
||||
const o = {
|
||||
[Symbol.toPrimitive]: hint => {
|
||||
lastHint = hint;
|
||||
},
|
||||
};
|
||||
let lastHint;
|
||||
|
||||
// Calls ToPrimitive abstract operation with 'string' hint
|
||||
String(o);
|
||||
expect(lastHint).toBe("string");
|
||||
|
||||
// Calls ToPrimitive abstract operation with 'number' hint
|
||||
+o;
|
||||
expect(lastHint).toBe("number");
|
||||
|
||||
// Calls ToPrimitive abstract operation with 'default' hint
|
||||
"" + o;
|
||||
expect(lastHint).toBe("default");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue