Commit Graph

688 Commits

Author SHA1 Message Date
AnotherTest
586aa3b1de Userland: Install LibLine's signal handlers in the JS repl 2020-04-11 14:29:25 +02:00
Andreas Kling
e5cde0082a LibX86: Run the instruction decoder in 32-bit mode by default
Let's assume a 32-bit execution environment unless otherwise specified.
2020-04-11 13:24:55 +02:00
Andreas Kling
32d83fdee4 LibX86: Add an X86 instruction decoder library + basic disassembler
This will be very useful for developer tools like ProfileView, and also
for future tools like debuggers and such. :^)
2020-04-11 13:16:17 +02:00
AnotherTest
6545a74743 JS repl: Fix indentation when a line starts with '})]' 2020-04-10 00:58:59 +02:00
Linus Groh
c06a6c67d5 LibJS: Add globalThis
We already have "global" as a way to access the global object in js(1)
(both REPL and script mode). This replaces it with "globalThis", which
is available in all environments, not just js.
2020-04-09 15:58:49 +02:00
Linus Groh
755b206618 LibJS: Handle empty values in Value::to_string() 2020-04-08 18:51:34 +02:00
Andreas Kling
bdffc9e7fb LibJS: Support array holes, encoded as empty JS::Value
This patch adds a new kind of JS::Value, the empty value.
It's what you get when you do JSValue() (or most commonly, {} in C++.)

An empty Value signifies the absence of a value, and should never be
visible to JavaScript itself. As of right now, it's used for array
holes and as a return value when an exception has been thrown and we
just want to unwind.

This patch is a bit of a mess as I had to fix a whole bunch of code
that was relying on JSValue() being undefined, etc.
2020-04-06 20:27:44 +02:00
Andreas Kling
90ba0145f6 LibJS: Add a number-indexed property storage to all Objects
Objects can have both named and indexed properties. Previously we kept
all property names as strings. This patch separates named and indexed
properties and splits them between Object::m_storage and m_elements.

This allows us to do much faster array-style access using numeric
indices. It also makes the Array class much less special, since all
Objects now have number-indexed storage. :^)
2020-04-06 18:09:26 +02:00
Liav A
23fb985f02 Kernel & Userland: Allow to mount image files formatted with Ext2FS 2020-04-06 15:36:36 +02:00
Andreas Kling
e323246517 Meta: Add missing copyright headers 2020-04-06 11:09:01 +02:00
AnotherTest
d077637fd6 JS Repl: Add live syntax highlighting
This patchset adds live syntax highlighting to the js repl.
It is turned off by default and can be enabled via the -s flag.
2020-04-05 16:11:13 +02:00
Brian Gianforcaro
4233c8662b js: Add a new --test-mode option, which exposes an assert() function.
Introduce a central assert implementation so that the LibJS test suite
can take advantage of one implementation instead of copy/pasting the
same function into every test case file.
2020-04-05 15:28:45 +02:00
AnotherTest
77191d82dc Kernel: Add the SO_BINDTODEVICE socket option
This patch adds a way for a socket to ask to be routed through a
specific interface.
Currently, this option only applies to sending, however, it should also
apply to receiving...somehow :^)
2020-04-05 09:50:48 +02:00
Linus Groh
79539378c6 js: Add lines to history 2020-04-05 01:54:38 +02:00
Andreas Kling
2db8716a6f LibJS: Don't return the "last computed value" from Interpreter::run()
Only return whatever a "return" statment told us to return.
The last computed value is now available in Interpreter::last_value()
instead, where the REPL can pick it up.
2020-04-04 23:45:13 +02:00
Andreas Kling
fc5067afd2 ProtocolServer+LibProtocol: Reject unhandled URLs instead of asserting
StartDownload requests for unhandled protocols (or invalid URLs) will
now refuse to load instead of asserting. A failure code is sent back
to LibProtocol and Protocol::Client::start_download() returns nullptr.

Fixes #1604.
2020-04-04 20:01:36 +02:00
Andreas Kling
040ba77d44 Userland: Fix null-pointer deref on unknown user/group in chown/chgrp
We can't just blindly dereference the result of getpwnam()/getgrnam()!

Fixes #1625.
2020-04-04 19:29:30 +02:00
Linus Groh
cd3e2690eb LibJS: Set length property in Object::put_native_function() 2020-04-04 15:58:49 +02:00
Andreas Kling
26eeaef0a8 LibGUI: Add MenuBar::add_menu(name)
This allows us to construct menus in a more natural way:

    auto& file_menu = menubar->add_menu("File");
    file_menu.add_action(...);

Instead of the old way:

    auto file_menu = GUI::Menu::construct();
    file_menu->add_action(...);
    menubar->add_menu(file_menu);
2020-04-04 12:58:05 +02:00
Andreas Kling
faac43597a LibJS: Add js_string(Interpreter&, String) 2020-04-04 12:58:05 +02:00
Linus Groh
a769db6078 js: Return 1 after exception in non-REPL mode 2020-04-04 10:29:42 +02:00
Dov Alperin
fb67bc2f4f Userland/JS: Add the 'save("file")' repl command
Calling save("file") in a repl saves all the typed lines so far
into the specified file. It currently does not have great support for
multilined functions since those get turned into one line.
2020-04-04 00:31:02 +02:00
Andreas Kling
9ae3cced76 Revert "Kernel & Userland: Allow to mount image files formatted with Ext2FS"
This reverts commit a60ea79a41.

