Commit graph

8835 commits

Author SHA1 Message Date
Andreas Kling
086f68e878 LibJS: Replace the global print() function with console.log() :^) 2020-03-16 14:58:20 +01:00
Andreas Kling
19452230cd LibJS: Add "Heap" and "Runtime" subdirectories
Let's try to keep LibJS tidy as it expands. :^)
2020-03-16 14:37:19 +01:00
0xtechnobabble
dfbaa8e543 LibJS: Implement abstract equality and inequality 2020-03-16 13:42:13 +01:00
0xtechnobabble
4d22a142f7 LibJS: Loosen type system
This commits makes effort towards tolerating some of javascript's quirks
when it comes to its type system, note that the interpreter's way of
handling type coercion is still not mature at all, for example, we still
have to implement NaN instead of just crashing when trying to parse a
string and failing.
2020-03-16 13:42:13 +01:00
0xtechnobabble
419d57e492 LibJS/Parser: Parse logical expressions 2020-03-16 13:42:13 +01:00
0xtechnobabble
94088640f1 LibJS: Specify overridden functions with 'override' 2020-03-16 13:42:13 +01:00
0xtechnobabble
cfd710eb31 LibJS: Implement null and undefined literals 2020-03-16 13:42:13 +01:00
0xtechnobabble
7aad10d984 LibJS: Fix assignment of const variable on declaration
We were previously assuming that we were reassigning a variable even
when we were not, oops, my bad. :/
2020-03-16 13:42:13 +01:00
Oriko
2a32330257 LibGUI: Add a ThemeChange event 2020-03-16 13:39:34 +01:00
Oriko
2b162ef794 LibGUI: Use themes for syntax highlighting 2020-03-16 13:39:34 +01:00
Andreas Kling
731abd9978 LibJS: Add String.prototype.repeat() :^) 2020-03-15 21:17:38 +01:00
Andreas Kling
63b3cfdc73 LibJS: Pass "this" as an Object* to NativeFunction callbacks
Instead of every NativeFunction callback having to ask the Interpreter
for the current "this" value and then converting it to an Object etc,
just pass "this" as an Object* directly.
2020-03-15 20:51:36 +01:00
Andreas Kling
3163929990 LibJS: Add a mechanism for callback-based object properties
This patch adds NativeProperty, which can be used to implement object
properties that have C++ getters and/or setters.

Use this to move String.prototype.length to its correct place. :^)
2020-03-15 19:31:00 +01:00
Andreas Kling
bb57bc1b42 LibJS: Remove debug spam in Object::get() 2020-03-15 19:31:00 +01:00
marprok
0fd5f0e4bd Userland: ifconfig can change the IP address of the default gateway
ioctl can now perform a request for a specific route and change
the address of it's default gateway.
2020-03-15 19:09:31 +01:00
Andreas Kling
23b1d97b0d LibJS: Add ObjectPrototype and implement hasOwnProperty()
All Objects will now have ObjectPrototype as their prototype, unless
overridden.
2020-03-15 15:25:43 +01:00
Andreas Kling
f1f14945cf LibJS: Rename collect_roots() => gather_roots()
Since this is about finding the things we should *not* garabge collect,
it seemed wrong to call it "collect_something" :^)
2020-03-15 15:13:24 +01:00
Andreas Kling
8dc6416bba LibJS: Use the same StringPrototype globally
To make sure that everyone has the same instance of StringPrototype,
hang a global prototype off of the Interpreter that can be fetched
when constructing new StringObjects.
2020-03-15 15:11:13 +01:00
Andreas Kling
9b4358e150 LibJS: Add Cell::interpreter() convenience helper
This allows you to go from any Cell* to the Interpreter.
2020-03-15 15:08:27 +01:00
Andreas Kling
fbefb19e10 LibJS: Interpreter should make sure that the "this" stack gets marked 2020-03-15 15:07:49 +01:00
Andreas Kling
2c5b9fb8f9 LibJS: Add StringPrototype and make it the prototype of StringObject
This patch adds String.prototype.charAt() to demonstrate that prototype
property lookup works, and that you can call a prototype function on an
object, and it will do what you expect. :^)
2020-03-15 15:02:49 +01:00
Andreas Kling
f7c15d00c9 LibJS: Add basic prototype support
Object will now traverse up the prototype chain when doing a get().
When a function is called on an object, that object will now also be
the "this" value inside the function. This stuff is probably not very
correct, but we will improve things as we go! :^)
2020-03-15 15:01:10 +01:00
Andreas Kling
d02c37f3e3 LibJS: Add Value::to_i32() helper function 2020-03-15 15:00:18 +01:00
Andreas Kling
8300b78b77 LibWeb: Add missing copyright headers 2020-03-15 10:24:05 +01:00
Shannon Booth
5dc5b8a2b6 LibCore: Rename Udp classes to UDP
The kernel was already using the UDP prefix, and the TCP LibCore classes
are also uppercased. Let's rename for consistency.

