Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/bun.js/bindings/AsyncContextFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ const ClassInfo AsyncContextFrame::s_info = { "AsyncContextFrame"_s, &Base::s_in

AsyncContextFrame* AsyncContextFrame::create(VM& vm, JSC::Structure* structure, JSValue callback, JSValue context)
{
AsyncContextFrame* asyncContextData = new (NotNull, allocateCell<AsyncContextFrame>(vm)) AsyncContextFrame(vm, structure);
AsyncContextFrame* asyncContextData = new (NotNull, allocateCell<AsyncContextFrame>(vm)) AsyncContextFrame(vm, structure, callback, context);
asyncContextData->finishCreation(vm);
asyncContextData->callback.set(vm, asyncContextData, callback);
asyncContextData->context.set(vm, asyncContextData, context);
return asyncContextData;
}

Expand All @@ -26,10 +24,8 @@ AsyncContextFrame* AsyncContextFrame::create(JSGlobalObject* global, JSValue cal
auto& vm = global->vm();
ASSERT(callback.isCallable());
auto* structure = jsCast<Zig::GlobalObject*>(global)->AsyncContextFrameStructure();
AsyncContextFrame* asyncContextData = new (NotNull, allocateCell<AsyncContextFrame>(vm)) AsyncContextFrame(vm, structure);
AsyncContextFrame* asyncContextData = new (NotNull, allocateCell<AsyncContextFrame>(vm)) AsyncContextFrame(vm, structure, callback, context);
asyncContextData->finishCreation(vm);
asyncContextData->callback.set(vm, asyncContextData, callback);
asyncContextData->context.set(vm, asyncContextData, context);
return asyncContextData;
}

Expand Down
4 changes: 3 additions & 1 deletion src/bun.js/bindings/AsyncContextFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ class AsyncContextFrame : public JSC::JSNonFinalObject {
[](auto& spaces, auto&& space) { spaces.m_subspaceForAsyncContextFrame = std::forward<decltype(space)>(space); });
}

AsyncContextFrame(JSC::VM& vm, JSC::Structure* structure)
AsyncContextFrame(JSC::VM& vm, JSC::Structure* structure, JSC::JSValue callback_, JSC::JSValue context_)
: JSNonFinalObject(vm, structure)
, callback(callback_, JSC::WriteBarrierEarlyInit)
, context(context_, JSC::WriteBarrierEarlyInit)
{
}
};
8 changes: 4 additions & 4 deletions src/bun.js/bindings/BunPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,26 +429,26 @@ class JSModuleMock final : public JSC::JSNonFinalObject {
void finishCreation(JSC::VM&, JSC::JSObject* callback);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

private:
JSModuleMock(JSC::VM&, JSC::Structure*);
JSModuleMock(JSC::VM&, JSC::Structure*, JSC::JSObject* callback);
};

const JSC::ClassInfo JSModuleMock::s_info = { "ModuleMock"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSModuleMock) };

JSModuleMock* JSModuleMock::create(JSC::VM& vm, JSC::Structure* structure, JSC::JSObject* callback)
{
JSModuleMock* ptr = new (NotNull, JSC::allocateCell<JSModuleMock>(vm)) JSModuleMock(vm, structure);
JSModuleMock* ptr = new (NotNull, JSC::allocateCell<JSModuleMock>(vm)) JSModuleMock(vm, structure, callback);
ptr->finishCreation(vm, callback);
return ptr;
}

void JSModuleMock::finishCreation(JSC::VM& vm, JSObject* callback)
{
Base::finishCreation(vm);
callbackFunctionOrCachedResult.set(vm, this, callback);
}

JSModuleMock::JSModuleMock(JSC::VM& vm, JSC::Structure* structure)
JSModuleMock::JSModuleMock(JSC::VM& vm, JSC::Structure* structure, JSC::JSObject* callback)
: Base(vm, structure)
, callbackFunctionOrCachedResult(callback, JSC::WriteBarrierEarlyInit)
{
}

Expand Down
9 changes: 5 additions & 4 deletions src/bun.js/bindings/InternalModuleRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ const ClassInfo InternalModuleRegistry::s_info = { "InternalModuleRegistry"_s, &
InternalModuleRegistry::InternalModuleRegistry(VM& vm, Structure* structure)
: Base(vm, structure)
{
// Initialize all internal fields to jsUndefined() using WriteBarrierEarlyInit
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
// to avoid triggering write barriers during construction
for (uint8_t i = 0; i < BUN_INTERNAL_MODULE_COUNT; i++) {
this->internalField(static_cast<Field>(i)).setWithoutWriteBarrier(jsUndefined());
}
}

template<typename Visitor>
Expand All @@ -147,10 +152,6 @@ void InternalModuleRegistry::finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));

for (uint8_t i = 0; i < BUN_INTERNAL_MODULE_COUNT; i++) {
this->internalField(static_cast<Field>(i)).set(vm, this, jsUndefined());
}
}

Structure* InternalModuleRegistry::createStructure(VM& vm, JSGlobalObject* globalObject)
Expand Down
12 changes: 6 additions & 6 deletions src/bun.js/bindings/JSBunRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ JSBunRequest* JSBunRequest::create(JSC::VM& vm, JSC::Structure* structure, void*
// We do not want to risk the GC running before this function is called.
Bun__JSRequest__calculateEstimatedByteSize(sinkPtr);

JSBunRequest* ptr = new (NotNull, JSC::allocateCell<JSBunRequest>(vm)) JSBunRequest(vm, structure, sinkPtr);
ptr->finishCreation(vm, params);
JSBunRequest* ptr = new (NotNull, JSC::allocateCell<JSBunRequest>(vm)) JSBunRequest(vm, structure, sinkPtr, params);
ptr->finishCreation(vm);
return ptr;
}

Expand Down Expand Up @@ -148,17 +148,17 @@ void JSBunRequest::setCookies(JSObject* cookies)
Request__setCookiesOnRequestContext(this->wrapped(), WebCoreCast<WebCore::JSCookieMap, WebCore::CookieMap>(JSValue::encode(cookies)));
}

JSBunRequest::JSBunRequest(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
JSBunRequest::JSBunRequest(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr, JSC::JSObject* params)
: Base(vm, structure, sinkPtr)
, m_params(params, JSC::WriteBarrierEarlyInit)
, m_cookies(nullptr, JSC::WriteBarrierEarlyInit)
{
}
extern SYSV_ABI "C" size_t Request__estimatedSize(void* requestPtr);
extern "C" void Bun__JSRequest__calculateEstimatedByteSize(void* requestPtr);
void JSBunRequest::finishCreation(JSC::VM& vm, JSObject* params)
void JSBunRequest::finishCreation(JSC::VM& vm)
{
Base::finishCreation(vm);
m_params.setMayBeNull(vm, this, params);
m_cookies.clear();

auto size = Request__estimatedSize(this->wrapped());
vm.heap.reportExtraMemoryAllocated(this, size);
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/bindings/JSBunRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class JSBunRequest : public JSRequest {
JSBunRequest* clone(JSC::VM& vm, JSGlobalObject* globalObject);

private:
JSBunRequest(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr);
void finishCreation(JSC::VM& vm, JSObject* params);
JSBunRequest(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr, JSC::JSObject* params);
void finishCreation(JSC::VM& vm);

mutable JSC::WriteBarrier<JSC::JSObject> m_params;
mutable JSC::WriteBarrier<JSC::JSObject> m_cookies;
Expand Down
9 changes: 3 additions & 6 deletions src/bun.js/bindings/JSCommonJSModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,13 +817,10 @@ class JSCommonJSModulePrototype final : public JSC::JSNonFinalObject {

const JSC::ClassInfo JSCommonJSModulePrototype::s_info = { "Module"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCommonJSModulePrototype) };

void JSCommonJSModule::finishCreation(JSC::VM& vm, JSC::JSString* id, JSValue filename, JSC::JSString* dirname, const JSC::SourceCode& sourceCode)
void JSCommonJSModule::finishCreation(JSC::VM& vm, const JSC::SourceCode& sourceCode)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
m_id.set(vm, this, id);
m_filename.set(vm, this, filename);
m_dirname.set(vm, this, dirname);
this->sourceCode = sourceCode;
}

Expand All @@ -847,8 +844,8 @@ JSCommonJSModule* JSCommonJSModule::create(
JSC::JSString* dirname,
const JSC::SourceCode& sourceCode)
{
JSCommonJSModule* cell = new (NotNull, JSC::allocateCell<JSCommonJSModule>(vm)) JSCommonJSModule(vm, structure);
cell->finishCreation(vm, id, filename, dirname, sourceCode);
JSCommonJSModule* cell = new (NotNull, JSC::allocateCell<JSCommonJSModule>(vm)) JSCommonJSModule(vm, structure, id, filename, dirname);
cell->finishCreation(vm, sourceCode);
return cell;
}

Expand Down
9 changes: 5 additions & 4 deletions src/bun.js/bindings/JSCommonJSModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ class JSCommonJSModule final : public JSC::JSDestructibleObject {

void clearSourceCode() { sourceCode = JSC::SourceCode(); }

void finishCreation(JSC::VM& vm,
JSC::JSString* id, JSValue filename,
JSC::JSString* dirname, const JSC::SourceCode& sourceCode);
void finishCreation(JSC::VM& vm, const JSC::SourceCode& sourceCode);

static JSC::Structure* createStructure(JSC::JSGlobalObject* globalObject);

Expand Down Expand Up @@ -153,8 +151,11 @@ class JSCommonJSModule final : public JSC::JSDestructibleObject {

bool hasEvaluated = false;

JSCommonJSModule(JSC::VM& vm, JSC::Structure* structure)
JSCommonJSModule(JSC::VM& vm, JSC::Structure* structure, JSC::JSString* id, JSC::JSValue filename, JSC::JSString* dirname)
: Base(vm, structure)
, m_id(id, JSC::WriteBarrierEarlyInit)
, m_filename(filename, JSC::WriteBarrierEarlyInit)
, m_dirname(dirname, JSC::WriteBarrierEarlyInit)
{
}
};
Expand Down
12 changes: 6 additions & 6 deletions src/bun.js/bindings/JSMockFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ class JSMockImplementation final : public JSNonFinalObject {
static JSMockImplementation* create(JSC::JSGlobalObject* globalObject, JSC::Structure* structure, Kind kind, JSC::JSValue heldValue, bool isOnce)
{
auto& vm = JSC::getVM(globalObject);
JSMockImplementation* impl = new (NotNull, allocateCell<JSMockImplementation>(vm)) JSMockImplementation(vm, structure, kind);
impl->finishCreation(vm, heldValue, isOnce ? jsNumber(1) : jsUndefined());
JSMockImplementation* impl = new (NotNull, allocateCell<JSMockImplementation>(vm)) JSMockImplementation(vm, structure, kind, heldValue, isOnce ? jsNumber(1) : jsUndefined());
impl->finishCreation(vm);
return impl;
}

Expand Down Expand Up @@ -195,17 +195,17 @@ class JSMockImplementation final : public JSNonFinalObject {
return !nextValueOrSentinel.get().isUndefined();
}

JSMockImplementation(JSC::VM& vm, JSC::Structure* structure, Kind kind)
JSMockImplementation(JSC::VM& vm, JSC::Structure* structure, Kind kind, JSC::JSValue first, JSC::JSValue second)
: Base(vm, structure)
, underlyingValue(first, JSC::WriteBarrierEarlyInit)
, nextValueOrSentinel(second, JSC::WriteBarrierEarlyInit)
, kind(kind)
{
}

void finishCreation(JSC::VM& vm, JSC::JSValue first, JSC::JSValue second)
void finishCreation(JSC::VM& vm)
{
Base::finishCreation(vm);
this->underlyingValue.set(vm, this, first);
this->nextValueOrSentinel.set(vm, this, second);
}
};

Expand Down
4 changes: 1 addition & 3 deletions src/bun.js/bindings/JSWrappingFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ JS_EXPORT_PRIVATE JSWrappingFunction* JSWrappingFunction::create(

// Structure* structure = globalObject->FFIFunctionStructure();
Structure* structure = JSWrappingFunction::createStructure(vm, globalObject, globalObject->objectPrototype());
JSWrappingFunction* function = new (NotNull, allocateCell<JSWrappingFunction>(vm)) JSWrappingFunction(vm, executable, globalObject, structure);
JSWrappingFunction* function = new (NotNull, allocateCell<JSWrappingFunction>(vm)) JSWrappingFunction(vm, executable, globalObject, structure, wrappedFn);
ASSERT(function->structure()->globalObject());
function->finishCreation(vm, executable, 0, nameStr);

function->m_wrappedFn.set(vm, globalObject, wrappedFn);

return function;
}

Expand Down
3 changes: 2 additions & 1 deletion src/bun.js/bindings/JSWrappingFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ class JSWrappingFunction final : public JSC::JSFunction {
}

private:
JSWrappingFunction(JSC::VM& vm, JSC::NativeExecutable* native, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
JSWrappingFunction(JSC::VM& vm, JSC::NativeExecutable* native, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSC::JSFunction* wrappedFn)
: Base(vm, native, globalObject, structure)
, m_wrappedFn(wrappedFn, JSC::WriteBarrierEarlyInit)
{
}

Expand Down
4 changes: 1 addition & 3 deletions src/bun.js/bindings/NodeVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,9 @@ JSValue NodeVMModule::evaluate(JSGlobalObject* globalObject, uint32_t timeout, b
NodeVMModule::NodeVMModule(JSC::VM& vm, JSC::Structure* structure, WTF::String identifier, JSValue context, JSValue moduleWrapper)
: Base(vm, structure)
, m_identifier(WTFMove(identifier))
, m_context(context.isObject() ? asObject(context) : nullptr, JSC::WriteBarrierEarlyInit)
, m_moduleWrapper(vm, this, moduleWrapper)
{
if (context.isObject()) {
m_context.set(vm, this, asObject(context));
}
}

void NodeVMModule::evaluateDependencies(JSGlobalObject* globalObject, AbstractModuleRecord* record, uint32_t timeout, bool breakOnSigint)
Expand Down
6 changes: 1 addition & 5 deletions src/bun.js/bindings/NodeVMSourceTextModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,10 @@ NodeVMSourceTextModule* NodeVMSourceTextModule::create(VM& vm, JSGlobalObject* g
auto* zigGlobalObject = defaultGlobalObject(globalObject);
WTF::String identifier = identifierValue.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, nullptr);
NodeVMSourceTextModule* ptr = new (NotNull, allocateCell<NodeVMSourceTextModule>(vm)) NodeVMSourceTextModule(vm, zigGlobalObject->NodeVMSourceTextModuleStructure(), WTFMove(identifier), contextValue, WTFMove(sourceCode), moduleWrapper);
NodeVMSourceTextModule* ptr = new (NotNull, allocateCell<NodeVMSourceTextModule>(vm)) NodeVMSourceTextModule(vm, zigGlobalObject->NodeVMSourceTextModuleStructure(), WTFMove(identifier), contextValue, WTFMove(sourceCode), moduleWrapper, initializeImportMeta);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
RETURN_IF_EXCEPTION(scope, nullptr);
ptr->finishCreation(vm);

if (!initializeImportMeta.isUndefined()) {
ptr->m_initializeImportMeta.set(vm, ptr, initializeImportMeta);
}

if (cachedData.isEmpty()) {
return ptr;
}
Expand Down
3 changes: 2 additions & 1 deletion src/bun.js/bindings/NodeVMSourceTextModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class NodeVMSourceTextModule final : public NodeVMModule {
RefPtr<CachedBytecode> m_bytecode;
SourceCode m_sourceCode;

NodeVMSourceTextModule(JSC::VM& vm, JSC::Structure* structure, WTF::String identifier, JSValue context, SourceCode sourceCode, JSValue moduleWrapper)
NodeVMSourceTextModule(JSC::VM& vm, JSC::Structure* structure, WTF::String identifier, JSValue context, SourceCode sourceCode, JSValue moduleWrapper, JSValue initializeImportMeta)
: Base(vm, structure, WTFMove(identifier), context, moduleWrapper)
, m_initializeImportMeta(initializeImportMeta, JSC::WriteBarrierEarlyInit)
, m_sourceCode(WTFMove(sourceCode))
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/bindings/node/JSNodeHTTPServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ JSNodeHTTPServerSocket::JSNodeHTTPServerSocket(JSC::VM& vm, JSC::Structure* stru
: JSC::JSDestructibleObject(vm, structure)
, socket(socket)
, is_ssl(is_ssl)
, currentResponseObject(response, JSC::WriteBarrierEarlyInit)
{
currentResponseObject.setEarlyValue(vm, this, response);
}

void JSNodeHTTPServerSocket::detach()
Expand Down
5 changes: 1 addition & 4 deletions src/bun.js/bindings/node/http/JSConnectionsList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ using namespace JSC;

const ClassInfo JSConnectionsList::s_info = { "ConnectionsList"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSConnectionsList) };

void JSConnectionsList::finishCreation(VM& vm, JSGlobalObject* globalObject, JSSet* allConnections, JSSet* activeConnections)
void JSConnectionsList::finishCreation(VM& vm, JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));

m_allConnections.set(vm, this, allConnections);
m_activeConnections.set(vm, this, activeConnections);
}

template<typename Visitor>
Expand Down
10 changes: 6 additions & 4 deletions src/bun.js/bindings/node/http/JSConnectionsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class JSConnectionsList final : public JSC::JSNonFinalObject {

static JSConnectionsList* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSC::JSSet* allConnectionsSet, JSC::JSSet* activeConnectionsSet)
{
JSConnectionsList* instance = new (NotNull, JSC::allocateCell<JSConnectionsList>(vm)) JSConnectionsList(vm, structure);
instance->finishCreation(vm, globalObject, allConnectionsSet, activeConnectionsSet);
JSConnectionsList* instance = new (NotNull, JSC::allocateCell<JSConnectionsList>(vm)) JSConnectionsList(vm, structure, allConnectionsSet, activeConnectionsSet);
instance->finishCreation(vm, globalObject);
return instance;
}

Expand All @@ -41,10 +41,12 @@ class JSConnectionsList final : public JSC::JSNonFinalObject {
DECLARE_INFO;
DECLARE_VISIT_CHILDREN;

void finishCreation(JSC::VM&, JSC::JSGlobalObject*, JSC::JSSet* allConnectionsSet, JSC::JSSet* activeConnectionsSet);
void finishCreation(JSC::VM&, JSC::JSGlobalObject*);

JSConnectionsList(JSC::VM& vm, JSC::Structure* structure)
JSConnectionsList(JSC::VM& vm, JSC::Structure* structure, JSC::JSSet* allConnections, JSC::JSSet* activeConnections)
: Base(vm, structure)
, m_allConnections(allConnections, JSC::WriteBarrierEarlyInit)
, m_activeConnections(activeConnections, JSC::WriteBarrierEarlyInit)
{
}

Expand Down