mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 19:08:50 +00:00
upgrade JSC
This commit is contained in:
@@ -23,9 +23,8 @@ class Readable : public JSC::JSNonFinalObject {
|
||||
|
||||
static constexpr unsigned StructureFlags = Base::StructureFlags;
|
||||
|
||||
template <typename CellType, JSC::SubspaceAccess>
|
||||
static JSC::CompleteSubspace *subspaceFor(JSC::VM &vm) {
|
||||
return &vm.cellSpace;
|
||||
template <typename CellType, SubspaceAccess> static GCClient::IsoSubspace *subspaceFor(VM &vm) {
|
||||
return &vm.plainObjectSpace();
|
||||
}
|
||||
|
||||
static JSC::Structure *createStructure(JSC::VM &vm, JSC::JSGlobalObject *globalObject,
|
||||
@@ -36,7 +35,7 @@ class Readable : public JSC::JSNonFinalObject {
|
||||
|
||||
static Readable *create(JSC::VM &vm, Bun__Readable *state, JSC::Structure *structure) {
|
||||
Readable *accessor =
|
||||
new (NotNull, JSC::allocateCell<Bun::Readable>(vm.heap)) Readable(vm, state, structure);
|
||||
new (NotNull, JSC::allocateCell<Bun::Readable>(vm)) Readable(vm, state, structure);
|
||||
accessor->finishCreation(vm);
|
||||
return accessor;
|
||||
}
|
||||
@@ -57,9 +56,8 @@ class Writable : public JSC::JSNonFinalObject {
|
||||
|
||||
static constexpr unsigned StructureFlags = Base::StructureFlags;
|
||||
|
||||
template <typename CellType, JSC::SubspaceAccess>
|
||||
static JSC::CompleteSubspace *subspaceFor(JSC::VM &vm) {
|
||||
return &vm.cellSpace;
|
||||
template <typename CellType, SubspaceAccess> static GCClient::IsoSubspace *subspaceFor(VM &vm) {
|
||||
return &vm.plainObjectSpace();
|
||||
}
|
||||
|
||||
static JSC::Structure *createStructure(JSC::VM &vm, JSC::JSGlobalObject *globalObject,
|
||||
@@ -69,8 +67,9 @@ class Writable : public JSC::JSNonFinalObject {
|
||||
}
|
||||
|
||||
static Writable *create(JSC::VM &vm, Bun__Writable *state, JSC::Structure *structure) {
|
||||
|
||||
Writable *accessor =
|
||||
new (NotNull, JSC::allocateCell<Writable>(vm.heap)) Writable(vm, state, structure);
|
||||
new (NotNull, JSC::allocateCell<Writable>(vm)) Writable(vm, state, structure);
|
||||
accessor->finishCreation(vm);
|
||||
return accessor;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
namespace Zig {
|
||||
|
||||
using namespace JSC;
|
||||
|
||||
class Path : public JSC::JSNonFinalObject {
|
||||
using Base = JSC::JSNonFinalObject;
|
||||
|
||||
@@ -18,9 +20,8 @@ class Path : public JSC::JSNonFinalObject {
|
||||
|
||||
static constexpr unsigned StructureFlags = Base::StructureFlags;
|
||||
|
||||
template <typename CellType, JSC::SubspaceAccess>
|
||||
static JSC::CompleteSubspace *subspaceFor(JSC::VM &vm) {
|
||||
return &vm.cellSpace;
|
||||
template <typename CellType, SubspaceAccess> static GCClient::IsoSubspace *subspaceFor(VM &vm) {
|
||||
return &vm.plainObjectSpace();
|
||||
}
|
||||
|
||||
static JSC::Structure *createStructure(JSC::VM &vm, JSC::JSGlobalObject *globalObject,
|
||||
@@ -30,7 +31,7 @@ class Path : public JSC::JSNonFinalObject {
|
||||
}
|
||||
|
||||
static Path *create(JSC::VM &vm, bool isWindows, JSC::Structure *structure) {
|
||||
Path *accessor = new (NotNull, JSC::allocateCell<Path>(vm.heap)) Path(vm, structure, isWindows);
|
||||
Path *accessor = new (NotNull, JSC::allocateCell<Path>(vm)) Path(vm, structure, isWindows);
|
||||
|
||||
accessor->finishCreation(vm);
|
||||
return accessor;
|
||||
|
||||
@@ -53,7 +53,8 @@ static JSC_DEFINE_HOST_FUNCTION(Process_functionNextTick,
|
||||
|
||||
case 1: {
|
||||
// This is a JSC builtin function
|
||||
globalObject->queueMicrotask(JSC::createJSMicrotask(vm, job));
|
||||
globalObject->queueMicrotask(JSC::createJSMicrotask(vm, job, JSC::JSValue{}, JSC::JSValue{},
|
||||
JSC::JSValue{}, JSC::JSValue{}));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
namespace Zig {
|
||||
|
||||
using namespace JSC;
|
||||
|
||||
class Process : public JSC::JSNonFinalObject {
|
||||
using Base = JSC::JSNonFinalObject;
|
||||
|
||||
@@ -16,9 +18,8 @@ class Process : public JSC::JSNonFinalObject {
|
||||
|
||||
static constexpr unsigned StructureFlags = Base::StructureFlags;
|
||||
|
||||
template <typename CellType, JSC::SubspaceAccess>
|
||||
static JSC::CompleteSubspace *subspaceFor(JSC::VM &vm) {
|
||||
return &vm.cellSpace;
|
||||
template <typename CellType, SubspaceAccess> static GCClient::IsoSubspace *subspaceFor(VM &vm) {
|
||||
return &vm.plainObjectSpace();
|
||||
}
|
||||
|
||||
static JSC::Structure *createStructure(JSC::VM &vm, JSC::JSGlobalObject *globalObject,
|
||||
@@ -28,7 +29,7 @@ class Process : public JSC::JSNonFinalObject {
|
||||
}
|
||||
|
||||
static Process *create(JSC::VM &vm, JSC::Structure *structure) {
|
||||
Process *accessor = new (NotNull, JSC::allocateCell<Process>(vm.heap)) Process(vm, structure);
|
||||
Process *accessor = new (NotNull, JSC::allocateCell<Process>(vm)) Process(vm, structure);
|
||||
accessor->finishCreation(vm);
|
||||
return accessor;
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ using String = WTF::String;
|
||||
|
||||
namespace JSC {
|
||||
|
||||
ALWAYS_INLINE GCDeferralContext::GCDeferralContext(Heap &heap) : m_heap(heap) {}
|
||||
ALWAYS_INLINE GCDeferralContext::GCDeferralContext(VM &vm) : m_vm(vm) {}
|
||||
|
||||
ALWAYS_INLINE GCDeferralContext::~GCDeferralContext() {
|
||||
if constexpr (validateDFGDoesGC) m_heap.verifyCanGC();
|
||||
if constexpr (validateDFGDoesGC) m_vm.verifyCanGC();
|
||||
|
||||
if (UNLIKELY(m_shouldGC)) m_heap.collectIfNecessaryOrDefer();
|
||||
if (UNLIKELY(m_shouldGC)) m_vm.heap.collectIfNecessaryOrDefer();
|
||||
}
|
||||
|
||||
} // namespace JSC
|
||||
@@ -58,7 +58,7 @@ void Zig::ConsoleClient::messageWithTypeAndLevel(MessageType type, MessageLevel
|
||||
JSC::JSGlobalObject *globalObject,
|
||||
Ref<ScriptArguments> &&arguments) {
|
||||
JSC::VM &vm = globalObject->vm();
|
||||
JSC::GCDeferralContext deferralContext(vm.heap);
|
||||
JSC::GCDeferralContext deferralContext(vm);
|
||||
JSC::DisallowGC disallowGC;
|
||||
auto args = arguments.ptr();
|
||||
JSC__JSValue jsArgs[255];
|
||||
|
||||
@@ -8,57 +8,58 @@ namespace Inspector {
|
||||
class InspectorConsoleAgent;
|
||||
class InspectorDebuggerAgent;
|
||||
class InspectorScriptProfilerAgent;
|
||||
}
|
||||
} // namespace Inspector
|
||||
namespace Zig {
|
||||
using InspectorConsoleAgent = Inspector::InspectorConsoleAgent;
|
||||
using InspectorDebuggerAgent = Inspector::InspectorDebuggerAgent;
|
||||
using InspectorScriptProfilerAgent = Inspector::InspectorScriptProfilerAgent;
|
||||
|
||||
using InspectorConsoleAgent = Inspector::InspectorConsoleAgent;
|
||||
using InspectorDebuggerAgent = Inspector::InspectorDebuggerAgent;
|
||||
using InspectorScriptProfilerAgent = Inspector::InspectorScriptProfilerAgent;
|
||||
using namespace JSC;
|
||||
|
||||
class ConsoleClient final : public JSC::ConsoleClient {
|
||||
WTF_MAKE_FAST_ALLOCATED;
|
||||
public:
|
||||
~ConsoleClient() final { }
|
||||
ConsoleClient(void* client) : JSC::ConsoleClient() {
|
||||
m_client = client;
|
||||
}
|
||||
|
||||
WTF_MAKE_FAST_ALLOCATED;
|
||||
|
||||
static bool logToSystemConsole();
|
||||
static void setLogToSystemConsole(bool);
|
||||
public:
|
||||
~ConsoleClient() final {}
|
||||
ConsoleClient(void *client) : JSC::ConsoleClient() { m_client = client; }
|
||||
|
||||
void setDebuggerAgent(InspectorDebuggerAgent* agent) { m_debuggerAgent = agent; }
|
||||
void setPersistentScriptProfilerAgent(InspectorScriptProfilerAgent* agent) { m_scriptProfilerAgent = agent; }
|
||||
static bool logToSystemConsole();
|
||||
static void setLogToSystemConsole(bool);
|
||||
|
||||
void* m_client;
|
||||
private:
|
||||
void setDebuggerAgent(InspectorDebuggerAgent *agent) { m_debuggerAgent = agent; }
|
||||
void setPersistentScriptProfilerAgent(InspectorScriptProfilerAgent *agent) {
|
||||
m_scriptProfilerAgent = agent;
|
||||
}
|
||||
|
||||
void messageWithTypeAndLevel(MessageType, MessageLevel, JSC::JSGlobalObject*, Ref<Inspector::ScriptArguments>&&);
|
||||
void count(JSC::JSGlobalObject*, const String& label);
|
||||
void countReset(JSC::JSGlobalObject*, const String& label);
|
||||
void profile(JSC::JSGlobalObject*, const String& title);
|
||||
void profileEnd(JSC::JSGlobalObject*, const String& title);
|
||||
void takeHeapSnapshot(JSC::JSGlobalObject*, const String& title);
|
||||
void time(JSC::JSGlobalObject*, const String& label);
|
||||
void timeLog(JSC::JSGlobalObject*, const String& label, Ref<Inspector::ScriptArguments>&&);
|
||||
void timeEnd(JSC::JSGlobalObject*, const String& label);
|
||||
void timeStamp(JSC::JSGlobalObject*, Ref<Inspector::ScriptArguments>&&);
|
||||
void record(JSC::JSGlobalObject*, Ref<Inspector::ScriptArguments>&&);
|
||||
void recordEnd(JSC::JSGlobalObject*, Ref<Inspector::ScriptArguments>&&);
|
||||
void screenshot(JSC::JSGlobalObject*, Ref<Inspector::ScriptArguments>&&);
|
||||
void *m_client;
|
||||
|
||||
void warnUnimplemented(const String& method);
|
||||
void internalAddMessage(MessageType, MessageLevel, JSC::JSGlobalObject*, Ref<Inspector::ScriptArguments>&&);
|
||||
private:
|
||||
void messageWithTypeAndLevel(MessageType, MessageLevel, JSC::JSGlobalObject *,
|
||||
Ref<Inspector::ScriptArguments> &&);
|
||||
void count(JSC::JSGlobalObject *, const String &label);
|
||||
void countReset(JSC::JSGlobalObject *, const String &label);
|
||||
void profile(JSC::JSGlobalObject *, const String &title);
|
||||
void profileEnd(JSC::JSGlobalObject *, const String &title);
|
||||
void takeHeapSnapshot(JSC::JSGlobalObject *, const String &title);
|
||||
void time(JSC::JSGlobalObject *, const String &label);
|
||||
void timeLog(JSC::JSGlobalObject *, const String &label, Ref<Inspector::ScriptArguments> &&);
|
||||
void timeEnd(JSC::JSGlobalObject *, const String &label);
|
||||
void timeStamp(JSC::JSGlobalObject *, Ref<Inspector::ScriptArguments> &&);
|
||||
void record(JSC::JSGlobalObject *, Ref<Inspector::ScriptArguments> &&);
|
||||
void recordEnd(JSC::JSGlobalObject *, Ref<Inspector::ScriptArguments> &&);
|
||||
void screenshot(JSC::JSGlobalObject *, Ref<Inspector::ScriptArguments> &&);
|
||||
|
||||
void startConsoleProfile();
|
||||
void stopConsoleProfile();
|
||||
void warnUnimplemented(const String &method);
|
||||
void internalAddMessage(MessageType, MessageLevel, JSC::JSGlobalObject *,
|
||||
Ref<Inspector::ScriptArguments> &&);
|
||||
|
||||
Inspector::InspectorConsoleAgent* m_consoleAgent;
|
||||
Inspector::InspectorDebuggerAgent* m_debuggerAgent { nullptr };
|
||||
Inspector::InspectorScriptProfilerAgent* m_scriptProfilerAgent { nullptr };
|
||||
Vector<String> m_profiles;
|
||||
bool m_profileRestoreBreakpointActiveValue { false };
|
||||
void startConsoleProfile();
|
||||
void stopConsoleProfile();
|
||||
|
||||
Inspector::InspectorConsoleAgent *m_consoleAgent;
|
||||
Inspector::InspectorDebuggerAgent *m_debuggerAgent{nullptr};
|
||||
Inspector::InspectorScriptProfilerAgent *m_scriptProfilerAgent{nullptr};
|
||||
Vector<String> m_profiles;
|
||||
bool m_profileRestoreBreakpointActiveValue{false};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
} // namespace Zig
|
||||
|
||||
@@ -104,7 +104,7 @@ extern "C" void JSCInitialize() {
|
||||
|
||||
extern "C" JSC__JSGlobalObject *Zig__GlobalObject__create(JSClassRef *globalObjectClass, int count,
|
||||
void *console_client) {
|
||||
auto heapSize = JSC::LargeHeap;
|
||||
auto heapSize = JSC::HeapType::Large;
|
||||
|
||||
JSC::VM &vm = JSC::VM::create(heapSize).leakRef();
|
||||
Bun::JSVMClientData::create(&vm);
|
||||
@@ -259,7 +259,7 @@ static Zig::ConsoleClient *m_console;
|
||||
|
||||
void GlobalObject::setConsole(void *console) {
|
||||
m_console = new Zig::ConsoleClient(console);
|
||||
this->setConsoleClient(makeWeakPtr(m_console));
|
||||
this->setConsoleClient(m_console);
|
||||
}
|
||||
|
||||
#pragma mark - Globals
|
||||
@@ -324,7 +324,8 @@ static JSC_DEFINE_HOST_FUNCTION(functionQueueMicrotask,
|
||||
}
|
||||
|
||||
// This is a JSC builtin function
|
||||
globalObject->queueMicrotask(JSC::createJSMicrotask(vm, job));
|
||||
globalObject->queueMicrotask(JSC::createJSMicrotask(vm, job, JSC::JSValue{}, JSC::JSValue{},
|
||||
JSC::JSValue{}, JSC::JSValue{}));
|
||||
|
||||
return JSC::JSValue::encode(JSC::jsUndefined());
|
||||
}
|
||||
@@ -350,7 +351,8 @@ static JSC_DEFINE_HOST_FUNCTION(functionSetTimeout,
|
||||
}
|
||||
|
||||
if (callFrame->argumentCount() == 1) {
|
||||
globalObject->queueMicrotask(JSC::createJSMicrotask(vm, job));
|
||||
globalObject->queueMicrotask(JSC::createJSMicrotask(vm, job, JSC::JSValue{}, JSC::JSValue{},
|
||||
JSC::JSValue{}, JSC::JSValue{}));
|
||||
return JSC::JSValue::encode(JSC::jsNumber(Bun__Timer__getNextID()));
|
||||
}
|
||||
|
||||
|
||||
@@ -27,13 +27,12 @@ class GlobalObject : public JSC::JSGlobalObject {
|
||||
Zig::Process *m_process;
|
||||
static constexpr bool needsDestruction = true;
|
||||
template <typename CellType, JSC::SubspaceAccess mode>
|
||||
static JSC::IsoSubspace *subspaceFor(JSC::VM &vm) {
|
||||
static GCClient::IsoSubspace *subspaceFor(VM &vm) {
|
||||
return vm.globalObjectSpace<mode>();
|
||||
}
|
||||
|
||||
static GlobalObject *create(JSC::VM &vm, JSC::Structure *structure) {
|
||||
auto *object =
|
||||
new (NotNull, JSC::allocateCell<GlobalObject>(vm.heap)) GlobalObject(vm, structure);
|
||||
auto *object = new (NotNull, JSC::allocateCell<GlobalObject>(vm)) GlobalObject(vm, structure);
|
||||
object->finishCreation(vm);
|
||||
return object;
|
||||
}
|
||||
@@ -80,7 +79,6 @@ class JSMicrotaskCallback : public RefCounted<JSMicrotaskCallback> {
|
||||
}
|
||||
|
||||
void call() {
|
||||
auto protectedThis{makeRef(*this)};
|
||||
JSC::VM &vm = m_globalObject->vm();
|
||||
auto task = &m_task.get();
|
||||
task->run(m_globalObject.get());
|
||||
|
||||
@@ -1842,15 +1842,19 @@ bool JSC__JSValue__isTerminationException(JSC__JSValue JSValue0, JSC__VM *arg1)
|
||||
void JSC__VM__shrinkFootprint(JSC__VM *arg0) { arg0->shrinkFootprintWhenIdle(); };
|
||||
void JSC__VM__whenIdle(JSC__VM *arg0, void (*ArgFn1)()) { arg0->whenIdle(ArgFn1); };
|
||||
|
||||
JSC__JSLock *JSC__VM__apiLock(JSC__VM *arg0) { return makeRefPtr((*arg0).apiLock()).leakRef(); }
|
||||
thread_local JSC::VM *g_commonVMOrNull;
|
||||
JSC__VM *JSC__VM__create(unsigned char HeapType0) {
|
||||
JSC::VM *vm =
|
||||
&JSC::VM::create(HeapType0 == JSC::SmallHeap ? JSC::SmallHeap : JSC::LargeHeap).leakRef();
|
||||
|
||||
auto &vm = JSC::VM::create(HeapType0 == 0 ? JSC::HeapType::Small : JSC::HeapType::Large, nullptr)
|
||||
.leakRef();
|
||||
#if ENABLE(WEBASSEMBLY)
|
||||
JSC::Wasm::enableFastMemory();
|
||||
#endif
|
||||
|
||||
return vm;
|
||||
g_commonVMOrNull = &vm;
|
||||
vm.heap.acquireAccess(); // At any time, we may do things that affect the GC.
|
||||
|
||||
return g_commonVMOrNull;
|
||||
}
|
||||
|
||||
void JSC__VM__holdAPILock(JSC__VM *arg0, void *ctx, void (*callback)(void *arg0)) {
|
||||
|
||||
@@ -1410,6 +1410,7 @@ pub const JSValue = enum(i64) {
|
||||
pub const JSType = enum(u8) {
|
||||
// The Cell value must come before any JS that is a JSCell.
|
||||
Cell,
|
||||
Structure,
|
||||
String,
|
||||
HeapBigInt,
|
||||
Symbol,
|
||||
@@ -1454,14 +1455,14 @@ pub const JSValue = enum(i64) {
|
||||
ScopedArguments,
|
||||
ClonedArguments,
|
||||
|
||||
// Start JSArray types.
|
||||
// Start JSArray s.
|
||||
Array,
|
||||
DerivedArray,
|
||||
// End JSArray types.
|
||||
// End JSArray s.
|
||||
|
||||
ArrayBuffer,
|
||||
|
||||
// Start JSArrayBufferView types. Keep in sync with the order of FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW.
|
||||
// Start JSArrayBufferView s. Keep in sync with the order of FOR_EACH_D_ARRAY__EXCLUDING_DATA_VIEW.
|
||||
Int8Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray,
|
||||
@@ -1474,25 +1475,26 @@ pub const JSValue = enum(i64) {
|
||||
BigInt64Array,
|
||||
BigUint64Array,
|
||||
DataView,
|
||||
// End JSArrayBufferView types.
|
||||
// End JSArrayBufferView s.
|
||||
|
||||
// JSScope <- JSWithScope
|
||||
// <- StrictEvalActivation
|
||||
// <- JSSymbolTableObject <- JSLexicalEnvironment <- JSModuleEnvironment
|
||||
// <- JSSegmentedVariableObject <- JSGlobalLexicalEnvironment
|
||||
// <- JSGlobalObject
|
||||
// Start JSScope types.
|
||||
// Start environment record types.
|
||||
// Start JSScope s.
|
||||
// Start environment record s.
|
||||
GlobalObject,
|
||||
GlobalLexicalEnvironment,
|
||||
LexicalEnvironment,
|
||||
ModuleEnvironment,
|
||||
StrictEvalActivation,
|
||||
// End environment record types.
|
||||
// End environment record s.
|
||||
WithScope,
|
||||
// End JSScope types.
|
||||
// End JSScope s.
|
||||
|
||||
ModuleNamespaceObject,
|
||||
ShadowRealm,
|
||||
RegExpObject,
|
||||
JSDate,
|
||||
ProxyObject,
|
||||
@@ -1508,10 +1510,10 @@ pub const JSValue = enum(i64) {
|
||||
JSWeakMap,
|
||||
JSWeakSet,
|
||||
WebAssemblyModule,
|
||||
// Start StringObject types.
|
||||
// Start StringObject s.
|
||||
StringObject,
|
||||
DerivedStringObject,
|
||||
// End StringObject types.
|
||||
// End StringObject s.
|
||||
|
||||
MaxJS = 0b11111111,
|
||||
_,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//-- AUTOGENERATED FILE -- 1645172173
|
||||
//-- AUTOGENERATED FILE -- 1645443002
|
||||
// clang-format off
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// clang-format: off
|
||||
//-- AUTOGENERATED FILE -- 1645172173
|
||||
//-- AUTOGENERATED FILE -- 1645443002
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
Reference in New Issue
Block a user