Also order the LibCore Makefile alphabetically, because everywhere else
seems to be doing that :)
2020-03-14 23:56:12 +01:00
0xtechnobabble
2e90a7eb2d LibJS/Parser: Implement the parsing of unary/prefixed update expressions 2020-03-14 20:02:53 +01:00
0xtechnobabble
db64f364f0 LibJS/AST: Implement prefixed update expressions 2020-03-14 20:02:53 +01:00
0xtechnobabble
20a0fc5576 LibJS: Rename BitNot -> BitwiseNot to match other bitwise operators 2020-03-14 20:02:53 +01:00
Stephan Unverwerth
3389021291 LibJS: Unescape strings in Token::string_value() 2020-03-14 16:00:28 +01:00
0xtechnobabble
644b4f4201 LibJS: Evaluate for statements in their own scope if necessary
We now evaluate for loops in their own scope if their init statement is
a lexical declaration.

Evaluating for loops in their own scope allow us to obtain expected
behaviour, which means for example, that the block-scoped variables
declared in a  for statement will be limited to the scope of the for
loop's body and  statement and not to that of the current scope (i.e the
one where the for statement was made)
2020-03-14 13:58:30 +01:00
0xtechnobabble
0659d07241 LibJS/Parser: Remove superfluous switch case 2020-03-14 13:58:30 +01:00
Andreas Kling
b5a22fc408 LibWeb: Implement Document.getElementById()
This was pleasantly simple! We don't have an ElementWrapper yet, so it
just returns a NodeWrapper, but it still basically works. :^)
2020-03-14 13:25:40 +01:00
Andreas Kling
1c406294fc LibWeb: Start implementing basic JavaScript DOM bindings
This patch introduces the Wrapper and Wrappable classes.

Node now inherits from Wrappable, and can be wrapped in a GC-allocated
Bindings::NodeWrapper object. The only property we expose right now is
the very simple nodeName property.

When a Document's JS::Interpreter is first instantiated, we add a
"document" property with a DocumentWrapper object to the global object.

This is pretty cool! :^)
2020-03-14 13:25:40 +01:00
Andreas Kling
9c9d3f0904 LibWeb: Parse <script> elements and run any JavaScript found inside
This patch begins integrating LibJS into LibWeb. Document holds the
JS::Interpreter for now, and it is created on demand when you first
call Document::interpreter().

We also add a simple "alert()" function to the global object.
2020-03-14 13:25:38 +01:00
Andreas Kling
f94099f796 LibJS: Strip double-quote characters from StringLiteral tokens
This is very hackish since I'm just doing it to make progress on
something else. :^)
2020-03-14 12:40:06 +01:00
Stephan Unverwerth
c0e6234219 LibJS: Lex single quote strings, escaped chars and unterminated strings 2020-03-14 12:13:53 +01:00
Oriko
d439013903 LibGUI: Highlight new JS tokens 2020-03-14 11:30:31 +01:00
Oriko
e273203d27 LibJS: Add missing tokens to name() 2020-03-14 11:30:31 +01:00
Stephan Unverwerth
15d5b2d29e LibJS: Add operator precedence parsing
Obey precedence and associativity rules when parsing expressions
with chained operators.
2020-03-14 00:11:24 +01:00
Oriko
b4381be0ba LibGUI: Add missing copyright headers 2020-03-13 23:09:58 +01:00
Oriko
2d7f4bea90 LibJS: Fix endless loop in string lexing 2020-03-13 22:53:13 +01:00
Oriko
196352ef67 LibGUI: Add Javascript syntax highlighter 2020-03-13 22:53:13 +01:00
Oriko
c02037e944 LibGUI: Abstract token pair matching 2020-03-13 22:53:13 +01:00
Stephan Unverwerth
ac524b632f LibJS: Fix lexing of the last character in a file
Before this commit the last character in a file would be swallowed.
This also fixes parsing of empty files which would previously ASSERT.
2020-03-13 21:47:57 +01:00
Linus Groh
0e04e2cff0 LibJS: Add parsed parameters to FunctionDeclaration 2020-03-13 20:16:01 +01:00
0xtechnobabble
83ea7bb9e7 LibJS: Don't allow the redeclaration of a var variable using let/const
Previously, we were allowing the redeclaration of a variable with `let`
or `const` if it was declared initially using `var`, we should not
tolerate any form of variable redeclaration using let/const.
2020-03-13 20:15:52 +01:00
Andreas Kling
9f38f4dbfb LibJS: Add Object::put_native_function() for convenience
This makes it a little bit nicer to add native function properties
to JavaScript objects.

Thanks to Sergey for suggesting it! :^)
2020-03-13 11:08:16 +01:00
Andreas Kling
6089d6566b LibJS: Make it possible to go from a Cell* to its Heap&
This patch makes all HeapBlock allocations aligned to their block size,
enabling us to find the HeapBlock* for a given Cell* by simply masking
bits off of the cell address.

Use this to make a simple Heap& getter for Cell, which lets us avoid
plumbing the Heap& everywhere.
2020-03-13 11:08:16 +01:00
Andreas Kling
d9c7009604 LibJS: Split Function into subclasses NativeFunction and ScriptFunction
Both types of functions are now Function and implement calling via:

    virtual Value call(Interpreter&, Vector<Value> arguments);

This removes the need for CallExpression::execute() to care about which
kind of function it's calling. :^)
2020-03-13 11:08:16 +01:00
Andreas Kling
1448f4384d LibJS: Move GlobalObject to its own Object subclass
This is mostly for tidiness at the moment.
2020-03-12 20:11:35 +01:00