diff options
author | Linus Groh <mail@linusgroh.de> | 2021-10-08 20:37:21 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-09 14:29:20 +0100 |
commit | cf168fac5002a1f66559dcf96719368d167596bc (patch) | |
tree | ed32522fdaed63d35cb2ac76b7b22bcde9c24fc4 /Userland/Libraries/LibJS/AST.cpp | |
parent | 58c34012dd5fd48e2e3800d6f374ecc82e91da1e (diff) | |
download | serenity-cf168fac5002a1f66559dcf96719368d167596bc.zip |
LibJS: Implement [[Call]] and [[Construct]] internal slots properly
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
:^)
Diffstat (limited to 'Userland/Libraries/LibJS/AST.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/AST.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 6e82d9bc7f..239fb679cb 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -388,7 +388,7 @@ Value SuperCall::execute(Interpreter& interpreter, GlobalObject& global_object) // 11. Perform ? InitializeInstanceElements(result, F). VERIFY(result.is_object()); - vm.initialize_instance_elements(result.as_object(), f); + TRY_OR_DISCARD(vm.initialize_instance_elements(result.as_object(), f)); // 12. Return result. return result; @@ -1205,6 +1205,8 @@ Value ClassDeclaration::execute(Interpreter& interpreter, GlobalObject& global_o // 15.7.14 Runtime Semantics: ClassDefinitionEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-classdefinitionevaluation ThrowCompletionOr<Value> ClassExpression::class_definition_evaluation(Interpreter& interpreter, GlobalObject& global_object, FlyString const& binding_name, FlyString const& class_name) const { + // FIXME: Clean up this mix of "spec", "somewhat spec", and "not spec at all". + auto& vm = interpreter.vm(); auto* environment = vm.lexical_environment(); VERIFY(environment); |