LibJS: Remove a bunch of unnecessary uses of Cell::interpreter()

We'll want to get rid of all uses of this, to free up the engine from
the old assumption that there's always an Interpreter available.
This commit is contained in:
Andreas Kling 2020-09-27 20:07:25 +02:00
parent 591b7b7031
commit 063acda76e
Notes: sideshowbarker 2024-07-19 02:10:08 +09:00
9 changed files with 13 additions and 21 deletions

View file

@ -25,7 +25,6 @@
*/
#include <AK/Function.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/ArrayPrototype.h>
#include <LibJS/Runtime/Error.h>
@ -35,8 +34,7 @@ namespace JS {
Array* Array::create(GlobalObject& global_object)
{
auto& interpreter = global_object.interpreter();
return interpreter.heap().allocate<Array>(global_object, *global_object.array_prototype());
return global_object.heap().allocate<Array>(global_object, *global_object.array_prototype());
}
Array::Array(Object& prototype)

View file

@ -24,7 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/BooleanObject.h>
#include <LibJS/Runtime/GlobalObject.h>
@ -32,8 +31,7 @@ namespace JS {
BooleanObject* BooleanObject::create(GlobalObject& global_object, bool value)
{
auto& interpreter = global_object.interpreter();
return interpreter.heap().allocate<BooleanObject>(global_object, value, *global_object.boolean_prototype());
return global_object.heap().allocate<BooleanObject>(global_object, value, *global_object.boolean_prototype());
}
BooleanObject::BooleanObject(bool value, Object& prototype)

View file

@ -24,7 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/GlobalObject.h>
@ -32,8 +31,7 @@ namespace JS {
Error* Error::create(GlobalObject& global_object, const FlyString& name, const String& message)
{
auto& interpreter = global_object.interpreter();
return interpreter.heap().allocate<Error>(global_object, name, message, *global_object.error_prototype());
return global_object.heap().allocate<Error>(global_object, name, message, *global_object.error_prototype());
}
Error::Error(const FlyString& name, const String& message, Object& prototype)

View file

@ -67,14 +67,14 @@ BoundFunction* Function::bind(Value bound_this_value, Vector<Value> arguments)
i32 computed_length = 0;
auto length_property = get("length");
if (interpreter().exception())
if (vm().exception())
return nullptr;
if (length_property.is_number())
computed_length = max(0, length_property.as_i32() - static_cast<i32>(arguments.size()));
Object* constructor_prototype = nullptr;
auto prototype_property = target_function.get("prototype");
if (interpreter().exception())
if (vm().exception())
return nullptr;
if (prototype_property.is_object())
constructor_prototype = &prototype_property.as_object();
@ -82,7 +82,7 @@ BoundFunction* Function::bind(Value bound_this_value, Vector<Value> arguments)
auto all_bound_arguments = bound_arguments();
all_bound_arguments.append(move(arguments));
return interpreter().heap().allocate<BoundFunction>(global_object(), global_object(), target_function, bound_this_object, move(all_bound_arguments), computed_length, constructor_prototype);
return heap().allocate<BoundFunction>(global_object(), global_object(), target_function, bound_this_object, move(all_bound_arguments), computed_length, constructor_prototype);
}
void Function::visit_children(Visitor& visitor)

View file

@ -118,7 +118,7 @@ Value LexicalEnvironment::get_this_binding() const
{
ASSERT(has_this_binding());
if (this_binding_status() == ThisBindingStatus::Uninitialized) {
interpreter().vm().throw_exception<ReferenceError>(interpreter().global_object(), ErrorType::ThisHasNotBeenInitialized);
vm().throw_exception<ReferenceError>(interpreter().global_object(), ErrorType::ThisHasNotBeenInitialized);
return {};
}
return m_this_value;
@ -128,7 +128,7 @@ void LexicalEnvironment::bind_this_value(Value this_value)
{
ASSERT(has_this_binding());
if (m_this_binding_status == ThisBindingStatus::Initialized) {
interpreter().vm().throw_exception<ReferenceError>(interpreter().global_object(), ErrorType::ThisIsAlreadyInitialized);
vm().throw_exception<ReferenceError>(interpreter().global_object(), ErrorType::ThisIsAlreadyInitialized);
return;
}
m_this_value = this_value;

View file

@ -70,7 +70,7 @@ Value NativeFunction::construct(Function&)
LexicalEnvironment* NativeFunction::create_environment()
{
return interpreter().heap().allocate<LexicalEnvironment>(global_object(), LexicalEnvironment::EnvironmentRecordType::Function);
return heap().allocate<LexicalEnvironment>(global_object(), LexicalEnvironment::EnvironmentRecordType::Function);
}
}

View file

@ -547,7 +547,7 @@ bool Object::put_own_property_by_index(Object& this_object, u32 property_index,
dbg() << "Disallow define_property of non-extensible object";
#endif
if (throw_exceptions && interpreter().in_strict_mode())
interpreter().vm().throw_exception<TypeError>(global_object(), ErrorType::NonExtensibleDefine, property_index);
vm().throw_exception<TypeError>(global_object(), ErrorType::NonExtensibleDefine, property_index);
return false;
}
@ -566,7 +566,7 @@ bool Object::put_own_property_by_index(Object& this_object, u32 property_index,
dbg() << "Disallow reconfig of non-configurable property";
#endif
if (throw_exceptions)
interpreter().vm().throw_exception<TypeError>(global_object(), ErrorType::DescChangeNonConfigurable, property_index);
vm().throw_exception<TypeError>(global_object(), ErrorType::DescChangeNonConfigurable, property_index);
return false;
}

View file

@ -53,7 +53,7 @@ ScriptFunction* ScriptFunction::create(GlobalObject& global_object, const FlyStr
}
ScriptFunction::ScriptFunction(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, Object& prototype, bool is_arrow_function)
: Function(prototype, is_arrow_function ? interpreter().this_value(global_object) : Value(), {})
: Function(prototype, is_arrow_function ? vm().this_value(global_object) : Value(), {})
, m_name(name)
, m_body(body)
, m_parameters(move(parameters))

View file

@ -25,7 +25,6 @@
*/
#include <AK/Function.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Uint8ClampedArray.h>
@ -34,8 +33,7 @@ namespace JS {
Uint8ClampedArray* Uint8ClampedArray::create(GlobalObject& global_object, u32 length)
{
auto& interpreter = global_object.interpreter();
return interpreter.heap().allocate<Uint8ClampedArray>(global_object, length, *global_object.array_prototype());
return global_object.heap().allocate<Uint8ClampedArray>(global_object, length, *global_object.array_prototype());
}
Uint8ClampedArray::Uint8ClampedArray(u32 length, Object& prototype)