From 0f5fe3b70e01dc570eaa61b5228ee452f360d75c Mon Sep 17 00:00:00 2001 From: davidot Date: Thu, 30 Sep 2021 13:01:09 +0200 Subject: [PATCH] SpreadSheet: Fix that non first sheets could not access global functions Because we declare the functions in runtime.js we need the correct global object to be setup otherwise they cannot be accessed when switching to the SheetGlobalObject. --- Userland/Applications/Spreadsheet/Spreadsheet.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Applications/Spreadsheet/Spreadsheet.cpp b/Userland/Applications/Spreadsheet/Spreadsheet.cpp index 079104ddf34..5c4278bd969 100644 --- a/Userland/Applications/Spreadsheet/Spreadsheet.cpp +++ b/Userland/Applications/Spreadsheet/Spreadsheet.cpp @@ -45,6 +45,9 @@ Sheet::Sheet(Workbook& workbook) global_object().define_direct_property("workbook", m_workbook.workbook_object(), JS::default_attributes); global_object().define_direct_property("thisSheet", &global_object(), JS::default_attributes); // Self-reference is unfortunate, but required. + // Note: We have to set the global object here otherwise the functions in runtime.js are not registered correctly. + interpreter().realm().set_global_object(global_object(), &global_object()); + // Sadly, these have to be evaluated once per sheet. auto file_or_error = Core::File::open("/res/js/Spreadsheet/runtime.js", Core::OpenMode::ReadOnly); if (!file_or_error.is_error()) {