1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 21:17:45 +00:00

Spreadsheet: Override visit_edges() and visit stored JS objects

...and don't let them leak out of their evaluation contexts.
Also keep the exceptions separate from the actual values.
This greatly reduces the number of assertions hit while entering random
data into a sheet.
This commit is contained in:
AnotherTest 2020-12-22 14:18:33 +03:30 committed by Andreas Kling
parent b3a9a25416
commit 7c8d35600c
11 changed files with 110 additions and 43 deletions

View file

@ -27,6 +27,7 @@
#include "Date.h"
#include "../Cell.h"
#include "../Spreadsheet.h"
#include <AK/ScopeGuard.h>
#include <LibCore/DateTime.h>
namespace Spreadsheet {
@ -42,6 +43,12 @@ DateCell::~DateCell()
String DateCell::display(Cell& cell, const CellTypeMetadata& metadata) const
{
ScopeGuard propagate_exception { [&cell] {
if (auto exc = cell.sheet().interpreter().exception()) {
cell.sheet().interpreter().vm().clear_exception();
cell.set_exception(exc);
}
} };
auto timestamp = js_value(cell, metadata);
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());
@ -53,7 +60,8 @@ 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().global_object());
auto js_data = cell.js_data();
auto value = js_data.to_double(cell.sheet().global_object());
return JS::Value(value / 1000); // Turn it to seconds
}

View file

@ -28,6 +28,7 @@
#include "../Cell.h"
#include "../Spreadsheet.h"
#include "Format.h"
#include <AK/ScopeGuard.h>
namespace Spreadsheet {
@ -42,6 +43,12 @@ NumericCell::~NumericCell()
String NumericCell::display(Cell& cell, const CellTypeMetadata& metadata) const
{
ScopeGuard propagate_exception { [&cell] {
if (auto exc = cell.sheet().interpreter().exception()) {
cell.sheet().interpreter().vm().clear_exception();
cell.set_exception(exc);
}
} };
auto value = js_value(cell, metadata);
String string;
if (metadata.format.is_empty())
@ -57,6 +64,12 @@ String NumericCell::display(Cell& cell, const CellTypeMetadata& metadata) const
JS::Value NumericCell::js_value(Cell& cell, const CellTypeMetadata&) const
{
ScopeGuard propagate_exception { [&cell] {
if (auto exc = cell.sheet().interpreter().exception()) {
cell.sheet().interpreter().vm().clear_exception();
cell.set_exception(exc);
}
} };
return cell.js_data().to_number(cell.sheet().global_object());
}