1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00
serenity/Libraries/LibJS/Runtime
Andreas Kling ed80952cb6 LibJS: Introduce LexicalEnvironment
This patch replaces the old variable lookup logic with a new one based
on lexical environments.

This brings us closer to the way JavaScript is actually specced, and
also gives us some basic support for closures.

The interpreter's call stack frames now have a pointer to the lexical
environment for that frame. Each lexical environment can have a chain
of parent environments.

Before calling a Function, we first ask it to create_environment().
This gives us a new LexicalEnvironment for that function, which has the
function's lexical parent's environment as its parent. This allows
inner functions to access variables in their outer function:

    function foo() { <-- LexicalEnvironment A
        var x = 1;
        function() { <-- LexicalEnvironment B (parent: A)
            console.log(x);
        }
    }

If we return the result of a function expression from a function, that
new function object will keep a reference to its parent environment,
which is how we get closures. :^)

I'm pretty sure I didn't get everything right here, but it's a pretty
good start. This is quite a bit slower than before, but also correcter!
2020-04-15 22:07:20 +02:00
..
Array.cpp LibJS: Remove shift, pop, push functions from Array object 2020-04-14 13:40:04 +02:00
Array.h LibJS: Remove shift, pop, push functions from Array object 2020-04-14 13:40:04 +02:00
ArrayConstructor.cpp LibJS: Tweak FunctionPrototype::to_string and constructors 2020-04-13 01:14:21 +02:00
ArrayConstructor.h LibJS: Add basic Array constructor 2020-04-04 22:28:21 +02:00
ArrayPrototype.cpp LibJS: Add Array.prototype.join() 2020-04-15 10:06:01 +02:00
ArrayPrototype.h LibJS: Add Array.prototype.join() 2020-04-15 10:06:01 +02:00
BooleanConstructor.cpp LibJS: Tweak FunctionPrototype::to_string and constructors 2020-04-13 01:14:21 +02:00
BooleanConstructor.h LibJS: Reformat BooleanConstructor.{cpp,h} 2020-04-07 17:25:50 +02:00
BooleanObject.cpp LibJS: Boolean, Number and String prototypes should have values too 2020-04-10 13:09:35 +02:00
BooleanObject.h LibJS: Add Boolean constructor object 2020-04-07 08:41:25 +02:00
BooleanPrototype.cpp LibJS: Boolean, Number and String prototypes should have values too 2020-04-10 13:09:35 +02:00
BooleanPrototype.h LibJS: Boolean, Number and String prototypes should have values too 2020-04-10 13:09:35 +02:00
Cell.cpp LibJS: Add "Heap" and "Runtime" subdirectories 2020-03-16 14:37:19 +01:00
Cell.h LibJS: Make JS::Cell non-copyable and non-movable 2020-04-02 15:24:50 +02:00
ConsoleObject.cpp LibJS: Add console.{debug,info,warn,error}() 2020-04-12 18:42:42 +02:00
ConsoleObject.h LibJS: Add console.{debug,info,warn,error}() 2020-04-12 18:42:42 +02:00
Date.cpp LibJS: Start implementing Date :^) 2020-03-30 14:11:54 +02:00
Date.h js: Implement print function for Date objects 2020-03-31 21:19:21 +02:00
DateConstructor.cpp LibJS: Tweak FunctionPrototype::to_string and constructors 2020-04-13 01:14:21 +02:00
DateConstructor.h LibJS: Implement constructor/non-constructor function calls 2020-04-01 20:18:36 +02:00
DatePrototype.cpp LibJS: Throw real TypeError, ReferenceError, etc objects 2020-04-10 13:09:35 +02:00
DatePrototype.h LibJS: Implement Date.prototype.to{Date,Time}String() 2020-03-30 21:43:35 +02:00
Error.cpp LibJS: Use enumerator macros for boilerplate code around native types 2020-04-10 14:06:52 +02:00
Error.h LibJS: Implement Error.prototype.name setter (#1776) 2020-04-13 11:19:53 +02:00
ErrorConstructor.cpp LibJS: Tweak FunctionPrototype::to_string and constructors 2020-04-13 01:14:21 +02:00
ErrorConstructor.h LibJS: Use enumerator macros for boilerplate code around native types 2020-04-10 14:06:52 +02:00
ErrorPrototype.cpp LibJS: Implement Error.prototype.name setter (#1776) 2020-04-13 11:19:53 +02:00
ErrorPrototype.h LibJS: Implement Error.prototype.name setter (#1776) 2020-04-13 11:19:53 +02:00
Exception.cpp LibJS: Implement "throw" 2020-03-24 22:21:58 +01:00
Exception.h LibJS: Implement "throw" 2020-03-24 22:21:58 +01:00
Function.cpp LibJS: Add Function() and Function.prototype 2020-04-04 15:58:49 +02:00
Function.h LibJS: Introduce LexicalEnvironment 2020-04-15 22:07:20 +02:00
FunctionConstructor.cpp LibJS: Tweak FunctionPrototype::to_string and constructors 2020-04-13 01:14:21 +02:00
FunctionConstructor.h LibJS: Add Function() and Function.prototype 2020-04-04 15:58:49 +02:00
FunctionPrototype.cpp LibJS: Tweak FunctionPrototype::to_string and constructors 2020-04-13 01:14:21 +02:00
FunctionPrototype.h LibJS: Add Function() and Function.prototype 2020-04-04 15:58:49 +02:00
GlobalObject.cpp LibJS: Add String constructor :^) 2020-04-10 14:14:02 +02:00
GlobalObject.h LibJS: Use enumerator macros for boilerplate code around native types 2020-04-10 14:06:52 +02:00
LexicalEnvironment.cpp LibJS: Introduce LexicalEnvironment 2020-04-15 22:07:20 +02:00
LexicalEnvironment.h LibJS: Introduce LexicalEnvironment 2020-04-15 22:07:20 +02:00
MathObject.cpp LibJS: Math.round() should call round() instead of roundf() 2020-04-15 19:12:10 +02:00
MathObject.h LibJS: Add Math.{cos,sin,tan}() 2020-04-06 10:58:16 +02:00
NativeFunction.cpp LibJS: Tweak FunctionPrototype::to_string and constructors 2020-04-13 01:14:21 +02:00
NativeFunction.h LibJS: Introduce LexicalEnvironment 2020-04-15 22:07:20 +02:00
NativeProperty.cpp LibJS+LibWeb: Move native properties to separate getters/setters 2020-03-29 00:37:33 +01:00
NativeProperty.h LibJS+LibWeb: Move native properties to separate getters/setters 2020-03-29 00:37:33 +01:00
NumberConstructor.cpp LibJS: Tweak FunctionPrototype::to_string and constructors 2020-04-13 01:14:21 +02:00
NumberConstructor.h LibJS: Add Number.isSafeInteger() 2020-04-07 21:28:43 +02:00
NumberObject.cpp LibJS: Add NumberObject and make to_object() on number values create it 2020-04-04 23:13:13 +02:00
NumberObject.h LibJS: Boolean, Number and String prototypes should have values too 2020-04-10 13:09:35 +02:00
NumberPrototype.cpp LibJS: Boolean, Number and String prototypes should have values too 2020-04-10 13:09:35 +02:00
NumberPrototype.h LibJS: Boolean, Number and String prototypes should have values too 2020-04-10 13:09:35 +02:00
Object.cpp LibJS: Make Function and CallFrame aware of their function name 2020-04-11 14:10:42 +02:00
Object.h LibJS: Add Object.defineProperty() and start caring about attributes 2020-04-10 00:36:06 +02:00
ObjectConstructor.cpp LibJS: Remove shift, pop, push functions from Array object 2020-04-14 13:40:04 +02:00
ObjectConstructor.h LibJS: Add Object.defineProperty() and start caring about attributes 2020-04-10 00:36:06 +02:00
ObjectPrototype.cpp LibJS: Make Object::to_string() call the "toString" property if present 2020-04-05 18:19:56 +02:00
ObjectPrototype.h LibJS+LibWeb: Move native JS functions into dedicated member functions 2020-03-28 23:10:37 +01:00
PrimitiveString.cpp LibJS: Add js_string(Interpreter&, String) 2020-04-04 12:58:05 +02:00
PrimitiveString.h LibJS: Add js_string(Interpreter&, String) 2020-04-04 12:58:05 +02:00
PropertyName.h LibJS: Support array holes, encoded as empty JS::Value 2020-04-06 20:27:44 +02:00
ScriptFunction.cpp LibJS: Introduce LexicalEnvironment 2020-04-15 22:07:20 +02:00
ScriptFunction.h LibJS: Introduce LexicalEnvironment 2020-04-15 22:07:20 +02:00
Shape.cpp LibJS: Key shape transitions on both property name and attributes 2020-04-10 16:33:44 +02:00
Shape.h LibJS: Key shape transitions on both property name and attributes 2020-04-10 16:33:44 +02:00
StringConstructor.cpp LibJS: Tweak FunctionPrototype::to_string and constructors 2020-04-13 01:14:21 +02:00
StringConstructor.h LibJS: Add String constructor :^) 2020-04-10 14:14:02 +02:00
StringObject.cpp LibJS: Add "Heap" and "Runtime" subdirectories 2020-03-16 14:37:19 +01:00
StringObject.h LibJS: Boolean, Number and String prototypes should have values too 2020-04-10 13:09:35 +02:00
StringPrototype.cpp LibJS: Add String.prototype.{trim, trimStart, trimEnd} (#1792) 2020-04-15 08:47:40 +02:00
StringPrototype.h LibJS: Add String.prototype.{trim, trimStart, trimEnd} (#1792) 2020-04-15 08:47:40 +02:00
Value.cpp LibJS: Adding two values should convert them to primitives first 2020-04-15 09:48:25 +02:00
Value.h LibJS: Adding two values should convert them to primitives first 2020-04-15 09:48:25 +02:00