mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:27:45 +00:00
LibJS: Implement tagged literals evaluation like the spec
We cache on the AST node side as this is easier to track a position, we just have to take care to wrap the values in a handle to make sure they are not garbage collected.
This commit is contained in:
parent
e5adc51e27
commit
3a8dd3e78d
3 changed files with 141 additions and 24 deletions
|
@ -130,4 +130,37 @@ describe("tagged template literal functionality", () => {
|
|||
expect(calls).toBe(3);
|
||||
expect(lastValue).toBe("\\u{10FFFFF}");
|
||||
});
|
||||
|
||||
test("for multiple values gives undefined only for invalid strings", () => {
|
||||
let restValue = null;
|
||||
let stringsValue = null;
|
||||
let calls = 0;
|
||||
|
||||
function extractArguments(value, ...arguments) {
|
||||
++calls;
|
||||
restValue = arguments;
|
||||
stringsValue = value;
|
||||
}
|
||||
extractArguments`valid${1}invalid\u`;
|
||||
|
||||
expect(calls).toBe(1);
|
||||
expect(restValue).toHaveLength(1);
|
||||
expect(restValue[0]).toBe(1);
|
||||
expect(stringsValue).toHaveLength(2);
|
||||
expect(stringsValue[0]).toBe("valid");
|
||||
expect(stringsValue[1]).toBeUndefined();
|
||||
expect(stringsValue.raw).toHaveLength(2);
|
||||
expect(stringsValue.raw[0]).toBe("valid");
|
||||
expect(stringsValue.raw[1]).toBe("invalid\\u");
|
||||
});
|
||||
|
||||
test("string value gets cached per AST node", () => {
|
||||
function call(func, val) {
|
||||
return func`template${val}second`;
|
||||
}
|
||||
|
||||
let firstResult = call(value => value, 1);
|
||||
let secondResult = call(value => value, 2);
|
||||
expect(firstResult).toBe(secondResult);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue