mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 19:38:58 +00:00
WIP slop
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
#include "NodeVMSourceTextModule.h"
|
||||
|
||||
#include "ErrorCode.h"
|
||||
#include "JSDOMExceptionHandling.h"
|
||||
#include "JSModuleRecord.h"
|
||||
#include "ModuleAnalyzer.h"
|
||||
|
||||
#include <print>
|
||||
|
||||
namespace Bun {
|
||||
using namespace NodeVM;
|
||||
@@ -17,7 +22,6 @@ NodeVMSourceTextModule* NodeVMSourceTextModule::create(VM& vm, JSGlobalObject* g
|
||||
|
||||
JSValue contextValue = args.at(1);
|
||||
if (contextValue.isUndefined()) {
|
||||
// TODO(@heimskr): should this be `globalObject->globalThis()` instead?
|
||||
contextValue = globalObject;
|
||||
} else if (!contextValue.isObject()) {
|
||||
throwArgumentTypeError(*globalObject, scope, 1, "context"_s, "Module"_s, "Module"_s, "object"_s);
|
||||
@@ -49,8 +53,16 @@ NodeVMSourceTextModule* NodeVMSourceTextModule::create(VM& vm, JSGlobalObject* g
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t lineOffset = lineOffsetValue.toUInt32(globalObject);
|
||||
uint32_t columnOffset = columnOffsetValue.toUInt32(globalObject);
|
||||
|
||||
Ref<StringSourceProvider> sourceProvider = StringSourceProvider::create(sourceTextValue.toWTFString(globalObject), SourceOrigin {}, String {}, SourceTaintedOrigin::Untainted,
|
||||
TextPosition { OrdinalNumber::fromZeroBasedInt(lineOffset), OrdinalNumber::fromZeroBasedInt(columnOffset) }, SourceProviderSourceType::Module);
|
||||
|
||||
SourceCode sourceCode(WTFMove(sourceProvider), lineOffset, columnOffset);
|
||||
|
||||
auto* zigGlobalObject = defaultGlobalObject(globalObject);
|
||||
NodeVMSourceTextModule* ptr = new (NotNull, allocateCell<NodeVMSourceTextModule>(vm)) NodeVMSourceTextModule(vm, zigGlobalObject->NodeVMSourceTextModuleStructure(), identifierValue.toWTFString(globalObject));
|
||||
NodeVMSourceTextModule* ptr = new (NotNull, allocateCell<NodeVMSourceTextModule>(vm)) NodeVMSourceTextModule(vm, zigGlobalObject->NodeVMSourceTextModuleStructure(), identifierValue.toWTFString(globalObject), WTFMove(sourceCode));
|
||||
ptr->finishCreation(vm);
|
||||
return ptr;
|
||||
}
|
||||
@@ -60,6 +72,32 @@ void NodeVMSourceTextModule::destroy(JSCell* cell)
|
||||
static_cast<NodeVMSourceTextModule*>(cell)->NodeVMSourceTextModule::~NodeVMSourceTextModule();
|
||||
}
|
||||
|
||||
bool NodeVMSourceTextModule::createModuleRecord(JSGlobalObject* globalObject)
|
||||
{
|
||||
if (m_moduleRecord) {
|
||||
return false;
|
||||
}
|
||||
|
||||
VM& vm = globalObject->vm();
|
||||
|
||||
ModuleAnalyzer analyzer(globalObject, Identifier::fromString(vm, m_identifier), m_sourceCode, {}, {}, AllFeatures);
|
||||
|
||||
JSModuleRecord* moduleRecord = JSModuleRecord::create(globalObject, vm, globalObject->m_moduleRecordStructure.get(globalObject), Identifier::fromString(vm, m_identifier), m_sourceCode, {}, {}, AllFeatures);
|
||||
m_moduleRecord.set(vm, this, moduleRecord);
|
||||
|
||||
std::println("link synchronousness: {}", int(moduleRecord->link(globalObject, JSC::jsUndefined())));
|
||||
|
||||
const auto& requests = moduleRecord->requestedModules();
|
||||
|
||||
std::println("requests: {}", requests.size());
|
||||
|
||||
for (const auto& request : requests) {
|
||||
std::println("request: {}", request.m_specifier->utf8().data());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
EncodedJSValue NodeVMSourceTextModule::link(JSGlobalObject* globalObject, JSArray* specifiers, JSArray* moduleNatives)
|
||||
{
|
||||
const unsigned length = specifiers->getArrayLength();
|
||||
@@ -87,11 +125,50 @@ EncodedJSValue NodeVMSourceTextModule::link(JSGlobalObject* globalObject, JSArra
|
||||
return JSC::encodedJSUndefined();
|
||||
}
|
||||
|
||||
// EncodedJSValue NodeVMSourceTextModule::link(JSGlobalObject* globalObject, JSValue linker)
|
||||
// {
|
||||
// VM& vm = globalObject->vm();
|
||||
// auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
|
||||
// if (status() != Status::Unlinked) {
|
||||
// throwError(globalObject, scope, ErrorCode::ERR_VM_MODULE_ALREADY_LINKED, "Module is already linked"_s);
|
||||
// return {};
|
||||
// }
|
||||
|
||||
// status(Status::Linking);
|
||||
|
||||
// JSModuleRecord* moduleRecord = JSModuleRecord::create(globalObject, vm, globalObject->m_moduleRecordStructure.get(globalObject), Identifier::fromString(vm, m_identifier), m_sourceCode, {}, {}, AllFeatures);
|
||||
|
||||
// Synchronousness synchronousness = moduleRecord->link(globalObject, linker);
|
||||
|
||||
// std::println("synchronousness: {}", int(synchronousness));
|
||||
|
||||
// if (synchronousness == Synchronousness::Sync) {
|
||||
// status(Status::Linked);
|
||||
// }
|
||||
|
||||
// m_moduleRecord.set(vm, this, moduleRecord);
|
||||
|
||||
// return JSC::encodedJSUndefined();
|
||||
// }
|
||||
|
||||
JSObject* NodeVMSourceTextModule::createPrototype(VM& vm, JSGlobalObject* globalObject)
|
||||
{
|
||||
return NodeVMModulePrototype::create(vm, NodeVMModulePrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
|
||||
}
|
||||
|
||||
template<typename Visitor>
|
||||
void NodeVMSourceTextModule::visitChildrenImpl(JSCell* cell, Visitor& visitor)
|
||||
{
|
||||
auto* vmModule = jsCast<NodeVMSourceTextModule*>(cell);
|
||||
ASSERT_GC_OBJECT_INHERITS(vmModule, info());
|
||||
Base::visitChildren(vmModule, visitor);
|
||||
|
||||
visitor.append(vmModule->m_moduleRecord);
|
||||
}
|
||||
|
||||
DEFINE_VISIT_CHILDREN(NodeVMSourceTextModule);
|
||||
|
||||
const JSC::ClassInfo NodeVMSourceTextModule::s_info = { "NodeVMSourceTextModule"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(NodeVMSourceTextModule) };
|
||||
|
||||
} // namespace Bun
|
||||
|
||||
Reference in New Issue
Block a user