1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:27:35 +00:00

LibJS: Make native function/property callbacks take VM, not Interpreter

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 :^)
This commit is contained in:
Andreas Kling 2020-09-27 18:36:49 +02:00
parent 1ff9d33131
commit 340a115dfe
64 changed files with 1160 additions and 1114 deletions

View file

@ -32,6 +32,7 @@
#include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/ErrorTypes.h>
#include <LibJS/Runtime/Exception.h>
#include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/Value.h>
namespace JS {
@ -206,11 +207,26 @@ public:
const LexicalEnvironment* get_this_environment() const;
Value get_new_target() const;
[[nodiscard]] Value call(Function&, Value this_value, Optional<MarkedValueList> arguments);
template<typename... Args>
[[nodiscard]] ALWAYS_INLINE Value call(Function& function, Value this_value, Args... args)
{
// Are there any values in this argpack?
// args = [] -> if constexpr (false)
// args = [x, y, z] -> if constexpr ((void)x, true || ...)
if constexpr ((((void)args, true) || ...)) {
MarkedValueList arglist { heap() };
(..., arglist.append(move(args)));
return call(function, this_value, move(arglist));
}
return call(function, this_value);
}
private:
VM();
[[nodiscard]] Value call_internal(Function&, Value this_value, Optional<MarkedValueList> arguments);
Exception* m_exception { nullptr };
Heap m_heap;
@ -234,4 +250,13 @@ private:
#undef __JS_ENUMERATE
};
template<>
[[nodiscard]] ALWAYS_INLINE Value VM::call(Function& function, Value this_value, MarkedValueList arguments) { return call_internal(function, this_value, move(arguments)); }
template<>
[[nodiscard]] ALWAYS_INLINE Value VM::call(Function& function, Value this_value, Optional<MarkedValueList> arguments) { return call_internal(function, this_value, move(arguments)); }
template<>
[[nodiscard]] ALWAYS_INLINE Value VM::call(Function& function, Value this_value) { return call(function, this_value, Optional<MarkedValueList> {}); }
}