Commit graph

8838 commits

Author SHA1 Message Date
Andreas Kling
06aec9667e LibWeb: Support more advanced selectors in document.querySelectorAll()
I made some mistakes in the selector parsing code. It's now able to
parse selectors composed of multiple complex selectors, instead of just
one complex selector.
2020-03-30 11:35:39 +02:00
Andreas Kling
c1c56b1131 LibWeb: Add Element.id property to the bindings 2020-03-30 11:35:39 +02:00
Andreas Kling
0f7bcd4111 LibWeb: Add naive support for document.querySelectorAll()
This currently returns a JS::Array of elements matching a selector.
The more correct behavior would be to return a static NodeList, but as
we don't have NodeLists right now, that'll be a task for the future.
2020-03-30 11:35:39 +02:00
Tibor Nagy
317a0d666b LibGUI: AboutDialog now inherits the icon of its parent window 2020-03-30 10:52:09 +02:00
Andreas Kling
8c5fa05c39 WindowServer: Use Gfx::ShareableBitmap for SetWindowIconBitmap 2020-03-29 19:37:23 +02:00
Andreas Kling
7cfe712f4d LibGfx+LibIPC: Add Gfx::ShareableBitmap, a bitmap for easy IPC usage
With this patch, it's now possible to pass a Gfx::ShareableBitmap in an
IPC message. As long as the message itself is synchronous, the bitmap
will be adopted by the receiving end, and disowned by the sender nicely
without any accounting effort like we've had to do in the past.

Use this in NotificationServer to allow sending arbitrary bitmaps as
icons instead of paths-to-icons.
2020-03-29 19:37:23 +02:00
Andreas Kling
24a0354ce8 LibIPC+LibGfx: Pass the IPC::Decoder to decoding helpers
Instead of passing the BufferStream, pass the Decoder. I'd like to stop
using BufferStream eventually anyway, so it's good to get it out of any
API's where it's in currently.
2020-03-29 19:37:23 +02:00
Andreas Kling
01ff36a2f4 LibIPC: Add forwarding header for LibIPC 2020-03-29 19:37:23 +02:00
Andreas Kling
ae9fe60412 LibGUI: Make Label::set_icon() take a const Gfx::Bitmap* 2020-03-29 19:37:23 +02:00
Linus Groh
0a94661c14 LibJS: Implement String.prototype.startsWith() 2020-03-29 19:37:16 +02:00
Hüseyin ASLITÜRK
f88b90f6fd LibGUI: Desktop, add methods for set background color and wallpaper mode 2020-03-29 19:36:37 +02:00
Hüseyin ASLITÜRK
7194b4823e LibGUI: ComboBox, add "set_selected_index" method
Easy way to set selected item.
2020-03-29 19:36:37 +02:00
Linus Groh
402fd5a3a3 LibJS: Add tests for Math constants 2020-03-29 17:35:08 +02:00
Linus Groh
03c3530d86 LibJS: Add constant properties to MathObject 2020-03-29 17:35:08 +02:00
Linus Groh
c698cc899d LibJS: Add tests for value to number conversion 2020-03-29 16:45:11 +02:00
Linus Groh
bad0556a59 LibJS: Handle empty strings and arrays in Value::to_number()
- An empty string is converted to 0
 - An empty array is converted to 0
 - An array with one item is converted to that item's numeric value
 - An array with more than one item is converted to NaN
2020-03-29 16:45:11 +02:00
Andreas Kling
2d3634d5f5 LibJS: Implement Math.abs() 2020-03-29 15:03:58 +02:00
Andreas Kling
2285f84596 LibJS: Implement basic execution of "switch" statements
The "break" keyword now unwinds to the nearest ScopeType::Breakable.
There's no support for break labels yet, but we'll get there too.
2020-03-29 15:03:58 +02:00
Andreas Kling
1923051c5b LibJS: Lexer and parser support for "switch" statements 2020-03-29 15:03:58 +02:00
Andreas Kling
f95a119627 LibJS: Implement Object.getOwnPropertyNames() 2020-03-29 01:26:57 +01:00
Andreas Kling
62d5f79388 LibJS+LibWeb: Function calls should always go through Interpreter
This ensures that we set up a call frame with |this| and arguments.
2020-03-29 00:45:53 +01:00
Andreas Kling
30440134cb LibJS+LibWeb: Move native properties to separate getters/setters
This was a bit cumbersome now, but it gets us closer to a format suited
for code generation.
2020-03-29 00:37:33 +01:00
Andreas Kling
56936b97d0 LibJS+LibWeb: Move native JS functions into dedicated member functions
Instead of implementing every native function as a lambda function,
use static member functions instead.

This makes it easier to navigate the code + backtraces look nicer. :^)
2020-03-28 23:10:37 +01:00
Andreas Kling
7c4e53f31e LibJS: Rework how native functions are called to improve |this| value
Native functions now only get the Interpreter& as an argument. They can
then extract |this| along with any indexed arguments it wants from it.

This forces functions that want |this| to actually deal with calling
interpreter.this_value().to_object(), and dealing with the possibility
of a non-object |this|.

This is still not great but let's keep massaging it forward.
2020-03-28 22:51:09 +01:00
Linus Groh
c209ea1985 LibJS: Implement Array.prototype.{shift,pop} 2020-03-28 22:18:11 +01:00
Andreas Kling
82ca7ae1f8 LibJS: Oops, "instanceof" was backwards!
Fix the "instanceof" operator to check if the constructor's prototype
property occurs anywhere in the prototype chain of the instance object.

This patch also adds Object.setPrototypeOf() to make it possible to
create a test for this bug.