Reverting these changes since they broke things.
Fixes #1608.
2020-04-03 21:28:57 +02:00
Andreas Kling
5e6e1fd482 LibJS: Start implementing object shapes
This patch adds JS::Shape, which implements a transition tree for our
Object class. Object property keys, prototypes and attributes are now
stored in a Shape, and each Object has a Shape.

When adding a property to an Object, we make a transition from the old
Shape to a new Shape. If we've made the same exact transition in the
past (with another Object), we reuse the same transition and both
objects may now share a Shape.

This will become the foundation of inline caching and other engine
optimizations in the future. :^)
2020-04-02 19:32:21 +02:00
Dov Alperin
3906d2b46a Userland/JS: Print any exceptions after execution of a JS file 2020-04-02 17:08:37 +02:00
Andreas Kling
57f72f2982 js: Change wording from "Exception caught" to "Uncaught exception" :^)
As Sergey pointed out, these exceptions are actually *not* caught!
2020-04-02 15:25:08 +02:00
Linus Groh
eb1fef2be6 js: Improve exception output for errors with empty message 2020-04-02 15:24:34 +02:00
Liav A
a60ea79a41 Kernel & Userland: Allow to mount image files formatted with Ext2FS 2020-04-02 12:03:08 +02:00
Andreas Kling
8ad890cfa6 js: Handle exceptions thrown during REPL execution
We now print thrown exceptions and clear the interpreter state so it
can continue running instead of refusing to do anything after an
exception has been thrown.

Fixes #1572.
2020-04-02 09:56:13 +02:00
Andreas Kling
cd1d369cdd LibJS: Add argument(i) and argument_count() to Interpreter
Add some convenience accessors for retrieving arguments from the
current call frame.
2020-04-01 22:38:59 +02:00
Andreas Kling
1549c5c48b LibJS: Make Value::as_object() return Object&
Let's move towards using references over pointers in LibJS as well.
I had originally steered away from it because that's how I've seen
things done in other engines. But this is not the other engines. :^)
2020-04-01 22:18:47 +02:00
Dov Alperin
c27e8a258a Userland/JS: Extend the global object when using a REPL
When we enter a repl we call initialize_global_object on our custom
ReplObject in order to expose REPL specific features. Specifically:
help(), exit(code), and load("file1.js", "file2.js", "fileEtc.js").
2020-04-01 22:11:33 +02:00
Andreas Kling
9d5d0261e1 LibJS: Add Interpreter::create<GlobalObjectType>()
Force Interpreter construction to go via a create() helper that takes
the global object type as a template parameter.
2020-04-01 21:05:35 +02:00
Andreas Kling
d062d7baa7 LibWeb+LibJS: Move DOM Window object to dedicated classes
LibWeb now creates a WindowObject which inherits from GlobalObject.
Allocation of the global object is moved out of the Interpreter ctor
to allow for specialized construction.

The existing Window interfaces are moved to WindowObject with their
implementation code in the new Window class.
2020-04-01 18:57:00 +02:00
Linus Groh
632231cc0c js: Implement print function for Date objects 2020-03-31 21:19:21 +02:00
Andreas Kling
b71e504bba js: Don't construct a Line::Editor unless we're going into the REPL
Otherwise the Line::Editor will try to reset termios on exit, which can
have unpleasant effects.
2020-03-31 19:00:20 +02:00
Andreas Kling
8ab576308f LibLine: Rename LineEditor.{cpp,h} => Editor.{cpp,h} 2020-03-31 13:34:57 +02:00
Andreas Kling
6595469de1 LibLine: Rename LineEditor to Line::Editor 2020-03-31 13:34:06 +02:00
Andreas Kling
a30a3277a3 LibLine: Rename from LibLineEdit 2020-03-31 13:32:11 +02:00
Andreas Kling
9c7451a21d js: Don't exit the REPL when pressing enter on an empty line 2020-03-31 13:30:00 +02:00
AnotherTest
06d35d036d Userland/js: Use the new line editor in repl
We now get cursor movements for free!
and we're rid of that icky `free` call, yay.
2020-03-31 13:21:46 +02:00
Brendan Coles
d64589101c Userland: Add optional human readable output to /bin/df
/bin/df now allows the operator to view human readable
output using `-h` or `--human-readable` optional flags.
2020-03-31 09:08:30 +02:00
Linus Groh
d4e3688f4f LibJS: Start implementing Date :^)
This adds:

- A global Date object (with `length` property and `now` function)
- The Date constructor (no arguments yet)
- The Date prototype (with `get*` functions)
2020-03-30 14:11:54 +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
Itamar
e5ebdb9bca strace: Change implementation to use ptrace() 2020-03-28 18:27:18 +01:00
Andreas Kling
23c5323a70 js: Publish the global object as "global" 2020-03-27 12:24: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
bc7a9097a7 js: Tweak pretty-printing of functions and null 2020-03-26 14:54:43 +01:00
Andreas Kling
97d3809a17 js: Fix build on Linux
Apparently ESUCCESS is not a thing on my host machine.
2020-03-26 14:46:00 +01:00
Andreas Kling
6e6495fdf9 js: Implement some modest pretty-printing of values 2020-03-26 12:26:11 +01:00