summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/FunctionObject.h
AgeCommit message (Collapse)Author
2022-09-15LibJS: Use correct include + object class for Function{Object,Prototype}Timothy Flynn
Not causing any real issue, just noticed while debugging vptr sanitation errors.
2022-08-23LibJS+LibWeb: Replace GlobalObject with Realm in initialize() functionsLinus Groh
This is a continuation of the previous commit. Calling initialize() is the first thing that's done after allocating a cell on the JS heap - and in the common case of allocating an object, that's where properties are assigned and intrinsics occasionally accessed. Since those are supposed to live on the realm eventually, this is another step into that direction.
2022-08-23LibJS+LibWeb: Replace GlobalObject with Realm in object constructorsLinus Groh
No functional changes - we can still very easily get to the global object via `Realm::global_object()`. This is in preparation of moving the intrinsics to the realm and no longer having to pass a global object when allocating any object. In a few (now, and many more in subsequent commits) places we get a realm using `GlobalObject::associated_realm()`, this is intended to be temporary. For example, create() functions will later receive the same treatment and are passed a realm instead of a global object.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-16Libraries: Use default constructors/destructors in LibJSLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-02-09LibJS: Add FunctionObject constructor allowing null prototypeLinus Groh
This just calls through to the Object constructor added in the previous commit.
2022-02-09LibJS: Replace uses of MarkedValueList with MarkedVector<Value>Linus Groh
This is effectively a drop-in replacement.
2022-01-24LibJS: Implement the SetFunctionLength AOLinus Groh
2022-01-24LibJS: Implement the SetFunctionName AOLinus Groh
2022-01-04LibJS: Convert FunctionObject::bind() to ThrowCompletionOrLinus Groh
2021-10-09LibJS: Decouple new_function_environment() from FunctionObjectLinus Groh
Now that only ECMAScriptFunctionObject uses this, we can remove the FunctionObject::new_function_environment() pure virtual method and just implement it as a standalone AO with an ECMAScriptFunctionObject parameter, next to the other NewFooEnvironment AOs.
2021-10-09LibJS: Implement [[Call]] and [[Construct]] internal slots properlyLinus Groh
This patch implements: - Spec compliant [[Call]] and [[Construct]] internal slots, as virtual FunctionObject::internal_{call,construct}(). These effectively replace the old virtual FunctionObject::{call,construct}(), but with several advantages: - Clear and consistent naming, following the object internal methods - Use of completions - internal_construct() returns an Object, and not Value! This has been a source of confusion for a long time, since in the spec there's always an Object returned but the Value return type in LibJS meant that this could not be fully trusted and something could screw you over. - Arguments are passed explicitly in form of a MarkedValueList, allowing manipulation (BoundFunction). We still put them on the execution context as a lot of code depends on it (VM::arguments()), but not from the Call() / Construct() AOs anymore, which now allows for bypassing them and invoking [[Call]] / [[Construct]] directly. Nothing but Call() / Construct() themselves do that at the moment, but future additions to ECMA262 or already existing web specs might. - Spec compliant, standalone Call() and Construct() AOs: currently the closest we have is VM::{call,construct}(), but those try to cater to all the different function object subclasses at once, resulting in a horrible mess and calling AOs with functions they should never be called with; most prominently PrepareForOrdinaryCall and OrdinaryCallBindThis, which are only for ECMAScriptFunctionObject. As a result this also contains an implicit optimization: we no longer need to create a new function environment for NativeFunctions - which, worth mentioning, is what started this whole crusade in the first place :^)
2021-09-30LibJS: Make scoping follow the specdavidot
Before this we used an ad-hoc combination of references and 'variables' stored in a hashmap. This worked in most cases but is not spec like. Additionally hoisting, dynamically naming functions and scope analysis was not done properly. This patch fixes all of that by: - Implement BindingInitialization for destructuring assignment. - Implementing a new ScopePusher which tracks the lexical and var scoped declarations. This hoists functions to the top level if no lexical declaration name overlaps. Furthermore we do checking of redeclarations in the ScopePusher now requiring less checks all over the place. - Add methods for parsing the directives and statement lists instead of having that code duplicated in multiple places. This allows declarations to pushed to the appropriate scope more easily. - Remove the non spec way of storing 'variables' in DeclarativeEnvironment and make Reference follow the spec instead of checking both the bindings and 'variables'. - Remove all scoping related things from the Interpreter. And instead use environments as specified by the spec. This also includes fixing that NativeFunctions did not produce a valid FunctionEnvironment which could cause issues with callbacks and eval. All FunctionObjects now have a valid NewFunctionEnvironment implementation. - Remove execute_statements from Interpreter and instead use ASTNode::execute everywhere this simplifies AST.cpp as you no longer need to worry about which method to call. - Make ScopeNodes setup their own environment. This uses four different methods specified by the spec {Block, Function, Eval, Global}DeclarationInstantiation with the annexB extensions. - Implement and use NamedEvaluation where specified. Additionally there are fixes to things exposed by these changes to eval, {for, for-in, for-of} loops and assignment. Finally it also fixes some tests in test-js which where passing before but not now that we have correct behavior :^).
2021-09-25LibJS: Move has_constructor() from NativeFunction to FunctionObjectLinus Groh
At a later point this will indicate whether some FunctionObject "has a [[Construct]] internal method" (separate from the current FunctionObject call() / construct()), to help with a more spec-compliant implementation of [[Call]] and [[Construct]]. This means that it is no longer relevant to just NativeFunction.
2021-09-25LibJS: Remove unused FunctionObject::environment()Linus Groh
ECMAScriptFunctionObject::environment() can just be non-virtual.
2021-09-25LibJS: Move [[BoundThis]] and [[BoundArguments]] to BoundFunctionLinus Groh
2021-09-25LibJS: Move has_simple_parameter_list to ECMAScriptFunctionObjectLinus Groh
2021-09-25LibJS: Move [[Fields]] to ECMAScriptFunctionObjectLinus Groh
2021-09-25LibJS: Move [[HomeObject]] to ECMAScriptFunctionObjectLinus Groh
2021-09-25LibJS: Move [[ConstructorKind]] to ECMAScriptFunctionObjectLinus Groh
2021-09-25LibJS: Move [[ThisMode]] to ECMAScriptFunctionObjectLinus Groh
2021-09-25LibJS: Rename OrdinaryFunctionObject to ECMAScriptFunctionObjectLinus Groh
The old name is the result of the perhaps somewhat confusingly named abstract operation OrdinaryFunctionCreate(), which creates an "ordinary object" (https://tc39.es/ecma262/#ordinary-object) in contrast to an "exotic object" (https://tc39.es/ecma262/#exotic-object). However, the term "Ordinary Function" is not used anywhere in the spec, instead the created object is referred to as an "ECMAScript Function Object" (https://tc39.es/ecma262/#sec-ecmascript-function-objects), so let's call it that. The "ordinary" vs. "exotic" distinction is important because there are also "Built-in Function Objects", which can be either implemented as ordinary ECMAScript function objects, or as exotic objects (our NativeFunction). More work needs to be done to move a lot of infrastructure to ECMAScriptFunctionObject in order to make FunctionObject nothing more than an interface for objects that implement [[Call]] and optionally [[Construct]].
2021-09-12LibJS: Set the callee context's realm in prepare_for_ordinary_call()Linus Groh
This includes making FunctionObject::realm() actually return a Realm, instead of a GlobalObject.
2021-09-01LibJS: Add support for public fields in classesdavidot
2021-07-05LibJS: Make FunctionObject's m_home_object an Object*, not ValueLinus Groh
As the name implies (and the spec confirms), this is only ever going to be an object or "nothing", or "undefined" in the spec. By taking this literally and updating a check to check for `is_undefined()`, we introduced a bug - the value was still initialized as an empty value. Instead, use a pointer to an Object - either we have one, or we don't. Fixes #8448.
2021-07-01LibJS: Drop "Record" suffix from all the *Environment record classesAndreas Kling
"Records" in the spec are basically C++ classes, so let's drop this mouthful of a suffix.
2021-06-30LibJS: Add a [[Realm]] getter to FunctionObject and use it where neededIdan Horowitz
Defined by https://tc39.es/ecma262/#sec-ordinaryfunctioncreate step #17 and by https://tc39.es/ecma262/#sec-createbuiltinfunction step #6.
2021-06-28LibJS: Use CreateUnmappedArgumentsObject for non-simple parameter listsAndreas Kling
This patch implements the IsSimpleParameterList static semantics for ordinary function objects. We now also create an unmapped arguments object for callee contexts with non-simple parameter lists, instead of only doing it in strict mode. Covered by test262.
2021-06-27LibJS: Rename Function => FunctionObjectAndreas Kling