This commit is contained in:
Claude
2025-06-27 03:58:14 +02:00
committed by Jarred Sumner
parent f4aa9aa18b
commit e1f9a62094
18 changed files with 1931 additions and 832 deletions

View File

@@ -98,7 +98,6 @@ src/bun.js/bindings/JSYogaConstructor.cpp
src/bun.js/bindings/JSYogaExports.cpp
src/bun.js/bindings/JSYogaModule.cpp
src/bun.js/bindings/JSYogaNode.cpp
src/bun.js/bindings/JSYogaNodeImpl.cpp
src/bun.js/bindings/JSYogaPrototype.cpp
src/bun.js/bindings/linux_perf_tracing.cpp
src/bun.js/bindings/MarkingConstraint.cpp

View File

@@ -121,6 +121,8 @@ src/bun.js/bindings/Exception.zig
src/bun.js/bindings/FetchHeaders.zig
src/bun.js/bindings/FFI.zig
src/bun.js/bindings/generated_classes_list.zig
src/bun.js/bindings/GeneratedBindings.zig
src/bun.js/bindings/GeneratedJS2Native.zig
src/bun.js/bindings/GetterSetter.zig
src/bun.js/bindings/HTTPServerAgent.zig
src/bun.js/bindings/JSArray.zig

View File

@@ -54,6 +54,7 @@ set(BUN_DEPENDENCIES
Lshpack
Mimalloc
TinyCC
Yoga
Zlib
LibArchive # must be loaded after zlib
HdrHistogram # must be loaded after zlib
@@ -61,9 +62,6 @@ set(BUN_DEPENDENCIES
)
include(CloneZstd)
# foreach(dependency ${BUN_DEPENDENCIES})
# include(Clone${dependency})
# endforeach()
# --- Codegen ---

View File

@@ -0,0 +1,18 @@
# Since we already have Yoga cloned, just build it directly
set(YOGA_PATH ${VENDOR_PATH}/yoga)
if(NOT EXISTS ${YOGA_PATH})
message(FATAL_ERROR "Yoga not found at ${YOGA_PATH}. Please clone it manually.")
endif()
# Build Yoga as a subdirectory
add_subdirectory(${YOGA_PATH} ${BUILD_PATH}/yoga EXCLUDE_FROM_ALL)
# Set the include directories
if(TARGET ${bun})
target_include_directories(${bun} PRIVATE ${YOGA_PATH})
target_link_libraries(${bun} PRIVATE yogacore)
endif()
# Create a custom target for consistency with other dependencies
add_custom_target(yoga DEPENDS yogacore)

View File

@@ -72,6 +72,8 @@ BUN_DECLARE_HOST_FUNCTION(Bun__fetch);
BUN_DECLARE_HOST_FUNCTION(Bun__fetchPreconnect);
BUN_DECLARE_HOST_FUNCTION(Bun__randomUUIDv7);
extern "C" JSC::EncodedJSValue Bun__createYogaModule(Zig::GlobalObject*);
using namespace JSC;
using namespace WebCore;
@@ -756,6 +758,7 @@ JSC_DEFINE_HOST_FUNCTION(functionFileURLToPath, (JSC::JSGlobalObject * globalObj
password constructPasswordObject DontDelete|PropertyCallback
pathToFileURL functionPathToFileURL DontDelete|Function 1
peek constructBunPeekObject DontDelete|PropertyCallback
Yoga constructYogaObject DontDelete|PropertyCallback
plugin constructPluginObject ReadOnly|DontDelete|PropertyCallback
randomUUIDv7 Bun__randomUUIDv7 DontDelete|Function 2
readableStreamToArray JSBuiltin Builtin|Function 1
@@ -837,6 +840,8 @@ public:
}
};
static JSValue constructYogaObject(VM& vm, JSObject* bunObject);
#define bunObjectReadableStreamToArrayCodeGenerator WebCore::readableStreamReadableStreamToArrayCodeGenerator
#define bunObjectReadableStreamToArrayBufferCodeGenerator WebCore::readableStreamReadableStreamToArrayBufferCodeGenerator
#define bunObjectReadableStreamToBytesCodeGenerator WebCore::readableStreamReadableStreamToBytesCodeGenerator
@@ -869,6 +874,13 @@ static JSValue constructCookieMapObject(VM& vm, JSObject* bunObject)
return WebCore::JSCookieMap::getConstructor(vm, zigGlobalObject);
}
static JSValue constructYogaObject(VM& vm, JSObject* bunObject)
{
auto* globalObject = jsCast<Zig::GlobalObject*>(bunObject->globalObject());
auto result = Bun__createYogaModule(globalObject);
return JSValue::decode(result);
}
JSC::JSObject* createBunObject(VM& vm, JSObject* globalObject)
{
return JSBunObject::create(vm, jsCast<Zig::GlobalObject*>(globalObject));

View File

@@ -2,11 +2,14 @@
#include "JSYogaConfig.h"
#include "webcore/DOMIsoSubspaces.h"
#include "webcore/DOMClientIsoSubspaces.h"
#include "webcore/WebCoreJSClientData.h"
#include <yoga/Yoga.h>
namespace Bun {
const JSC::ClassInfo JSYogaConfig::s_info = { "Yoga.Config"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSYogaConfig) };
using namespace JSC;
const JSC::ClassInfo JSYogaConfig::s_info = { "Config"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSYogaConfig) };
JSYogaConfig::JSYogaConfig(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure)
@@ -51,7 +54,7 @@ JSC::GCClient::IsoSubspace* JSYogaConfig::subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return WebCore::subspaceForImpl<JSYogaConfig, WebCore::UseCustomHeapCellType::No>(
return WebCore::subspaceForImpl<MyClassT, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForJSYogaConfig.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSYogaConfig = std::forward<decltype(space)>(space); },

View File