Thanks to DexesTTP for pointing this out! :^)
2020-03-28 19:48:12 +01:00
Itamar
e5ebdb9bca strace: Change implementation to use ptrace() 2020-03-28 18:27:18 +01:00
Itamar
6b74d38aab Kernel: Add 'ptrace' syscall
This commit adds a basic implementation of
the ptrace syscall, which allows one process
(the tracer) to control another process (the tracee).

While a process is being traced, it is stopped whenever a signal is
received (other than SIGCONT).

The tracer can start tracing another thread with PT_ATTACH,
which causes the tracee to stop.

From there, the tracer can use PT_CONTINUE
to continue the execution of the tracee,
or use other request codes (which haven't been implemented yet)
to modify the state of the tracee.

Additional request codes are PT_SYSCALL, which causes the tracee to
continue exection but stop at the next entry or exit from a syscall,
and PT_GETREGS which fethces the last saved register set of the tracee
(can be used to inspect syscall arguments and return value).

A special request code is PT_TRACE_ME, which is issued by the tracee
and causes it to stop when it calls execve and wait for the
tracer to attach.
2020-03-28 18:27:18 +01:00
Andreas Kling
14047ca432 LibJS: Add a global "Object" constructor
This patch adds an "Object" constructor to the global object. The only
function it implements so far is Object.getPrototypeOf().
2020-03-28 17:23:54 +01:00
Andreas Kling
a3d92b1210 LibJS: Implement the "instanceof" operator
This operator walks the prototype chain of the RHS value and looks for
a "prototype" property with the same value as the prototype of the LHS.

This is pretty cool. :^)
2020-03-28 16:56:54 +01:00
Andreas Kling
37fe16a99c LibJS: Add Function.prototype and make "new" Objects delegate to it 2020-03-28 16:40:36 +01:00
Andreas Kling
0593ce406b LibJS: Implement basic support for the "new" keyword
NewExpression mostly piggybacks on the existing CallExpression. The big
difference is that "new" creates a new Object and passes it as |this|
to the callee.
2020-03-28 16:33:52 +01:00
Andreas Kling
fecbef4ffe LibJS: Make it possible to reference the "this" value in JavaScript 2020-03-28 16:33:04 +01:00
Andreas Kling
14de45296e LibJS: Fix broken parsing of !o.a
Unary expressions parsing now respects precedence and associativity of
operators. This patch also makes `typeof` left-associative which was
an oversight.

Thanks to Conrad for helping me work this out. :^)
2020-03-28 11:51:44 +01:00
Andreas Kling
0cbbf6f5eb LibJS: Add a tiny little test for the ReferenceError exception 2020-03-28 10:27:48 +01:00
Andreas Kling
660ec504ca LibWeb: Move get_element_by_id() to a NonElementParentNode mixin class
This matches the current version of the DOM spec. And since C++ doesn't
have mixins this is actually a CRTP class.
2020-03-28 09:13:29 +01:00
Andreas Kling
0d2fb306af LibJS: Check for exceptions in a lot more places 2020-03-27 15:36:00 +01:00
Emanuel Sprung
4d50398f02 LibGUI: Add store(), add() and remove() methods to JsonArrayModel
This patchset adds the methods to alter an JSON model and store it back
to the disk.
2020-03-27 14:12:18 +01:00
Andreas Kling
6a5cd32205 LibJS: The global isNaN() should coerce to number before testing NaN
For stricter NaN checking, we'll have to implement Number.isNaN().
2020-03-27 12:59:41 +01:00
Andreas Kling
c60dc84a33 LibJS: Allow function calls with missing arguments
We were interpreting "undefined" as a variable lookup failure in some
cases and throwing a ReferenceError exception instead of treating it
as the valid value "undefined".

This patch wraps the result of variable lookup in Optional<>, which
allows us to only throw ReferenceError when lookup actually fails.
2020-03-27 12:56:05 +01:00
Andreas Kling
04ced9e24a LibJS: Add global isNaN() function 2020-03-27 12:45:36 +01:00
Andreas Kling
9a78b4af2c LibJS: Basic NaN support
This patch adds js_nan() for constructing a NaN value. You can check
if a Value is NaN with Value::is_nan().
2020-03-27 12:40:22 +01:00
Andreas Kling
9494865f99 LibJS: Actually pop frames off of the scope stack when exiting a scope 2020-03-27 11:34:58 +01:00
Andreas Kling
faedb763ca NotificationServer: Allow showing an icon in notifications
We currently use icon paths for this because I didn't want to deal with
implementing icon bitmap sharing right now. In the future it would be
better to post a bitmap somehow instead of a path.
2020-03-26 20:38:28 +01:00
Andreas Kling
96c7e2cd6d LibGUI: Make a new connection to NotificationServer each time
Since NotificationServer is a spawn-on-demand + die-when-not-used type
of service, we can't expect a singleton connection to it to remain open
and useful.

We solve this for now by making a new IPC connection for every new
notification sent. Maybe there's a better solution for this.
2020-03-26 20:10:03 +01:00
Andreas Kling
4802413f71 LibJS: Say "return {}" instead of "return js_undefined()" in AST nodes
This looks a bit nicer somehow.
2020-03-26 12:36:52 +01:00
Andreas Kling
ad6ede7ee4 LibJS: Make FunctionDeclaration return undefined
FunctionExpression returns a JS::Function, while FunctionDeclaration
declares one in the relevant scope.
2020-03-26 12:27:15 +01:00
Andreas Kling
68dec2801d LibJS: Add Object::own_properties() convenience accessor 2020-03-26 12:19:01 +01:00
Andreas Kling
d7073b9f3e LibJS: Add Value::is_array() 2020-03-26 12:02:18 +01:00
Sergey Bugaev
5ba8247cbb LibC: Fix getline() forgetting to null-terminate on EOF 2020-03-26 08:18:08 +01:00