From 96c197faf1d3244585f76e40942912adfc3dec3f Mon Sep 17 00:00:00 2001 From: R-Goc Date: Sat, 24 May 2025 23:46:13 +0200 Subject: [PATCH] LibJS: Add minimum changes to build on Windows and run js.exe This commit adds the minimal export macros needed to run js.exe on windows. A followup commit is planned to move to explicit export entirely. A static_assert for the size of a struct is also ifdef'ed out as the semantics around object layout and inheritance are different on MSVC abi and the struct IteratorRecord ends up being 40 bytes not 32. --- Libraries/LibJS/Bytecode/Interpreter.cpp | 3 ++- Libraries/LibJS/Bytecode/Interpreter.h | 2 +- Libraries/LibJS/CMakeLists.txt | 4 ++++ Libraries/LibJS/Contrib/Test262/GlobalObject.h | 3 ++- Libraries/LibJS/Runtime/ErrorTypes.h | 3 ++- Libraries/LibJS/Runtime/Iterator.h | 3 +++ 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Libraries/LibJS/Bytecode/Interpreter.cpp b/Libraries/LibJS/Bytecode/Interpreter.cpp index a75acb443cc..60dd1bba207 100644 --- a/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -1789,7 +1790,7 @@ inline ThrowCompletionOr delete_by_value_with_this(Bytecode::Interpreter& return Value(TRY(reference.delete_(vm))); } -class PropertyNameIterator final +class JS_API PropertyNameIterator final : public Object , public BuiltinIterator { JS_OBJECT(PropertyNameIterator, Object); diff --git a/Libraries/LibJS/Bytecode/Interpreter.h b/Libraries/LibJS/Bytecode/Interpreter.h index cf0678306f9..385cd650f6b 100644 --- a/Libraries/LibJS/Bytecode/Interpreter.h +++ b/Libraries/LibJS/Bytecode/Interpreter.h @@ -104,7 +104,7 @@ private: ExecutionContext* m_running_execution_context { nullptr }; }; -extern bool g_dump_bytecode; +JS_API extern bool g_dump_bytecode; ThrowCompletionOr> compile(VM&, ASTNode const&, JS::FunctionKind kind, FlyString const& name); ThrowCompletionOr> compile(VM&, ECMAScriptFunctionObject const&); diff --git a/Libraries/LibJS/CMakeLists.txt b/Libraries/LibJS/CMakeLists.txt index ad62c22cbb2..1477816b919 100644 --- a/Libraries/LibJS/CMakeLists.txt +++ b/Libraries/LibJS/CMakeLists.txt @@ -290,3 +290,7 @@ else() endif() target_link_libraries(LibJS PUBLIC JSClangPlugin) + +# TODO: Use lagom_generate_export_header and annotate entire LibJS with export macros +include(GenerateExportHeader) +generate_export_header(LibJS EXPORT_MACRO_NAME JS_API EXPORT_FILE_NAME "Export.h") diff --git a/Libraries/LibJS/Contrib/Test262/GlobalObject.h b/Libraries/LibJS/Contrib/Test262/GlobalObject.h index 375742a6ba9..dfbfca918b6 100644 --- a/Libraries/LibJS/Contrib/Test262/GlobalObject.h +++ b/Libraries/LibJS/Contrib/Test262/GlobalObject.h @@ -7,11 +7,12 @@ #pragma once #include +#include #include namespace JS::Test262 { -class GlobalObject final : public JS::GlobalObject { +class JS_API GlobalObject final : public JS::GlobalObject { JS_OBJECT(GlobalObject, JS::GlobalObject); GC_DECLARE_ALLOCATOR(GlobalObject); diff --git a/Libraries/LibJS/Runtime/ErrorTypes.h b/Libraries/LibJS/Runtime/ErrorTypes.h index bd6efc065ff..6d9f4392fab 100644 --- a/Libraries/LibJS/Runtime/ErrorTypes.h +++ b/Libraries/LibJS/Runtime/ErrorTypes.h @@ -8,6 +8,7 @@ #include #include +#include #define JS_ENUMERATE_ERROR_TYPES(M) \ M(AccessorBadField, "Accessor descriptor's '{}' field must be a function or undefined") \ @@ -306,7 +307,7 @@ namespace JS { -class ErrorType { +class JS_API ErrorType { public: #define __ENUMERATE_JS_ERROR(name, message) \ static const ErrorType name; diff --git a/Libraries/LibJS/Runtime/Iterator.h b/Libraries/LibJS/Runtime/Iterator.h index b7c6598c78d..3034d5d3ba2 100644 --- a/Libraries/LibJS/Runtime/Iterator.h +++ b/Libraries/LibJS/Runtime/Iterator.h @@ -37,7 +37,10 @@ private: virtual void visit_edges(Cell::Visitor&) override; }; +// msvc abi semantics about layout with inheritance differ from Sys-V +#if !defined(AK_OS_WINDOWS) static_assert(sizeof(IteratorRecord) == 32); +#endif class Iterator : public Object { JS_OBJECT(Iterator, Object);