Commit graph

14389 commits

Author SHA1 Message Date
Linus Groh
6a37285d93 Lagom: Add Regex fuzzers 2020-11-29 09:29:26 +01:00
Linus Groh
cbe4595ec2 LibRegex: Fix clang build errors 2020-11-29 09:29:26 +01:00
Linus Groh
3ac7fb9f6c LibJS: Disallow 'with' statement in strict mode 2020-11-28 20:33:41 +01:00
Andreas Kling
42b1b36eb4 LibJS: Run clang-format on WithScope.h 2020-11-28 17:36:38 +01:00
Andreas Kling
1fad95fec5 LibJS: Add a basic unit test for the "with" statement 2020-11-28 17:16:48 +01:00
Andreas Kling
9de6443ab7 LibJS: Add basic support for "with" statements
with statements evaluate an expression and put the result of it at the
"front" of the scope chain. This is implemented by creating a WithScope
object and placing it in front of the VM's current call frame's scope.
2020-11-28 17:16:48 +01:00
Andreas Kling
c3fe9b4df8 LibJS: Add a scope object abstraction
Both GlobalObject and LexicalEnvironment now inherit from ScopeObject,
and the VM's call frames point to a ScopeObject chain rather than just
a LexicalEnvironment chain.

This gives us much more flexibility to implement things like "with",
and also unifies some of the code paths that previously required
special handling of the global object.

There's a bunch of more cleanup that can be done in the wake of this
change, and there might be some oversights in the handling of the
"super" keyword, but this generally seems like a good architectural
improvement. :^)
2020-11-28 17:16:48 +01:00
Andreas Kling
e1bbc7c075 LibJS: Make JS::Value constructors take const cell pointers
Taking non-const cell pointers is asking for trouble, since passing e.g
a "const Object*" to Value(Object*) will actually call Value(bool),
which is most likely not what you want.
2020-11-28 17:16:48 +01:00
Andreas Kling
d617120499 LibJS: Parse "with" statements :^) 2020-11-28 17:16:48 +01:00
Andreas Kling
98f2da9834 LibJS: Rename Cell::visit_children() => Cell::visit_edges()
The GC heap is really a graph of cells, so "children" didn't quite feel
appropriate here.
2020-11-28 17:16:48 +01:00
Andreas Kling
97a05ac9ac LibJS: Allow Shape without a global object
It would be nice to be able to cache some shapes globally in the VM,
but then they can't be tied to a specific global object. So let's just
get rid of the requirement that shapes are tied to a global object.
2020-11-28 17:16:48 +01:00
Linus Groh
d66087ac2f LibGUI/FileIconProvider: Initialize s_filetype_image_icon
This was accidentally removed in 1c90321.
Fixes #4125.
2020-11-28 17:16:33 +01:00
Linus Groh
149b54e26f LibJS: Remove quotes from RegExpCompileError message
They look a bit out of place, especially for multi-line error messages.
2020-11-28 16:46:25 +01:00
Linus Groh
7615649fdf LibRegex: Remove trailing newline from error_string() 2020-11-28 16:46:25 +01:00
Linus Groh
ca8e5b0791 LibRegex: Don't print error message in Regex constructor
It should be up to the caller to decide what to do when parsing of the
pattern fails.
2020-11-28 16:46:25 +01:00
Sergey Bugaev
952c0dc2a0 Userland: Implement find -name clause
Closes https://github.com/SerenityOS/serenity/issues/4191
2020-11-28 14:28:58 +01:00
Andreas Kling
1abda05d38 LibGUI: Make GUI::Dialogs non-minimizable by default 2020-11-28 10:26:05 +01:00
Andreas Kling
005afa4c6e LibGUI: Don't assert when right clicking on a vertical HeaderView
Just log a debug message instead. We still need to actually implement
vertical header context menus, but for now let's at least not crash.
2020-11-28 10:26:05 +01:00
AnotherTest
491e4a8a3b LibRegex: Allow '-' as the last element of a charclass
Fixes #4189.
2020-11-28 10:13:33 +01:00
AnotherTest
e2fa1b40c4 LibRegex: Allow unknown escapes in non-unicode mode (for ECMA262)
This makes regexps like `/\x/` to work as normal.
Partially deals with #4189.
2020-11-28 10:13:33 +01:00
AnotherTest
801750b95a LibRegex: Fix parsing identity escape sequences
Also fixes the propagation of default options (the previous
implementation reset them to zero before parsing...).
Partially deals with #4189.
2020-11-28 10:13:33 +01:00
AnotherTest
e83e7a03c2 LibRegex: Stop trying to read a character class when no tokens remain
e.g. in "[".
Fixes #4186.
2020-11-28 10:13:33 +01:00
Brendan Coles
2adcdbcc1e Tests: Add Kernel tests for unveil system call browse 'b' flag 2020-11-28 10:08:00 +01:00
Linus Groh
7dd77020ae LibJS: Use enumerator macros to define RegExp.prototype flag getters 2020-11-28 01:20:11 +01:00
Linus Groh
8a9a7f1677 LibJS: Make RegExp.prototype.source spec-compliant
Basically:
- And edge case for this object being RegExp.prototype.source
- Return "(?:)" for empty pattern
- Escape some things properly
2020-11-28 01:20:11 +01:00
Linus Groh
b6e5442d55 LibJS: Make RegExp.prototype.toString() spec-compliant
It should use the 'source' and 'flags' properties of the object, and
therefore work with non-RegExp objects as well.
2020-11-28 01:20:11 +01:00
Linus Groh
ee66eaa1b0 LibJS: Make RegExp.prototype.flags spec-compliant
This should be using the individual flag boolean properties rather than
the [[OriginalFlags]] internal slot.
Use an enumerator macro here for brevity, this will be useful for other
things as well. :^)
2020-11-28 01:20:11 +01:00
Linus Groh
5cb45e4feb LibJS: Make RegExp() constructor spec-compliant
- Default values should depend on arguments being undefined, not being
  missing