@@ -5,6 +5,8 @@
namespace Bun {
using namespace JSC;
const JSC::ClassInfo JSYogaConstants::s_info = { "YogaConstants"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSYogaConstants) };
void JSYogaConstants::finishCreation(JSC::VM& vm)
@@ -12,97 +14,96 @@ void JSYogaConstants::finishCreation(JSC::VM& vm)
Base::finishCreation(vm);
// Align values
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_AUTO"_s), JSC::jsNumber(YGAlignAuto), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_FLEX_START"_s), JSC::jsNumber(YGAlignFlexStart), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_CENTER"_s), JSC::jsNumber(YGAlignCenter), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_FLEX_END"_s), JSC::jsNumber(YGAlignFlexEnd), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_STRETCH"_s), JSC::jsNumber(YGAlignStretch), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_BASELINE"_s), JSC::jsNumber(YGAlignBaseline), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_SPACE_BETWEEN"_s), JSC::jsNumber(YGAlignSpaceBetween), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_SPACE_AROUND"_s), JSC::jsNumber(YGAlignSpaceAround), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_SPACE_EVENLY"_s), JSC::jsNumber(YGAlignSpaceEvenly), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ALIGN_AUTO"_s), JSC::jsNumber(static_cast<int>(YGAlignAuto)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ALIGN_FLEX_START"_s), JSC::jsNumber(static_cast<int>(YGAlignFlexStart)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ALIGN_CENTER"_s), JSC::jsNumber(static_cast<int>(YGAlignCenter)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ALIGN_FLEX_END"_s), JSC::jsNumber(static_cast<int>(YGAlignFlexEnd)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ALIGN_STRETCH"_s), JSC::jsNumber(static_cast<int>(YGAlignStretch)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ALIGN_BASELINE"_s), JSC::jsNumber(static_cast<int>(YGAlignBaseline)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ALIGN_SPACE_BETWEEN"_s), JSC::jsNumber(static_cast<int>(YGAlignSpaceBetween)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ALIGN_SPACE_AROUND"_s), JSC::jsNumber(static_cast<int>(YGAlignSpaceAround)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ALIGN_SPACE_EVENLY"_s), JSC::jsNumber(static_cast<int>(YGAlignSpaceEvenly)), 0);
// Direction values
putDirect(vm, JSC::Identifier::fromString(vm, "DIRECTION_INHERIT"_s), JSC::jsNumber(YGDirectionInherit), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "DIRECTION_LTR"_s), JSC::jsNumber(YGDirectionLTR), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "DIRECTION_RTL"_s), JSC::jsNumber(YGDirectionRTL), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "DIRECTION_INHERIT"_s), JSC::jsNumber(static_cast<int>(YGDirectionInherit)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "DIRECTION_LTR"_s), JSC::jsNumber(static_cast<int>(YGDirectionLTR)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "DIRECTION_RTL"_s), JSC::jsNumber(static_cast<int>(YGDirectionRTL)), 0);
// Display values
putDirect(vm, JSC::Identifier::fromString(vm, "DISPLAY_FLEX"_s), JSC::jsNumber(YGDisplayFlex), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "DISPLAY_NONE"_s), JSC::jsNumber(YGDisplayNone), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "DISPLAY_FLEX"_s), JSC::jsNumber(static_cast<int>(YGDisplayFlex)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "DISPLAY_NONE"_s), JSC::jsNumber(static_cast<int>(YGDisplayNone)), 0);
// Edge values
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_LEFT"_s), JSC::jsNumber(YGEdgeLeft), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_TOP"_s), JSC::jsNumber(YGEdgeTop), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_RIGHT"_s), JSC::jsNumber(YGEdgeRight), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_BOTTOM"_s), JSC::jsNumber(YGEdgeBottom), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_START"_s), JSC::jsNumber(YGEdgeStart), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_END"_s), JSC::jsNumber(YGEdgeEnd), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_HORIZONTAL"_s), JSC::jsNumber(YGEdgeHorizontal), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_VERTICAL"_s), JSC::jsNumber(YGEdgeVertical), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_ALL"_s), JSC::jsNumber(YGEdgeAll), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "EDGE_LEFT"_s), JSC::jsNumber(static_cast<int>(YGEdgeLeft)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "EDGE_TOP"_s), JSC::jsNumber(static_cast<int>(YGEdgeTop)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "EDGE_RIGHT"_s), JSC::jsNumber(static_cast<int>(YGEdgeRight)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "EDGE_BOTTOM"_s), JSC::jsNumber(static_cast<int>(YGEdgeBottom)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "EDGE_START"_s), JSC::jsNumber(static_cast<int>(YGEdgeStart)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "EDGE_END"_s), JSC::jsNumber(static_cast<int>(YGEdgeEnd)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "EDGE_HORIZONTAL"_s), JSC::jsNumber(static_cast<int>(YGEdgeHorizontal)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "EDGE_VERTICAL"_s), JSC::jsNumber(static_cast<int>(YGEdgeVertical)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "EDGE_ALL"_s), JSC::jsNumber(static_cast<int>(YGEdgeAll)), 0);
// Experimental feature values
putDirect(vm, JSC::Identifier::fromString(vm, "EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS"_s), JSC::jsNumber(YGExperimentalFeatureWebFlexBasis), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EXPERIMENTAL_FEATURE_ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE"_s), JSC::jsNumber(YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EXPERIMENTAL_FEATURE_FIX_ABSOLUTE_TRAILING_COLUMN_MARGIN"_s), JSC::jsNumber(YGExperimentalFeatureFixAbsoluteTrailingColumnMargin), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS"_s), JSC::jsNumber(static_cast<int>(YGExperimentalFeatureWebFlexBasis)), 0);
// Flex direction values
putDirect(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_COLUMN"_s), JSC::jsNumber(YGFlexDirectionColumn), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_COLUMN_REVERSE"_s), JSC::jsNumber(YGFlexDirectionColumnReverse), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_ROW"_s), JSC::jsNumber(YGFlexDirectionRow), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_ROW_REVERSE"_s), JSC::jsNumber(YGFlexDirectionRowReverse), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_COLUMN"_s), JSC::jsNumber(static_cast<int>(YGFlexDirectionColumn)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_COLUMN_REVERSE"_s), JSC::jsNumber(static_cast<int>(YGFlexDirectionColumnReverse)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_ROW"_s), JSC::jsNumber(static_cast<int>(YGFlexDirectionRow)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_ROW_REVERSE"_s), JSC::jsNumber(static_cast<int>(YGFlexDirectionRowReverse)), 0);
// Gutter values
putDirect(vm, JSC::Identifier::fromString(vm, "GUTTER_COLUMN"_s), JSC::jsNumber(YGGutterColumn), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "GUTTER_ROW"_s), JSC::jsNumber(YGGutterRow), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "GUTTER_ALL"_s), JSC::jsNumber(YGGutterAll), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "GUTTER_COLUMN"_s), JSC::jsNumber(static_cast<int>(YGGutterColumn)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "GUTTER_ROW"_s), JSC::jsNumber(static_cast<int>(YGGutterRow)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "GUTTER_ALL"_s), JSC::jsNumber(static_cast<int>(YGGutterAll)), 0);
// Justify values
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_FLEX_START"_s), JSC::jsNumber(YGJustifyFlexStart), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_CENTER"_s), JSC::jsNumber(YGJustifyCenter), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_FLEX_END"_s), JSC::jsNumber(YGJustifyFlexEnd), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_SPACE_BETWEEN"_s), JSC::jsNumber(YGJustifySpaceBetween), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_SPACE_AROUND"_s), JSC::jsNumber(YGJustifySpaceAround), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_SPACE_EVENLY"_s), JSC::jsNumber(YGJustifySpaceEvenly), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "JUSTIFY_FLEX_START"_s), JSC::jsNumber(static_cast<int>(YGJustifyFlexStart)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "JUSTIFY_CENTER"_s), JSC::jsNumber(static_cast<int>(YGJustifyCenter)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "JUSTIFY_FLEX_END"_s), JSC::jsNumber(static_cast<int>(YGJustifyFlexEnd)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "JUSTIFY_SPACE_BETWEEN"_s), JSC::jsNumber(static_cast<int>(YGJustifySpaceBetween)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "JUSTIFY_SPACE_AROUND"_s), JSC::jsNumber(static_cast<int>(YGJustifySpaceAround)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "JUSTIFY_SPACE_EVENLY"_s), JSC::jsNumber(static_cast<int>(YGJustifySpaceEvenly)), 0);
// Measure mode values
putDirect(vm, JSC::Identifier::fromString(vm, "MEASURE_MODE_UNDEFINED"_s), JSC::jsNumber(YGMeasureModeUndefined), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "MEASURE_MODE_EXACTLY"_s), JSC::jsNumber(YGMeasureModeExactly), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "MEASURE_MODE_AT_MOST"_s), JSC::jsNumber(YGMeasureModeAtMost), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "MEASURE_MODE_UNDEFINED"_s), JSC::jsNumber(static_cast<int>(YGMeasureModeUndefined)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "MEASURE_MODE_EXACTLY"_s), JSC::jsNumber(static_cast<int>(YGMeasureModeExactly)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "MEASURE_MODE_AT_MOST"_s), JSC::jsNumber(static_cast<int>(YGMeasureModeAtMost)), 0);
// Node type values
putDirect(vm, JSC::Identifier::fromString(vm, "NODE_TYPE_DEFAULT"_s), JSC::jsNumber(YGNodeTypeDefault), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "NODE_TYPE_TEXT"_s), JSC::jsNumber(YGNodeTypeText), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "NODE_TYPE_DEFAULT"_s), JSC::jsNumber(static_cast<int>(YGNodeTypeDefault)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "NODE_TYPE_TEXT"_s), JSC::jsNumber(static_cast<int>(YGNodeTypeText)), 0);
// Overflow values
putDirect(vm, JSC::Identifier::fromString(vm, "OVERFLOW_VISIBLE"_s), JSC::jsNumber(YGOverflowVisible), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "OVERFLOW_HIDDEN"_s), JSC::jsNumber(YGOverflowHidden), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "OVERFLOW_SCROLL"_s), JSC::jsNumber(YGOverflowScroll), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "OVERFLOW_VISIBLE"_s), JSC::jsNumber(static_cast<int>(YGOverflowVisible)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "OVERFLOW_HIDDEN"_s), JSC::jsNumber(static_cast<int>(YGOverflowHidden)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "OVERFLOW_SCROLL"_s), JSC::jsNumber(static_cast<int>(YGOverflowScroll)), 0);
// Position type values
putDirect(vm, JSC::Identifier::fromString(vm, "POSITION_TYPE_STATIC"_s), JSC::jsNumber(YGPositionTypeStatic), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "POSITION_TYPE_RELATIVE"_s), JSC::jsNumber(YGPositionTypeRelative), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "POSITION_TYPE_ABSOLUTE"_s), JSC::jsNumber(YGPositionTypeAbsolute), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "POSITION_TYPE_STATIC"_s), JSC::jsNumber(static_cast<int>(YGPositionTypeStatic)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "POSITION_TYPE_RELATIVE"_s), JSC::jsNumber(static_cast<int>(YGPositionTypeRelative)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "POSITION_TYPE_ABSOLUTE"_s), JSC::jsNumber(static_cast<int>(YGPositionTypeAbsolute)), 0);
// Unit values
putDirect(vm, JSC::Identifier::fromString(vm, "UNIT_UNDEFINED"_s), JSC::jsNumber(YGUnitUndefined), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "UNIT_POINT"_s), JSC::jsNumber(YGUnitPoint), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "UNIT_PERCENT"_s), JSC::jsNumber(YGUnitPercent), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "UNIT_AUTO"_s), JSC::jsNumber(YGUnitAuto), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "UNIT_UNDEFINED"_s), JSC::jsNumber(static_cast<int>(YGUnitUndefined)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "UNIT_POINT"_s), JSC::jsNumber(static_cast<int>(YGUnitPoint)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "UNIT_PERCENT"_s), JSC::jsNumber(static_cast<int>(YGUnitPercent)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "UNIT_AUTO"_s), JSC::jsNumber(static_cast<int>(YGUnitAuto)), 0);
// Wrap values
putDirect(vm, JSC::Identifier::fromString(vm, "WRAP_NO_WRAP"_s), JSC::jsNumber(YGWrapNoWrap), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "WRAP_WRAP"_s), JSC::jsNumber(YGWrapWrap), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "WRAP_WRAP_REVERSE"_s), JSC::jsNumber(YGWrapWrapReverse), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "WRAP_NO_WRAP"_s), JSC::jsNumber(static_cast<int>(YGWrapNoWrap)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "WRAP_WRAP"_s), JSC::jsNumber(static_cast<int>(YGWrapWrap)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "WRAP_WRAP_REVERSE"_s), JSC::jsNumber(static_cast<int>(YGWrapWrapReverse)), 0);
// Errata values
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_NONE"_s), JSC::jsNumber(YGErrataNone), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_STRETCH_FLEX_BASIS"_s), JSC::jsNumber(YGErrataStretchFlexBasis), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_ABSOLUTE_POSITIONING_INCORRECT"_s), JSC::jsNumber(YGErrataAbsolutePositioningIncorrect), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_ABSOLUTE_PERCENT_AGAINST_INNER_SIZE"_s), JSC::jsNumber(YGErrataAbsolutePercentAgainstInnerSize), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_ALL"_s), JSC::jsNumber(YGErrataAll), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_CLASSIC"_s), JSC::jsNumber(YGErrataClassic), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ERRATA_NONE"_s), JSC::jsNumber(static_cast<int>(YGErrataNone)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ERRATA_STRETCH_FLEX_BASIS"_s), JSC::jsNumber(static_cast<int>(YGErrataStretchFlexBasis)), 0);
// YGErrataAbsolutePositioningIncorrect is not available in this version of Yoga
// putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ERRATA_ABSOLUTE_POSITIONING_INCORRECT"_s), JSC::jsNumber(static_cast<int>(YGErrataAbsolutePositioningIncorrect)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ERRATA_ABSOLUTE_PERCENT_AGAINST_INNER_SIZE"_s), JSC::jsNumber(static_cast<int>(YGErrataAbsolutePercentAgainstInnerSize)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ERRATA_ALL"_s), JSC::jsNumber(static_cast<int>(YGErrataAll)), 0);
putDirectWithoutTransition(vm, JSC::Identifier::fromString(vm, "ERRATA_CLASSIC"_s), JSC::jsNumber(static_cast<int>(YGErrataClassic)), 0);
}
} // namespace Bun

View File

@@ -8,6 +8,10 @@
#include <JavaScriptCore/JSCInlines.h>
#include <yoga/Yoga.h>
#ifndef UNLIKELY
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#endif
namespace Bun {
// Forward declarations for constructor functions
@@ -26,7 +30,7 @@ JSYogaConfigConstructor::JSYogaConfigConstructor(JSC::VM& vm, JSC::Structure* st
void JSYogaConfigConstructor::finishCreation(JSC::VM& vm, JSC::JSObject* prototype)
{
Base::finishCreation(vm, 0, "Config"_s);
Base::finishCreation(vm, 0, "Config"_s, PropertyAdditionMode::WithStructureTransition);
putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
// Add static methods - create() is an alias for the constructor
@@ -43,7 +47,7 @@ JSYogaNodeConstructor::JSYogaNodeConstructor(JSC::VM& vm, JSC::Structure* struct
void JSYogaNodeConstructor::finishCreation(JSC::VM& vm, JSC::JSObject* prototype)
{
Base::finishCreation(vm, 1, "Node"_s); // 1 for optional config parameter
Base::finishCreation(vm, 1, "Node"_s, PropertyAdditionMode::WithStructureTransition); // 1 for optional config parameter
putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
// Add static methods - create() is an alias for the constructor
@@ -143,6 +147,7 @@ void setupJSYogaConfigClassStructure(JSC::LazyClassStructure::Initializer& init)
auto* constructor = JSYogaConfigConstructor::create(init.vm, constructorStructure, prototype);
auto* structure = JSYogaConfig::createStructure(init.vm, init.global, prototype);
init.setPrototype(prototype);
init.setStructure(structure);
init.setConstructor(constructor);
@@ -157,6 +162,7 @@ void setupJSYogaNodeClassStructure(JSC::LazyClassStructure::Initializer& init)
auto* constructor = JSYogaNodeConstructor::create(init.vm, constructorStructure, prototype);
auto* structure = JSYogaNode::createStructure(init.vm, init.global, prototype);
init.setPrototype(prototype);
init.setStructure(structure);
init.setConstructor(constructor);

View File

@@ -2,6 +2,8 @@
#include "JSYogaConstructor.h"
#include "ZigGlobalObject.h"
using namespace JSC;
extern "C" {
JSC::EncodedJSValue Bun__JSYogaConfigConstructor(Zig::GlobalObject* globalObject)

View File

@@ -1,10 +1,11 @@
#include "root.h"
#include "JSYogaModule.h"
#include "JSYogaConstants.h"
#include "JSYogaConstructor.h"
#include "JSYogaPrototype.h"
#include <yoga/Yoga.h>
#include "ZigGlobalObject.h"
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/FunctionPrototype.h>
namespace Bun {
@@ -28,6 +29,9 @@ void JSYogaModule::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject
auto* configConstructor = JSYogaConfigConstructor::create(vm,
JSYogaConfigConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()),
configPrototype);
// Set constructor property on prototype
configPrototype->setConstructor(vm, configConstructor);
// Create Node constructor and prototype
auto* nodePrototype = JSYogaNodePrototype::create(vm, globalObject,
@@ -36,24 +40,125 @@ void JSYogaModule::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject
auto* nodeConstructor = JSYogaNodeConstructor::create(vm,
JSYogaNodeConstructor::createStructure(vm, globalObject, globalObject->functionPrototype()),
nodePrototype);
// Set constructor property on prototype
nodePrototype->setConstructor(vm, nodeConstructor);
// Add constructors to module
putDirect(vm, vm.propertyNames->Config, configConstructor, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
putDirect(vm, JSC::Identifier::fromString(vm, "Config"_s), configConstructor, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
putDirect(vm, JSC::Identifier::fromString(vm, "Node"_s), nodeConstructor, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
// Add all constants directly to the Yoga object
auto* constants = JSYogaConstants::create(vm, JSYogaConstants::createStructure(vm, globalObject, JSC::jsNull()));
// Copy all properties from constants object to this module
JSC::PropertyNameArray properties(vm, JSC::PropertyNameMode::StringsAndSymbols, JSC::PrivateSymbolMode::Exclude);
constants->getPropertyNames(globalObject, properties, JSC::DontEnumPropertiesMode::Exclude);
for (const auto& propertyName : properties) {
JSC::PropertySlot slot(constants, JSC::PropertySlot::InternalMethodType::Get);
if (constants->getPropertySlot(globalObject, propertyName, slot)) {
putDirect(vm, propertyName, slot.getValue(globalObject, propertyName), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
}
}
// Add constants
// Align values
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_AUTO"_s), JSC::jsNumber(static_cast<int>(YGAlignAuto)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_FLEX_START"_s), JSC::jsNumber(static_cast<int>(YGAlignFlexStart)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_CENTER"_s), JSC::jsNumber(static_cast<int>(YGAlignCenter)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_FLEX_END"_s), JSC::jsNumber(static_cast<int>(YGAlignFlexEnd)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_STRETCH"_s), JSC::jsNumber(static_cast<int>(YGAlignStretch)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_BASELINE"_s), JSC::jsNumber(static_cast<int>(YGAlignBaseline)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_SPACE_BETWEEN"_s), JSC::jsNumber(static_cast<int>(YGAlignSpaceBetween)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_SPACE_AROUND"_s), JSC::jsNumber(static_cast<int>(YGAlignSpaceAround)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ALIGN_SPACE_EVENLY"_s), JSC::jsNumber(static_cast<int>(YGAlignSpaceEvenly)), 0);
// Box sizing values
putDirect(vm, JSC::Identifier::fromString(vm, "BOX_SIZING_BORDER_BOX"_s), JSC::jsNumber(static_cast<int>(YGBoxSizingBorderBox)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "BOX_SIZING_CONTENT_BOX"_s), JSC::jsNumber(static_cast<int>(YGBoxSizingContentBox)), 0);
// Dimension values
putDirect(vm, JSC::Identifier::fromString(vm, "DIMENSION_WIDTH"_s), JSC::jsNumber(static_cast<int>(YGDimensionWidth)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "DIMENSION_HEIGHT"_s), JSC::jsNumber(static_cast<int>(YGDimensionHeight)), 0);
// Direction values
putDirect(vm, JSC::Identifier::fromString(vm, "DIRECTION_INHERIT"_s), JSC::jsNumber(static_cast<int>(YGDirectionInherit)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "DIRECTION_LTR"_s), JSC::jsNumber(static_cast<int>(YGDirectionLTR)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "DIRECTION_RTL"_s), JSC::jsNumber(static_cast<int>(YGDirectionRTL)), 0);
// Display values
putDirect(vm, JSC::Identifier::fromString(vm, "DISPLAY_FLEX"_s), JSC::jsNumber(static_cast<int>(YGDisplayFlex)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "DISPLAY_NONE"_s), JSC::jsNumber(static_cast<int>(YGDisplayNone)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "DISPLAY_CONTENTS"_s), JSC::jsNumber(static_cast<int>(YGDisplayContents)), 0);
// Edge values
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_LEFT"_s), JSC::jsNumber(static_cast<int>(YGEdgeLeft)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_TOP"_s), JSC::jsNumber(static_cast<int>(YGEdgeTop)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_RIGHT"_s), JSC::jsNumber(static_cast<int>(YGEdgeRight)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_BOTTOM"_s), JSC::jsNumber(static_cast<int>(YGEdgeBottom)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_START"_s), JSC::jsNumber(static_cast<int>(YGEdgeStart)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_END"_s), JSC::jsNumber(static_cast<int>(YGEdgeEnd)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_HORIZONTAL"_s), JSC::jsNumber(static_cast<int>(YGEdgeHorizontal)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_VERTICAL"_s), JSC::jsNumber(static_cast<int>(YGEdgeVertical)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "EDGE_ALL"_s), JSC::jsNumber(static_cast<int>(YGEdgeAll)), 0);
// Errata values
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_NONE"_s), JSC::jsNumber(static_cast<int>(YGErrataNone)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_STRETCH_FLEX_BASIS"_s), JSC::jsNumber(static_cast<int>(YGErrataStretchFlexBasis)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_ABSOLUTE_POSITION_WITHOUT_INSETS_EXCLUDES_PADDING"_s), JSC::jsNumber(static_cast<int>(YGErrataAbsolutePositionWithoutInsetsExcludesPadding)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_ABSOLUTE_PERCENT_AGAINST_INNER_SIZE"_s), JSC::jsNumber(static_cast<int>(YGErrataAbsolutePercentAgainstInnerSize)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_ALL"_s), JSC::jsNumber(static_cast<int>(YGErrataAll)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "ERRATA_CLASSIC"_s), JSC::jsNumber(static_cast<int>(YGErrataClassic)), 0);
// Experimental feature values
putDirect(vm, JSC::Identifier::fromString(vm, "EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS"_s), JSC::jsNumber(static_cast<int>(YGExperimentalFeatureWebFlexBasis)), 0);
// Flex direction values
putDirect(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_COLUMN"_s), JSC::jsNumber(static_cast<int>(YGFlexDirectionColumn)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_COLUMN_REVERSE"_s), JSC::jsNumber(static_cast<int>(YGFlexDirectionColumnReverse)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_ROW"_s), JSC::jsNumber(static_cast<int>(YGFlexDirectionRow)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "FLEX_DIRECTION_ROW_REVERSE"_s), JSC::jsNumber(static_cast<int>(YGFlexDirectionRowReverse)), 0);
// Gutter values
putDirect(vm, JSC::Identifier::fromString(vm, "GUTTER_COLUMN"_s), JSC::jsNumber(static_cast<int>(YGGutterColumn)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "GUTTER_ROW"_s), JSC::jsNumber(static_cast<int>(YGGutterRow)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "GUTTER_ALL"_s), JSC::jsNumber(static_cast<int>(YGGutterAll)), 0);
// Justify values
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_FLEX_START"_s), JSC::jsNumber(static_cast<int>(YGJustifyFlexStart)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_CENTER"_s), JSC::jsNumber(static_cast<int>(YGJustifyCenter)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_FLEX_END"_s), JSC::jsNumber(static_cast<int>(YGJustifyFlexEnd)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_SPACE_BETWEEN"_s), JSC::jsNumber(static_cast<int>(YGJustifySpaceBetween)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_SPACE_AROUND"_s), JSC::jsNumber(static_cast<int>(YGJustifySpaceAround)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "JUSTIFY_SPACE_EVENLY"_s), JSC::jsNumber(static_cast<int>(YGJustifySpaceEvenly)), 0);
// Log level values
putDirect(vm, JSC::Identifier::fromString(vm, "LOG_LEVEL_ERROR"_s), JSC::jsNumber(static_cast<int>(YGLogLevelError)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "LOG_LEVEL_WARN"_s), JSC::jsNumber(static_cast<int>(YGLogLevelWarn)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "LOG_LEVEL_INFO"_s), JSC::jsNumber(static_cast<int>(YGLogLevelInfo)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "LOG_LEVEL_DEBUG"_s), JSC::jsNumber(static_cast<int>(YGLogLevelDebug)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "LOG_LEVEL_VERBOSE"_s), JSC::jsNumber(static_cast<int>(YGLogLevelVerbose)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "LOG_LEVEL_FATAL"_s), JSC::jsNumber(static_cast<int>(YGLogLevelFatal)), 0);
// Measure mode values
putDirect(vm, JSC::Identifier::fromString(vm, "MEASURE_MODE_UNDEFINED"_s), JSC::jsNumber(static_cast<int>(YGMeasureModeUndefined)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "MEASURE_MODE_EXACTLY"_s), JSC::jsNumber(static_cast<int>(YGMeasureModeExactly)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "MEASURE_MODE_AT_MOST"_s), JSC::jsNumber(static_cast<int>(YGMeasureModeAtMost)), 0);
// Node type values
putDirect(vm, JSC::Identifier::fromString(vm, "NODE_TYPE_DEFAULT"_s), JSC::jsNumber(static_cast<int>(YGNodeTypeDefault)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "NODE_TYPE_TEXT"_s), JSC::jsNumber(static_cast<int>(YGNodeTypeText)), 0);
// Overflow values
putDirect(vm, JSC::Identifier::fromString(vm, "OVERFLOW_VISIBLE"_s), JSC::jsNumber(static_cast<int>(YGOverflowVisible)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "OVERFLOW_HIDDEN"_s), JSC::jsNumber(static_cast<int>(YGOverflowHidden)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "OVERFLOW_SCROLL"_s), JSC::jsNumber(static_cast<int>(YGOverflowScroll)), 0);
// Position type values
putDirect(vm, JSC::Identifier::fromString(vm, "POSITION_TYPE_STATIC"_s), JSC::jsNumber(static_cast<int>(YGPositionTypeStatic)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "POSITION_TYPE_RELATIVE"_s), JSC::jsNumber(static_cast<int>(YGPositionTypeRelative)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "POSITION_TYPE_ABSOLUTE"_s), JSC::jsNumber(static_cast<int>(YGPositionTypeAbsolute)), 0);
// Unit values
putDirect(vm, JSC::Identifier::fromString(vm, "UNIT_UNDEFINED"_s), JSC::jsNumber(static_cast<int>(YGUnitUndefined)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "UNIT_POINT"_s), JSC::jsNumber(static_cast<int>(YGUnitPoint)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "UNIT_PERCENT"_s), JSC::jsNumber(static_cast<int>(YGUnitPercent)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "UNIT_AUTO"_s), JSC::jsNumber(static_cast<int>(YGUnitAuto)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "UNIT_MAX_CONTENT"_s), JSC::jsNumber(static_cast<int>(YGUnitMaxContent)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "UNIT_FIT_CONTENT"_s), JSC::jsNumber(static_cast<int>(YGUnitFitContent)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "UNIT_STRETCH"_s), JSC::jsNumber(static_cast<int>(YGUnitStretch)), 0);
// Wrap values
putDirect(vm, JSC::Identifier::fromString(vm, "WRAP_NO_WRAP"_s), JSC::jsNumber(static_cast<int>(YGWrapNoWrap)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "WRAP_WRAP"_s), JSC::jsNumber(static_cast<int>(YGWrapWrap)), 0);
putDirect(vm, JSC::Identifier::fromString(vm, "WRAP_WRAP_REVERSE"_s), JSC::jsNumber(static_cast<int>(YGWrapWrapReverse)), 0);
}
// Export function for Zig integration

View File

@@ -2,11 +2,14 @@
#include "JSYogaNode.h"
#include "webcore/DOMIsoSubspaces.h"
#include "webcore/DOMClientIsoSubspaces.h"
#include "webcore/WebCoreJSClientData.h"
#include <yoga/Yoga.h>
namespace Bun {
const JSC::ClassInfo JSYogaNode::s_info = { "Yoga.Node"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSYogaNode) };
using namespace JSC;
const JSC::ClassInfo JSYogaNode::s_info = { "Node"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSYogaNode) };
JSYogaNode::JSYogaNode(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure)
@@ -67,7 +70,7 @@ JSC::GCClient::IsoSubspace* JSYogaNode::subspaceFor(JSC::VM& vm)
{
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
return nullptr;
return WebCore::subspaceForImpl<JSYogaNode, WebCore::UseCustomHeapCellType::No>(
return WebCore::subspaceForImpl<MyClassT, WebCore::UseCustomHeapCellType::No>(
vm,
[](auto& spaces) { return spaces.m_clientSubspaceForJSYogaNode.get(); },
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSYogaNode = std::forward<decltype(space)>(space); },
@@ -77,7 +80,8 @@ JSC::GCClient::IsoSubspace* JSYogaNode::subspaceFor(JSC::VM& vm)
DEFINE_VISIT_CHILDREN(JSYogaNode);
void JSYogaNode::visitChildrenImpl(JSC::JSCell* cell, JSC::Visitor& visitor)
template<typename Visitor>
void JSYogaNode::visitChildrenImpl(JSC::JSCell* cell, Visitor& visitor)
{
JSYogaNode* thisObject = jsCast<JSYogaNode*>(cell);
Base::visitChildren(thisObject, visitor);

View File

@@ -2,7 +2,7 @@
#include "root.h"
#include <memory>
#include <JavaScriptCore/JSDestructibleObject.h>
#include <JavaScriptCore/Strong.h>
#include <JavaScriptCore/WriteBarrier.h>
// Forward declarations
typedef struct YGNode* YGNodeRef;
@@ -30,14 +30,15 @@ public:
YGNodeRef internal() { return m_node; }
void clearInternal() { m_node = nullptr; }
void setInternal(YGNodeRef node) { m_node = node; }
// Helper to get JS wrapper from Yoga node
static JSYogaNode* fromYGNode(YGNodeRef);
JSC::JSGlobalObject* globalObject() const;
// Storage for JS callbacks
JSC::Strong<JSC::JSObject> m_measureFunc;
JSC::Strong<JSC::JSObject> m_dirtiedFunc;
JSC::WriteBarrier<JSC::JSObject> m_measureFunc;
JSC::WriteBarrier<JSC::JSObject> m_dirtiedFunc;
private:
JSYogaNode(JSC::VM&, JSC::Structure*);

View File

@@ -1,683 +0,0 @@
#include "root.h"
#include "JSYogaNode.h"
#include <JavaScriptCore/JSCInlines.h>
#include <yoga/Yoga.h>
namespace Bun {
// Helper function to parse value arguments (number, string, object, undefined)
static void parseYogaValue(JSC::JSGlobalObject* globalObject, JSC::JSValue arg,
std::function<void(float)> setNumber,
std::function<void(float)> setPercent,
std::function<void()> setAuto,
std::function<void()> setUndefined,
std::function<void()> setMaxContent = nullptr,
std::function<void()> setFitContent = nullptr,
std::function<void()> setStretch = nullptr)
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (arg.isNumber()) {
setNumber(static_cast<float>(arg.asNumber()));
} else if (arg.isString()) {
auto str = arg.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, void());
if (str == "auto"_s) {
setAuto();
} else if (str == "max-content"_s && setMaxContent) {
setMaxContent();
} else if (str == "fit-content"_s && setFitContent) {
setFitContent();
} else if (str == "stretch"_s && setStretch) {
setStretch();
} else if (str.endsWith('%')) {
// Parse percentage
str.remove(str.length() - 1);
float percent = str.toFloat();
setPercent(percent);
} else {
throwTypeError(globalObject, scope, "Invalid string value for style property"_s);
}
} else if (arg.isUndefinedOrNull()) {
setUndefined();
} else if (arg.isObject()) {
// Handle { unit, value } object
JSC::JSObject* obj = arg.getObject();
JSC::JSValue unitValue = obj->get(globalObject, vm.propertyNames->unit);
JSC::JSValue valueValue = obj->get(globalObject, vm.propertyNames->value);
RETURN_IF_EXCEPTION(scope, void());
int32_t unit = unitValue.toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, void());
float value = static_cast<float>(valueValue.toNumber(globalObject));
RETURN_IF_EXCEPTION(scope, void());
switch (static_cast<YGUnit>(unit)) {
case YGUnitPoint:
setNumber(value);
break;
case YGUnitPercent:
setPercent(value);
break;
case YGUnitAuto:
setAuto();
break;
case YGUnitUndefined:
default:
setUndefined();
break;
}
} else {
throwTypeError(globalObject, scope, "Invalid value type for style property"_s);
}
}
// Width/Height setters
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetWidth, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setWidth"_s));
}
if (callFrame->argumentCount() < 1) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
YGNodeRef node = thisObject->internal();
JSC::JSValue arg = callFrame->uncheckedArgument(0);
parseYogaValue(globalObject, arg, [node](float value) { YGNodeStyleSetWidth(node, value); }, [node](float percent) { YGNodeStyleSetWidthPercent(node, percent); }, [node]() { YGNodeStyleSetWidthAuto(node); }, [node]() { YGNodeStyleSetWidth(node, YGUndefined); }, [node]() { YGNodeStyleSetWidthMaxContent(node); }, [node]() { YGNodeStyleSetWidthFitContent(node); }, [node]() { YGNodeStyleSetWidthStretch(node); });
RETURN_IF_EXCEPTION(scope, {});
return JSC::JSValue::encode(JSC::jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetHeight, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setHeight"_s));
}
if (callFrame->argumentCount() < 1) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
YGNodeRef node = thisObject->internal();
JSC::JSValue arg = callFrame->uncheckedArgument(0);
parseYogaValue(globalObject, arg, [node](float value) { YGNodeStyleSetHeight(node, value); }, [node](float percent) { YGNodeStyleSetHeightPercent(node, percent); }, [node]() { YGNodeStyleSetHeightAuto(node); }, [node]() { YGNodeStyleSetHeight(node, YGUndefined); }, [node]() { YGNodeStyleSetHeightMaxContent(node); }, [node]() { YGNodeStyleSetHeightFitContent(node); }, [node]() { YGNodeStyleSetHeightStretch(node); });
RETURN_IF_EXCEPTION(scope, {});
return JSC::JSValue::encode(JSC::jsUndefined());
}
// Edge value setters (margin, padding, position)
static void parseEdgeValue(JSC::JSGlobalObject* globalObject, YGNodeRef node, YGEdge edge, JSC::JSValue arg,
std::function<void(YGNodeRef, YGEdge, float)> setNumber,
std::function<void(YGNodeRef, YGEdge, float)> setPercent,
std::function<void(YGNodeRef, YGEdge)> setAuto)
{
parseYogaValue(globalObject, arg, [node, edge, setNumber](float value) { setNumber(node, edge, value); }, [node, edge, setPercent](float percent) { setPercent(node, edge, percent); }, [node, edge, setAuto]() { if (setAuto) setAuto(node, edge); }, [node, edge, setNumber]() { setNumber(node, edge, YGUndefined); });
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetMargin, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setMargin"_s));
}
if (callFrame->argumentCount() < 2) {
throwTypeError(globalObject, scope, "setMargin requires 2 arguments"_s);
return {};
}
YGNodeRef node = thisObject->internal();
int32_t edge = callFrame->uncheckedArgument(0).toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
JSC::JSValue value = callFrame->uncheckedArgument(1);
parseEdgeValue(globalObject, node, static_cast<YGEdge>(edge), value,
YGNodeStyleSetMargin,
YGNodeStyleSetMarginPercent,
YGNodeStyleSetMarginAuto);
RETURN_IF_EXCEPTION(scope, {});
return JSC::JSValue::encode(JSC::jsUndefined());
}
// Hierarchy methods
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncInsertChild, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "insertChild"_s));
}
if (callFrame->argumentCount() < 2) {
throwTypeError(globalObject, scope, "insertChild requires 2 arguments"_s);
return {};
}
auto* childNode = jsDynamicCast<JSYogaNode*>(callFrame->uncheckedArgument(0));
if (!childNode) {
throwTypeError(globalObject, scope, "First argument must be a Yoga.Node"_s);
return {};
}
int32_t index = callFrame->uncheckedArgument(1).toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
YGNodeInsertChild(thisObject->internal(), childNode->internal(), index);
return JSC::JSValue::encode(JSC::jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetChild, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getChild"_s));
}
if (callFrame->argumentCount() < 1) {
throwTypeError(globalObject, scope, "getChild requires 1 argument"_s);
return {};
}
int32_t index = callFrame->uncheckedArgument(0).toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
YGNodeRef childRef = YGNodeGetChild(thisObject->internal(), index);
JSYogaNode* childNode = childRef ? JSYogaNode::fromYGNode(childRef) : nullptr;
return JSC::JSValue::encode(childNode ? childNode : JSC::jsNull());
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetParent, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getParent"_s));
}
YGNodeRef parentRef = YGNodeGetParent(thisObject->internal());
JSYogaNode* parentNode = parentRef ? JSYogaNode::fromYGNode(parentRef) : nullptr;
return JSC::JSValue::encode(parentNode ? parentNode : JSC::jsNull());
}
// Measure function callback
static YGSize bunMeasureCallback(YGNodeConstRef ygNode, float width, YGMeasureMode widthMode,
float height, YGMeasureMode heightMode)
{
JSYogaNode* jsNode = JSYogaNode::fromYGNode(const_cast<YGNodeRef>(ygNode));
if (!jsNode || !jsNode->m_measureFunc) return { YGUndefined, YGUndefined };
JSC::JSGlobalObject* globalObject = jsNode->globalObject();
JSC::VM& vm = globalObject->vm();
JSC::JSLockHolder lock(vm);
auto scope = DECLARE_CATCH_SCOPE(vm);
JSC::MarkedArgumentBuffer args;
args.append(JSC::jsNumber(width));
args.append(JSC::jsNumber(static_cast<int>(widthMode)));
args.append(JSC::jsNumber(height));
args.append(JSC::jsNumber(static_cast<int>(heightMode)));
JSC::JSValue result = JSC::call(globalObject, jsNode->m_measureFunc.get(), JSC::jsUndefined(), args);
if (scope.exception()) {
scope.clearException();
return { 0, 0 };
}
if (!result.isObject()) return { 0, 0 };
JSC::JSObject* sizeObj = result.getObject();
float resultWidth = sizeObj->get(globalObject, vm.propertyNames->width).toFloat(globalObject);
float resultHeight = sizeObj->get(globalObject, vm.propertyNames->height).toFloat(globalObject);
return { resultWidth, resultHeight };
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetMeasureFunc, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setMeasureFunc"_s));
}
if (callFrame->argumentCount() < 1) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
JSValue func = callFrame->uncheckedArgument(0);
if (func.isUndefinedOrNull()) {
thisObject->m_measureFunc.clear();
YGNodeSetMeasureFunc(thisObject->internal(), nullptr);
} else if (func.isCallable()) {
thisObject->m_measureFunc.set(vm, thisObject, func.getObject());
YGNodeSetMeasureFunc(thisObject->internal(), bunMeasureCallback);
} else {
throwTypeError(globalObject, scope, "Measure function must be callable or null"_s);
return {};
}
return JSC::JSValue::encode(JSC::jsUndefined());
}
// Min/Max setters
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetMinWidth, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setMinWidth"_s));
}
if (callFrame->argumentCount() < 1) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
YGNodeRef node = thisObject->internal();
JSC::JSValue arg = callFrame->uncheckedArgument(0);
parseYogaValue(globalObject, arg, [node](float value) { YGNodeStyleSetMinWidth(node, value); }, [node](float percent) { YGNodeStyleSetMinWidthPercent(node, percent); }, []() { /* no auto for min */ }, [node]() { YGNodeStyleSetMinWidth(node, YGUndefined); });
RETURN_IF_EXCEPTION(scope, {});
return JSC::JSValue::encode(JSC::jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetMinHeight, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setMinHeight"_s));
}
if (callFrame->argumentCount() < 1) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
YGNodeRef node = thisObject->internal();
JSC::JSValue arg = callFrame->uncheckedArgument(0);
parseYogaValue(globalObject, arg, [node](float value) { YGNodeStyleSetMinHeight(node, value); }, [node](float percent) { YGNodeStyleSetMinHeightPercent(node, percent); }, []() { /* no auto for min */ }, [node]() { YGNodeStyleSetMinHeight(node, YGUndefined); });
RETURN_IF_EXCEPTION(scope, {});
return JSC::JSValue::encode(JSC::jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetMaxWidth, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setMaxWidth"_s));
}
if (callFrame->argumentCount() < 1) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
YGNodeRef node = thisObject->internal();
JSC::JSValue arg = callFrame->uncheckedArgument(0);
parseYogaValue(globalObject, arg, [node](float value) { YGNodeStyleSetMaxWidth(node, value); }, [node](float percent) { YGNodeStyleSetMaxWidthPercent(node, percent); }, []() { /* no auto for max */ }, [node]() { YGNodeStyleSetMaxWidth(node, YGUndefined); });
RETURN_IF_EXCEPTION(scope, {});
return JSC::JSValue::encode(JSC::jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetMaxHeight, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setMaxHeight"_s));
}
if (callFrame->argumentCount() < 1) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
YGNodeRef node = thisObject->internal();
JSC::JSValue arg = callFrame->uncheckedArgument(0);
parseYogaValue(globalObject, arg, [node](float value) { YGNodeStyleSetMaxHeight(node, value); }, [node](float percent) { YGNodeStyleSetMaxHeightPercent(node, percent); }, []() { /* no auto for max */ }, [node]() { YGNodeStyleSetMaxHeight(node, YGUndefined); });
RETURN_IF_EXCEPTION(scope, {});
return JSC::JSValue::encode(JSC::jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetFlexBasis, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setFlexBasis"_s));
}
if (callFrame->argumentCount() < 1) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
YGNodeRef node = thisObject->internal();
JSC::JSValue arg = callFrame->uncheckedArgument(0);
parseYogaValue(globalObject, arg, [node](float value) { YGNodeStyleSetFlexBasis(node, value); }, [node](float percent) { YGNodeStyleSetFlexBasisPercent(node, percent); }, [node]() { YGNodeStyleSetFlexBasisAuto(node); }, [node]() { YGNodeStyleSetFlexBasis(node, YGUndefined); });
RETURN_IF_EXCEPTION(scope, {});
return JSC::JSValue::encode(JSC::jsUndefined());
}
// Padding setter
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetPadding, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setPadding"_s));
}
if (callFrame->argumentCount() < 2) {
throwTypeError(globalObject, scope, "setPadding requires 2 arguments"_s);
return {};
}
YGNodeRef node = thisObject->internal();
int32_t edge = callFrame->uncheckedArgument(0).toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
JSC::JSValue value = callFrame->uncheckedArgument(1);
parseEdgeValue(globalObject, node, static_cast<YGEdge>(edge), value,
YGNodeStyleSetPadding,
YGNodeStyleSetPaddingPercent,
nullptr // no auto for padding
);
RETURN_IF_EXCEPTION(scope, {});
return JSC::JSValue::encode(JSC::jsUndefined());
}
// Position setter
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetPosition, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setPosition"_s));
}
if (callFrame->argumentCount() < 2) {
throwTypeError(globalObject, scope, "setPosition requires 2 arguments"_s);
return {};
}
YGNodeRef node = thisObject->internal();
int32_t edge = callFrame->uncheckedArgument(0).toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
JSC::JSValue value = callFrame->uncheckedArgument(1);
parseEdgeValue(globalObject, node, static_cast<YGEdge>(edge), value,
YGNodeStyleSetPosition,
YGNodeStyleSetPositionPercent,
nullptr // no auto for position
);
RETURN_IF_EXCEPTION(scope, {});
return JSC::JSValue::encode(JSC::jsUndefined());
}
// Gap setter
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncSetGap, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "setGap"_s));
}
if (callFrame->argumentCount() < 2) {
throwTypeError(globalObject, scope, "setGap requires 2 arguments"_s);
return {};
}
YGNodeRef node = thisObject->internal();
int32_t gutter = callFrame->uncheckedArgument(0).toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
float gap = static_cast<float>(callFrame->uncheckedArgument(1).toNumber(globalObject));
RETURN_IF_EXCEPTION(scope, {});
YGNodeStyleSetGap(node, static_cast<YGGutter>(gutter), gap);
return JSC::JSValue::encode(JSC::jsUndefined());
}
// Helper to convert YGValue to JSValue
static JSC::JSValue ygValueToJS(JSC::JSGlobalObject* globalObject, YGValue value)
{
JSC::VM& vm = globalObject->vm();
if (YGFloatIsUndefined(value.value)) {
return JSC::jsUndefined();
}
JSC::JSObject* obj = JSC::constructEmptyObject(globalObject);
obj->putDirect(vm, vm.propertyNames->unit, JSC::jsNumber(static_cast<int>(value.unit)));
obj->putDirect(vm, vm.propertyNames->value, JSC::jsNumber(value.value));
return obj;
}
// Style getters
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetWidth, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getWidth"_s));
}
YGValue value = YGNodeStyleGetWidth(thisObject->internal());
return JSC::JSValue::encode(ygValueToJS(globalObject, value));
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetHeight, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getHeight"_s));
}
YGValue value = YGNodeStyleGetHeight(thisObject->internal());
return JSC::JSValue::encode(ygValueToJS(globalObject, value));
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetMinWidth, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getMinWidth"_s));
}
YGValue value = YGNodeStyleGetMinWidth(thisObject->internal());
return JSC::JSValue::encode(ygValueToJS(globalObject, value));
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetMinHeight, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getMinHeight"_s));
}
YGValue value = YGNodeStyleGetMinHeight(thisObject->internal());
return JSC::JSValue::encode(ygValueToJS(globalObject, value));
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetMaxWidth, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getMaxWidth"_s));
}
YGValue value = YGNodeStyleGetMaxWidth(thisObject->internal());
return JSC::JSValue::encode(ygValueToJS(globalObject, value));
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetMaxHeight, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getMaxHeight"_s));
}
YGValue value = YGNodeStyleGetMaxHeight(thisObject->internal());
return JSC::JSValue::encode(ygValueToJS(globalObject, value));
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetFlexBasis, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getFlexBasis"_s));
}
YGValue value = YGNodeStyleGetFlexBasis(thisObject->internal());
return JSC::JSValue::encode(ygValueToJS(globalObject, value));
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetMargin, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getMargin"_s));
}
if (callFrame->argumentCount() < 1) {
throwTypeError(globalObject, scope, "getMargin requires 1 argument"_s);
return {};
}
int32_t edge = callFrame->uncheckedArgument(0).toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
YGValue value = YGNodeStyleGetMargin(thisObject->internal(), static_cast<YGEdge>(edge));
return JSC::JSValue::encode(ygValueToJS(globalObject, value));
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetPadding, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getPadding"_s));
}
if (callFrame->argumentCount() < 1) {
throwTypeError(globalObject, scope, "getPadding requires 1 argument"_s);
return {};
}
int32_t edge = callFrame->uncheckedArgument(0).toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
YGValue value = YGNodeStyleGetPadding(thisObject->internal(), static_cast<YGEdge>(edge));
return JSC::JSValue::encode(ygValueToJS(globalObject, value));
}
JSC_DEFINE_HOST_FUNCTION(jsYogaNodeProtoFuncGetPosition, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* thisObject = jsDynamicCast<JSYogaNode*>(callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
return JSC::JSValue::encode(Bun::throwThisTypeError(*globalObject, scope, "Yoga.Node"_s, "getPosition"_s));
}
if (callFrame->argumentCount() < 1) {
throwTypeError(globalObject, scope, "getPosition requires 1 argument"_s);
return {};
}
int32_t edge = callFrame->uncheckedArgument(0).toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
YGValue value = YGNodeStyleGetPosition(thisObject->internal(), static_cast<YGEdge>(edge));
return JSC::JSValue::encode(ygValueToJS(globalObject, value));
}
} // namespace Bun

