1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 10:27:36 +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

@ -43,7 +43,7 @@ DateCell::~DateCell()
String DateCell::display(Cell& cell, const CellTypeMetadata& metadata) const
{
auto timestamp = js_value(cell, metadata);
auto string = Core::DateTime::from_timestamp(timestamp.to_i32(cell.sheet->interpreter())).to_string(metadata.format.is_empty() ? "%Y-%m-%d %H:%M:%S" : metadata.format.characters());
auto string = Core::DateTime::from_timestamp(timestamp.to_i32(cell.sheet->global_object())).to_string(metadata.format.is_empty() ? "%Y-%m-%d %H:%M:%S" : metadata.format.characters());
if (metadata.length >= 0)
return string.substring(0, metadata.length);
@ -53,7 +53,7 @@ String DateCell::display(Cell& cell, const CellTypeMetadata& metadata) const
JS::Value DateCell::js_value(Cell& cell, const CellTypeMetadata&) const
{
auto value = cell.js_data().to_double(cell.sheet->interpreter());
auto value = cell.js_data().to_double(cell.sheet->global_object());
return JS::Value(value / 1000); // Turn it to seconds
}

View file

@ -47,7 +47,7 @@ String NumericCell::display(Cell& cell, const CellTypeMetadata& metadata) const
if (metadata.format.is_empty())
string = value.to_string_without_side_effects();
else
string = format_double(metadata.format.characters(), value.to_double(cell.sheet->interpreter()));
string = format_double(metadata.format.characters(), value.to_double(cell.sheet->global_object()));
if (metadata.length >= 0)
return string.substring(0, metadata.length);
@ -57,7 +57,7 @@ String NumericCell::display(Cell& cell, const CellTypeMetadata& metadata) const
JS::Value NumericCell::js_value(Cell& cell, const CellTypeMetadata&) const
{
return cell.js_data().to_number(cell.sheet->interpreter());
return cell.js_data().to_number(cell.sheet->global_object());
}
}

View file

@ -86,21 +86,21 @@ void SheetGlobalObject::initialize()
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
{
if (interpreter.argument_count() != 1) {
interpreter.vm().throw_exception<JS::TypeError>(global_object, "Expected exactly one argument to parse_cell_name()");
if (vm.argument_count() != 1) {
vm.throw_exception<JS::TypeError>(global_object, "Expected exactly one argument to parse_cell_name()");
return {};
}
auto name_value = interpreter.argument(0);
auto name_value = vm.argument(0);
if (!name_value.is_string()) {
interpreter.vm().throw_exception<JS::TypeError>(global_object, "Expected a String argument to parse_cell_name()");
vm.throw_exception<JS::TypeError>(global_object, "Expected a String argument to parse_cell_name()");
return {};
}
auto position = Sheet::parse_cell_name(name_value.as_string().string());
if (!position.has_value())
return JS::js_undefined();
auto object = JS::Object::create_empty(interpreter.global_object());
object->put("column", JS::js_string(interpreter, position.value().column));
auto object = JS::Object::create_empty(global_object);
object->put("column", JS::js_string(vm, position.value().column));
object->put("row", JS::Value((unsigned)position.value().row));
return object;
@ -124,22 +124,22 @@ void WorkbookObject::initialize(JS::GlobalObject& global_object)
JS_DEFINE_NATIVE_FUNCTION(WorkbookObject::sheet)
{
if (interpreter.argument_count() != 1) {
interpreter.vm().throw_exception<JS::TypeError>(global_object, "Expected exactly one argument to sheet()");
if (vm.argument_count() != 1) {
vm.throw_exception<JS::TypeError>(global_object, "Expected exactly one argument to sheet()");
return {};
}
auto name_value = interpreter.argument(0);
auto name_value = vm.argument(0);
if (!name_value.is_string() && !name_value.is_number()) {
interpreter.vm().throw_exception<JS::TypeError>(global_object, "Expected a String or Number argument to sheet()");
vm.throw_exception<JS::TypeError>(global_object, "Expected a String or Number argument to sheet()");
return {};
}
auto* this_object = interpreter.this_value(global_object).to_object(interpreter, global_object);
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return {};
if (!this_object->inherits("WorkbookObject")) {
interpreter.vm().throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "WorkbookObject");
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "WorkbookObject");
return {};
}