- "(?:)" for empty pattern happens in RegExp.prototype.source, not the
  constructor
2020-11-28 01:20:11 +01:00
Andreas Kling
99536449d5 LibWeb: Don't generate layout nodes for DOM inside replaced elements
Before this change, we'd show both a <canvas>, and any fallback content
inside the <canvas> for browsers that don't support <canvas>. :^)
2020-11-28 00:59:26 +01:00
DavidKorczynski
ff8ac60184
Lagom: Various fixes to make Lagom run on OSS-Fuzz (#4176) 2020-11-27 23:57:02 +01:00
asynts
83f6b8bc9a LibWeb: Two more edge cases for TreeNode::insert_before. 2020-11-27 23:23:33 +01:00
AnotherTest
210a3db44d LibJS: Implement `RegExpPrototype::exec()'
This implements *only* the builtin exec() function.
2020-11-27 21:32:41 +01:00
AnotherTest
8ba273a2f3 LibJS: Hook up Regex<ECMA262> to RegExpObject and implement `test()'
This makes RegExpObject compile and store a Regex<ECMA262>, adds
all flag-related properties, and implements `RegExpPrototype.test()`
(complete with 'lastIndex' support) :^)
It should be noted that this only implements `test()' using the builtin
`exec()'.
2020-11-27 21:32:41 +01:00
AnotherTest
75081b2bdd LibRegex: Fix reported compare-against value in debug 2020-11-27 21:32:41 +01:00
AnotherTest
dbef2b1ee9 LibRegex: Implement an ECMA262-compatible parser
This also adds support for lookarounds and individually-negated
comparisons.
The only unimplemented part of the parser spec is the unicode stuff.
2020-11-27 21:32:41 +01:00
AnotherTest
3200ff5f4f LibJS+js: Rename RegExp.{content => pattern}
The spec talks about it as 'pattern', so let's use that instead.
2020-11-27 21:32:41 +01:00
AnotherTest
3db8ced4c7 LibRegex: Change bytecode value type to a 64-bit value
To allow storing unicode ranges compactly; this is not utilised at the
moment, but changing this later would've been significantly more
difficult.
Also fixes a few debug logs.
2020-11-27 21:32:41 +01:00
AnotherTest
92ea9ed4a5 LibRegex: Fix greedy/reluctant modifiers in PosixExtendedParser
Also fixes the issue with assertions causing early termination when
they fail.
2020-11-27 21:32:41 +01:00
AnotherTest
45e5661296 Userland: Add support for 'match' in 'expr' 2020-11-27 21:32:41 +01:00
Emanuel Sprung
6add8b9c05 LibRegex: Remove backup file, remove BOM in RegexParser.cpp, run clang-format 2020-11-27 21:32:41 +01:00
Emanuel Sprung
3b7884ee8a TextEditor: Add button to match regular expression during search 2020-11-27 21:32:41 +01:00
Emanuel Sprung
4a630d4b63 LibRegex: Add RegexStringView wrapper to support utf8 and utf32 views 2020-11-27 21:32:41 +01:00
Emanuel Sprung
12dd40a2a5 Userland: Add grep utility
Grep supports only extended regular expressions, and is able to handle one pattern
handed over via -e or directly after the options. Also, multiple files can be
handed over. Recursive mode is outstanding, but no real magic :^)
2020-11-27 21:32:41 +01:00
Emanuel Sprung
55450055d8 LibRegex: Add a regular expression library
This commit is a mix of several commits, squashed into one because the
commits before 'Move regex to own Library and fix all the broken stuff'
were not fixable in any elegant way.
The commits are listed below for "historical" purposes:

- AK: Add options/flags and Errors for regular expressions

Flags can be provided for any possible flavour by adding a new scoped enum.
Handling of flags is done by templated Options class and the overloaded
'|' and '&' operators.

- AK: Add Lexer for regular expressions

The lexer parses the input and extracts tokens needed to parse a regular
expression.

- AK: Add regex Parser and PosixExtendedParser

This patchset adds a abstract parser class that can be derived to implement
different parsers. A parser produces bytecode to be executed within the
regex matcher.

- AK: Add regex matcher

This patchset adds an regex matcher based on the principles of the T-REX VM.
The bytecode pruduced by the respective Parser is put into the matcher and
the VM will recursively execute the bytecode according to the available OpCodes.
Possible improvement: the recursion could be replaced by multi threading capabilities.

To match a Regular expression, e.g. for the Posix standard regular expression matcher
use the following API:

```
Pattern<PosixExtendedParser> pattern("^.*$");
auto result = pattern.match("Well, hello friends!\nHello World!"); // Match whole needle

EXPECT(result.count == 1);
EXPECT(result.matches.at(0).view.starts_with("Well"));
EXPECT(result.matches.at(0).view.end() == "!");

result = pattern.match("Well, hello friends!\nHello World!", PosixFlags::Multiline); // Match line by line

EXPECT(result.count == 2);
EXPECT(result.matches.at(0).view == "Well, hello friends!");
EXPECT(result.matches.at(1).view == "Hello World!");

EXPECT(pattern.has_match("Well,....")); // Just check if match without a result, which saves some resources.
```

- AK: Rework regex to work with opcodes objects

This patchsets reworks the matcher to work on a more structured base.
For that an abstract OpCode class and derived classes for the specific
OpCodes have been added. The respective opcode logic is contained in
each respective execute() method.

- AK: Add benchmark for regex

- AK: Some optimization in regex for runtime and memory

- LibRegex: Move regex to own Library and fix all the broken stuff

Now regex works again and grep utility is also in place for testing.
This commit also fixes the use of regex.h in C by making `regex_t`
an opaque (-ish) type, which makes its behaviour consistent between
C and C++ compilers.
Previously, <regex.h> would've blown C compilers up, and even if it
didn't, would've caused a leak in C code, and not in C++ code (due to
the existence of `OwnPtr` inside the struct).

To make this whole ordeal easier to deal with (for now), this pulls the
definitions of `reg*()` into LibRegex.

pros:
- The circular dependency between LibC and LibRegex is broken
- Eaiser to test (without accidentally pulling in the host's libc!)

cons:
- Using any of the regex.h functions will require the user to link -lregex
- The symbols will be missing from libc, which will be a big surprise
  down the line (especially with shared libs).

Co-Authored-By: Ali Mohammad Pur <ali.mpfard@gmail.com>
2020-11-27 21:32:41 +01:00
asynts
4eb23abf06 LibWeb: Update m_previous_sibling in TreeNode::insert_before. 2020-11-27 21:29:21 +01:00
Andreas Kling
024b216141 LibWeb: Don't generate a wrap() function for the Event IDL interface
We already have a wrap() in EventWrapperFactory.cpp. It would be nice
to generate that at some point but it will require a lot more work on
the wrapper generator.
2020-11-27 13:54:58 +01:00
Andreas Kling
ddbfd77e2c LibWeb: Don't put block boxes inside inlines
Inline layout nodes cannot have block children (except inline-block,
of course.)

When encountering a block box child of an inline, we now hoist the
block up to the inline's containing block, and also wrap any preceding
inline siblings in an anonymous wrapper block.

This improves the ACID2 situation quite a bit (although we still need
floats to really bring it home.)

I also took this opportunity to move all tree building logic into
Layout::TreeBuilder, to continue the theme of absolving our LayoutNode
objects of responsibilities. :^)
2020-11-26 21:22:42 +01:00
Andreas Kling
ffa4405083 LibPthread: Fix broken EINVAL check in pthread_attr_setdetachstate()
Also fix up some misleading error messages in the 'tt' test program.
2020-11-26 19:33:44 +01:00
Andreas Kling
a5e560ee49 test-js: Don't keep a pointer to a temporary String's characters
This was only an issue in the Lagom build.
2020-11-26 19:33:35 +01:00
Tom
2b78b17926 Kernel: Enable VMWareBackdoor immediately at boot
Rather than waiting until we get the first mouse packet, enable the
absolute mode immediately. This avoids having to click first to be
able to move the mouse.
2020-11-26 10:00:01 +01:00