File diff suppressed because it is too large Load Diff

View File

@@ -39,6 +39,9 @@ private:
}
void finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject);
public:
void setConstructor(JSC::VM& vm, JSC::JSObject* constructor);
};
class JSYogaNodePrototype final : public JSC::JSNonFinalObject {
@@ -75,6 +78,9 @@ private:
}
void finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject);
public:
void setConstructor(JSC::VM& vm, JSC::JSObject* constructor);
};
} // namespace Bun

View File

@@ -177,6 +177,7 @@
#include "JSPrivateKeyObject.h"
#include "webcore/JSMIMEParams.h"
#include "JSNodePerformanceHooksHistogram.h"
#include "JSYogaConstructor.h"
#include "JSS3File.h"
#include "S3Error.h"
#include "ProcessBindingBuffer.h"
@@ -2811,6 +2812,16 @@ void GlobalObject::finishCreation(VM& vm)
setupHTTPParserClassStructure(init);
});
m_JSYogaConfigClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
Bun::setupJSYogaConfigClassStructure(init);
});
m_JSYogaNodeClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
Bun::setupJSYogaNodeClassStructure(init);
});
m_JSNodePerformanceHooksHistogramClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
Bun::setupJSNodePerformanceHooksHistogramClassStructure(init);

