Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibJS: Add new host hook, specify template literals and more #14904

Merged
merged 6 commits into from
Aug 17, 2022

Conversation

davidot
Copy link
Member

@davidot davidot commented Aug 17, 2022

I have not implemented the hook in browser yet as the PR is not merged yet:
whatwg/html#8198

I do have a patch ready but it might be more complicated by extending location and or window

The original JS PR has already been merged:
tc39/ecma262#2807

@davidot davidot force-pushed the plz-no-privates-on-my-window branch from e863fc3 to ecfdd4a Compare August 17, 2022 19:41
Userland/Libraries/LibJS/Runtime/Object.cpp Outdated Show resolved Hide resolved
Userland/Libraries/LibJS/Runtime/Object.cpp Outdated Show resolved Hide resolved
Userland/Libraries/LibJS/Runtime/VM.cpp Outdated Show resolved Hide resolved
Userland/Libraries/LibJS/Runtime/Value.cpp Outdated Show resolved Hide resolved
Userland/Libraries/LibJS/Tests/builtins/Number/Number.js Outdated Show resolved Hide resolved
Userland/Libraries/LibJS/AST.cpp Outdated Show resolved Hide resolved
Userland/Libraries/LibJS/AST.cpp Outdated Show resolved Hide resolved
Userland/Libraries/LibJS/AST.cpp Outdated Show resolved Hide resolved
Userland/Libraries/LibJS/AST.cpp Outdated Show resolved Hide resolved
Userland/Libraries/LibJS/AST.cpp Outdated Show resolved Hide resolved
davidot and others added 6 commits August 17, 2022 22:51
This hook allows us to reject private elements on certain exotic
objects like the window object in browser.
Note that per the spec we should only call this hook if the host is a
web browser, however because LibJS has no way of knowing whether it is
in a web browser environment we just always call the host hook.
Assuming we had at least one argument meant that the ...arg count would
underflow causing the bound function to have length 0 instead of the
given length when binding with no arguments.
We use strtod to convert a string to number after checking whether the
string is [+-]Infinity, however strtod also checks for either 'inf' or
'infinity' in a case-insensitive.
There are still valid cases for strtod to return infinity like 10e100000
so we just check if the "number" contains 'i' or 'I' in which case
the strtod infinity is not valid.
Since tagged template literals can inspect the raw string it is not a
syntax error to have invalid escapes. However the cooked value should be
`undefined`.
We accomplish this by tracking whether parse_string_literal
fails and then using a NullLiteral (since UndefinedLiteral is not a
thing) and finally converting null in tagged template execution to
undefined.
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.
@davidot davidot force-pushed the plz-no-privates-on-my-window branch from ecfdd4a to fe0082d Compare August 17, 2022 20:52
@linusg linusg merged commit 28e552f into SerenityOS:master Aug 17, 2022
@davidot davidot deleted the plz-no-privates-on-my-window branch August 17, 2022 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants