mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
Identify and document LazyClassStructure constructor export issue
## What was achieved - ✅ Fixed SyntheticModuleType enum generation by running bundle-modules.ts - ✅ Successfully build and load node:sqlite module with all exports - ✅ Module correctly exports backup, constants, DatabaseSync, StatementSync - ✅ Identified root cause of constructor instantiation issue ## Constructor Export Issue Analysis - 🔍 **Root Cause**: LazyClassStructure timing conflict with native module exports - 🔍 **Assertion**: `putDirectCustomAccessor` fails during module initialization - 🔍 **Affects**: Both direct constructor export and wrapper function approaches - 🔍 **Timing**: Occurs when accessing JSNodeSQLiteDatabaseSyncStructure() during module init ## Implementation Status - ✅ Module loading works: `require('node:sqlite')` - ✅ Proper API surface: DatabaseSync, StatementSync, constants, backup - ✅ Build system integration complete - ⚠️ Constructor instantiation blocked by JSC assertion - ⚠️ StatementSync properly designed to require database instance ## Files changed - STATUS.md: Updated with detailed analysis and current status - NodeSQLiteModule.cpp: Implemented constructor wrappers (blocked by JSC issue) - NodeSQLiteModule.h: Updated exports to use wrapper functions - test_*.js: Created test files to isolate the issue ## Next Steps - Requires JSC/LazyClassStructure expert knowledge - Alternative: Implement constructors without LazyClassStructure system - Current workaround: Placeholders with error messages 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
#include "NodeSQLiteModule.h"
|
||||
#include "../bindings/sqlite/JSNodeSQLiteDatabaseSync.h"
|
||||
#include "../bindings/sqlite/JSNodeSQLiteStatementSync.h"
|
||||
#include "ZigGlobalObject.h"
|
||||
#include "JavaScriptCore/JSCInlines.h"
|
||||
#include "JavaScriptCore/CallFrame.h"
|
||||
|
||||
namespace Zig {
|
||||
|
||||
using namespace JSC;
|
||||
using namespace WebCore;
|
||||
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeSQLiteBackup, (JSGlobalObject* globalObject, CallFrame* callFrame))
|
||||
{
|
||||
VM& vm = globalObject->vm();
|
||||
@@ -12,4 +20,34 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeSQLiteBackup, (JSGlobalObject* globalObje
|
||||
return {};
|
||||
}
|
||||
|
||||
// Wrapper for DatabaseSync constructor
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeSQLiteDatabaseSyncWrapper, (JSGlobalObject* globalObject, CallFrame* callFrame))
|
||||
{
|
||||
VM& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
|
||||
if (!callFrame->newTarget()) {
|
||||
throwTypeError(globalObject, scope, "Class constructor DatabaseSync cannot be invoked without 'new'"_s);
|
||||
return {};
|
||||
}
|
||||
|
||||
auto* zigGlobalObject = jsCast<GlobalObject*>(defaultGlobalObject(globalObject));
|
||||
Structure* structure = zigGlobalObject->JSNodeSQLiteDatabaseSyncStructure();
|
||||
auto* object = Bun::JSNodeSQLiteDatabaseSync::create(vm, structure);
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
|
||||
return JSValue::encode(object);
|
||||
}
|
||||
|
||||
// Wrapper for StatementSync constructor
|
||||
JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeSQLiteStatementSyncWrapper, (JSGlobalObject* globalObject, CallFrame* callFrame))
|
||||
{
|
||||
VM& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
|
||||
// StatementSync cannot be created directly - it's created via database.prepare()
|
||||
throwTypeError(globalObject, scope, "StatementSync cannot be constructed directly. Use database.prepare() instead."_s);
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace Zig
|
||||
Reference in New Issue
Block a user