View File

@@ -552,6 +552,9 @@ public:
V(public, LazyClassStructure, m_JSConnectionsListClassStructure) \
V(public, LazyClassStructure, m_JSHTTPParserClassStructure) \
\
V(public, LazyClassStructure, m_JSYogaConfigClassStructure) \
V(public, LazyClassStructure, m_JSYogaNodeClassStructure) \
\
V(private, LazyPropertyOfGlobalObject<Structure>, m_pendingVirtualModuleResultStructure) \
V(private, LazyPropertyOfGlobalObject<JSFunction>, m_performMicrotaskFunction) \
V(private, LazyPropertyOfGlobalObject<JSFunction>, m_nativeMicrotaskTrampoline) \

View File

@@ -1,5 +1,7 @@
import { describe, expect, test } from "bun:test";
const Yoga = Bun.Yoga;
describe("Yoga.Node", () => {
test("Node constructor", () => {
const node = new Yoga.Node();
@@ -174,6 +176,15 @@ describe("Yoga.Node", () => {
};
node.setDirtiedFunc(dirtiedFunc);
// markDirty requires a measure function
node.setMeasureFunc(() => ({ width: 100, height: 50 }));
// Nodes start dirty, so clear the dirty flag first
node.calculateLayout();
expect(node.isDirty()).toBe(false);
// Now mark dirty - this should trigger the callback
node.markDirty();
expect(dirtiedCalled).toBe(true);
@@ -190,24 +201,29 @@ describe("Yoga.Node", () => {
node.reset();
// After reset, values should be back to defaults
// After reset, width/height default to AUTO, not UNDEFINED
const width = node.getWidth();
expect(width.unit).toBe(Yoga.UNIT_UNDEFINED);
expect(width.unit).toBe(Yoga.UNIT_AUTO);
});
test("dirty state", () => {
const node = new Yoga.Node();
// Initially not dirty
expect(node.isDirty()).toBe(false);
// Mark as dirty
node.markDirty();
// Nodes start as dirty by default in Yoga
expect(node.isDirty()).toBe(true);
// Calculate layout clears dirty flag
node.calculateLayout();
expect(node.isDirty()).toBe(false);
// Mark as dirty (requires measure function)
node.setMeasureFunc(() => ({ width: 100, height: 50 }));
node.markDirty();
expect(node.isDirty()).toBe(true);
// Calculate layout clears dirty flag again
node.calculateLayout();
expect(node.isDirty()).toBe(false);
});
test("free node", () => {