summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/NativeFunction.h
AgeCommit message (Collapse)Author
2020-09-27LibJS: Remove Interpreter& argument to Function::construct()Andreas Kling
This is no longer needed, we can get everything we need from the VM.
2020-09-27LibJS: Make native function/property callbacks take VM, not InterpreterAndreas Kling
More work on decoupling the general runtime from Interpreter. The goal is becoming clearer. Interpreter should be one possible way to execute code inside a VM. In the future we might have other ways :^)
2020-09-27LibJS: Make Function::call() not require an Interpreter&Andreas Kling
This makes a difference inside ScriptFunction::call(), which will now instantiate a temporary Interpreter if one is not attached to the VM.
2020-09-20LibJS: Remove unused argument in NativeFunction constructorAndreas Kling
2020-07-23LibJS: Simplify Cell::initialize()Andreas Kling
Remove the Interpreter& argument and pass only GlobalObject&. We can find everything we need via the global object anyway.
2020-07-01LibJS: Explicitly pass a "Function& new_target" to Function::constructMatthew Olsson
This allows the proxy handler to pass the proper new.target to construct handlers.
2020-06-29LibJS: Initial class implementation; allow super expressions in objectJack Karamanian
literal methods; add EnvrionmentRecord fields and methods to LexicalEnvironment Adding EnvrionmentRecord's fields and methods lets us throw an exception when |this| is not initialized, which occurs when the super constructor in a derived class has not yet been called, or when |this| has already been initialized (the super constructor was already called).
2020-06-21LibJS+LibWeb: Add JS::Object::inherits(class_name)Andreas Kling
To allow implementing the DOM class hierarchy in JS bindings, this patch adds an inherits() function that can be used to ask an Object if it inherits from a specific C++ class (by name). The necessary overrides are baked into each Object subclass by the new JS_OBJECT macro, which works similarly to C_OBJECT in LibCore. Thanks to @Dexesttp for suggesting this approach. :^)
2020-06-20LibJS: Move native objects towards two-pass constructionAndreas Kling
To make sure that everything is set up correctly in objects before we start adding properties to them, we split cell allocation into 3 steps: 1. Allocate a cell of appropriate size from the Heap 2. Call the C++ constructor on the cell 3. Call initialize() on the constructed object The job of initialize() is to define all the initial properties. Doing it in a second pass guarantees that the Object has a valid Shape and can find its own GlobalObject.
2020-06-20LibJS: Pass GlobalObject& to native functions and property accessorsAndreas Kling
More work towards supporting multiple global objects. Native C++ code now get a GlobalObject& and don't have to ask the Interpreter for it. I've added macros for declaring and defining native callbacks since this was pretty tedious and this makes it easier next time we want to change any of these signatures.
2020-04-18LibJS: Pass prototype to Function constructorsAndreas Kling
2020-04-15LibJS: Introduce LexicalEnvironmentAndreas Kling
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-13LibJS: Tweak FunctionPrototype::to_string and constructorsStephan Unverwerth
The output of FunctionPrototype::to_string is now more in line with the output in Firefox. The builtin constructors have been extended to include their function name in the output.
2020-04-11LibJS: Make Function and CallFrame aware of their function nameLinus Groh
2020-04-01LibJS: Implement constructor/non-constructor function callsLinus Groh
This adds Function::construct() for constructor function calls via `new` keyword. NativeFunction doesn't have constructor behaviour by default, ScriptFunction simply calls call() in construct()
2020-03-28LibJS: Rework how native functions are called to improve |this| valueAndreas Kling
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-28LibJS: Add a global "Object" constructorAndreas Kling
This patch adds an "Object" constructor to the global object. The only function it implements so far is Object.getPrototypeOf().
2020-03-21LibJS+LibWeb: Fix some inconsistencies in NativeFunction callbacksAndreas Kling
These should always pass the arguments in a const Vector<JS::Value>&.
2020-03-17LibJS: Pass argument value vectors as const Vector<Value>&Andreas Kling
Now that Interpreter keeps all arguments in the CallFrame stack, we can just pass a const-reference to the CallFrame's argument vector to each function handler (instead of copying it.)
2020-03-16LibJS: Add "Heap" and "Runtime" subdirectoriesAndreas Kling
Let's try to keep LibJS tidy as it expands. :^)