Make format consistent with WebKit

This commit is contained in:
Jarred Sumner
2022-02-22 15:51:41 -08:00
parent 4dd6472908
commit 27be64cf12
20 changed files with 3979 additions and 3465 deletions

View File

@@ -16,18 +16,22 @@
namespace Bun {
using namespace JSC;
JSVMClientData::JSVMClientData(VM &vm) : m_builtinNames(vm) {}
JSVMClientData::JSVMClientData(VM& vm)
: m_builtinNames(vm)
{
}
JSVMClientData::~JSVMClientData() {}
void JSVMClientData::create(VM *vm) {
JSVMClientData *clientData = new JSVMClientData(*vm);
vm->clientData = clientData; // ~VM deletes this pointer.
void JSVMClientData::create(VM* vm)
{
JSVMClientData* clientData = new JSVMClientData(*vm);
vm->clientData = clientData; // ~VM deletes this pointer.
// vm->heap.addMarkingConstraint(makeUnique<BunGCOutputConstraint>(*vm, *clientData));
// vm->heap.addMarkingConstraint(makeUnique<BunGCOutputConstraint>(*vm, *clientData));
// vm->m_typedArrayController = adoptRef(new WebCoreTypedArrayController(
// type == WorkerThreadType::DedicatedWorker || type == WorkerThreadType::Worklet));
// vm->m_typedArrayController = adoptRef(new WebCoreTypedArrayController(
// type == WorkerThreadType::DedicatedWorker || type == WorkerThreadType::Worklet));
}
} // namespace Bun

View File

@@ -10,32 +10,33 @@ namespace Bun {
using namespace JSC;
class JSVMClientData : public JSC::VM::ClientData {
WTF_MAKE_NONCOPYABLE(JSVMClientData);
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(JSVMClientData);
WTF_MAKE_FAST_ALLOCATED;
public:
explicit JSVMClientData(JSC::VM &);
public:
explicit JSVMClientData(JSC::VM&);
virtual ~JSVMClientData();
virtual ~JSVMClientData();
static void create(JSC::VM *);
static void create(JSC::VM*);
BunBuiltinNames &builtinNames() { return m_builtinNames; }
BunBuiltinNames& builtinNames() { return m_builtinNames; }
// Vector<JSC::IsoSubspace *> &outputConstraintSpaces() { return m_outputConstraintSpaces; }
// Vector<JSC::IsoSubspace *> &outputConstraintSpaces() { return m_outputConstraintSpaces; }
// template <typename Func> void forEachOutputConstraintSpace(const Func &func) {
// for (auto *space : m_outputConstraintSpaces) func(*space);
// }
// template <typename Func> void forEachOutputConstraintSpace(const Func &func) {
// for (auto *space : m_outputConstraintSpaces) func(*space);
// }
private:
BunBuiltinNames m_builtinNames;
private:
BunBuiltinNames m_builtinNames;
// Vector<JSC::IsoSubspace *> m_outputConstraintSpaces;
// Vector<JSC::IsoSubspace *> m_outputConstraintSpaces;
};
static JSVMClientData *clientData(JSC::VM &vm) {
return static_cast<Bun::JSVMClientData *>(vm.clientData);
static JSVMClientData* clientData(JSC::VM& vm)
{
return static_cast<Bun::JSVMClientData*>(vm.clientData);
}
} // namespace Bun

View File

@@ -15,46 +15,48 @@ using JSObject = JSC::JSObject;
using JSNonFinalObject = JSC::JSNonFinalObject;
namespace JSCastingHelpers = JSC::JSCastingHelpers;
static ReadableEvent getReadableEvent(const WTF::String &eventName);
static ReadableEvent getReadableEvent(const WTF::String &eventName) {
if (eventName == "close")
return ReadableEvent__Close;
else if (eventName == "data")
return ReadableEvent__Data;
else if (eventName == "end")
return ReadableEvent__End;
else if (eventName == "error")
return ReadableEvent__Error;
else if (eventName == "pause")
return ReadableEvent__Pause;
else if (eventName == "readable")
return ReadableEvent__Readable;
else if (eventName == "resume")
return ReadableEvent__Resume;
else if (eventName == "open")
return ReadableEvent__Open;
else
return ReadableEventUser;
static ReadableEvent getReadableEvent(const WTF::String& eventName);
static ReadableEvent getReadableEvent(const WTF::String& eventName)
{
if (eventName == "close")
return ReadableEvent__Close;
else if (eventName == "data")
return ReadableEvent__Data;
else if (eventName == "end")
return ReadableEvent__End;
else if (eventName == "error")
return ReadableEvent__Error;
else if (eventName == "pause")
return ReadableEvent__Pause;
else if (eventName == "readable")
return ReadableEvent__Readable;
else if (eventName == "resume")
return ReadableEvent__Resume;
else if (eventName == "open")
return ReadableEvent__Open;
else
return ReadableEventUser;
}
static WritableEvent getWritableEvent(const WTF::String &eventName);
static WritableEvent getWritableEvent(const WTF::String &eventName) {
if (eventName == "close")
return WritableEvent__Close;
else if (eventName == "drain")
return WritableEvent__Drain;
else if (eventName == "error")
return WritableEvent__Error;
else if (eventName == "finish")
return WritableEvent__Finish;
else if (eventName == "pipe")
return WritableEvent__Pipe;
else if (eventName == "unpipe")
return WritableEvent__Unpipe;
else if (eventName == "open")
return WritableEvent__Open;
else
return WritableEventUser;
static WritableEvent getWritableEvent(const WTF::String& eventName);
static WritableEvent getWritableEvent(const WTF::String& eventName)
{
if (eventName == "close")
return WritableEvent__Close;
else if (eventName == "drain")
return WritableEvent__Drain;
else if (eventName == "error")
return WritableEvent__Error;
else if (eventName == "finish")
return WritableEvent__Finish;
else if (eventName == "pipe")
return WritableEvent__Pipe;
else if (eventName == "unpipe")
return WritableEvent__Unpipe;
else if (eventName == "open")
return WritableEvent__Open;
else
return WritableEventUser;
}
// clang-format off
@@ -116,211 +118,235 @@ static JSC_DECLARE_HOST_FUNCTION(Writable__uncork);
static JSC_DECLARE_HOST_FUNCTION(Writable__write);
static JSC_DEFINE_HOST_FUNCTION(Readable__on,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
if (callFrame->argumentCount() < 2) { return JSC::JSValue::encode(JSC::jsUndefined()); }
JSC::VM &vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (callFrame->argumentCount() < 2) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto thisObject = JSC::jsDynamicCast<Bun::Readable *>(vm, callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
scope.release();
JSC::throwVMTypeError(globalObject, scope);
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto thisObject = JSC::jsDynamicCast<Bun::Readable*>(vm, callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
scope.release();
JSC::throwVMTypeError(globalObject, scope);
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto eventName = callFrame->argument(0).toStringOrNull(globalObject);
if (UNLIKELY(!eventName)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
ReadableEvent event = getReadableEvent(eventName->value(globalObject));
if (event == ReadableEventUser) {
// TODO:
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto listener = callFrame->argument(1);
JSC::JSObject* object = listener.getObject();
if (UNLIKELY(!object) || !listener.isCallable(vm)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
Bun__Readable__addEventListener(thisObject->state, globalObject, event,
JSC::JSValue::encode(listener), true);
auto eventName = callFrame->argument(0).toStringOrNull(globalObject);
if (UNLIKELY(!eventName)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
ReadableEvent event = getReadableEvent(eventName->value(globalObject));
if (event == ReadableEventUser) {
// TODO:
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto listener = callFrame->argument(1);
JSC::JSObject *object = listener.getObject();
if (UNLIKELY(!object) || !listener.isCallable(vm)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
Bun__Readable__addEventListener(thisObject->state, globalObject, event,
JSC::JSValue::encode(listener), true);
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
extern "C" Bun__Readable *JSC__JSValue__getReadableStreamState(JSC__JSValue value, JSC__VM *vm) {
auto *thisObject = JSC::jsDynamicCast<Bun::Readable *>(*vm, JSC::JSValue::decode(value));
if (UNLIKELY(!thisObject)) { return nullptr; }
return thisObject->state;
extern "C" Bun__Readable* JSC__JSValue__getReadableStreamState(JSC__JSValue value, JSC__VM* vm)
{
auto* thisObject = JSC::jsDynamicCast<Bun::Readable*>(*vm, JSC::JSValue::decode(value));
if (UNLIKELY(!thisObject)) {
return nullptr;
}
return thisObject->state;
}
extern "C" Bun__Writable *JSC__JSValue__getWritableStreamState(JSC__JSValue value, JSC__VM *vm) {
auto *thisObject = JSC::jsDynamicCast<Bun::Writable *>(*vm, JSC::JSValue::decode(value));
if (UNLIKELY(!thisObject)) { return nullptr; }
return thisObject->state;
extern "C" Bun__Writable* JSC__JSValue__getWritableStreamState(JSC__JSValue value, JSC__VM* vm)
{
auto* thisObject = JSC::jsDynamicCast<Bun::Writable*>(*vm, JSC::JSValue::decode(value));
if (UNLIKELY(!thisObject)) {
return nullptr;
}
return thisObject->state;
}
const JSC::ClassInfo Readable::s_info = {"Readable", &Base::s_info, nullptr, nullptr,
CREATE_METHOD_TABLE(Readable)};
const JSC::ClassInfo Readable::s_info = { "Readable", &Base::s_info, nullptr, nullptr,
CREATE_METHOD_TABLE(Readable) };
const JSC::ClassInfo Writable::s_info = {"Writable", &Base::s_info, nullptr, nullptr,
CREATE_METHOD_TABLE(Writable)};
const JSC::ClassInfo Writable::s_info = { "Writable", &Base::s_info, nullptr, nullptr,
CREATE_METHOD_TABLE(Writable) };
static JSC_DEFINE_HOST_FUNCTION(Readable__once,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
if (callFrame->argumentCount() < 2) { return JSC::JSValue::encode(JSC::jsUndefined()); }
JSC::VM &vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (callFrame->argumentCount() < 2) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto thisObject = JSC::jsDynamicCast<Bun::Readable *>(vm, callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
scope.release();
JSC::throwVMTypeError(globalObject, scope);
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto thisObject = JSC::jsDynamicCast<Bun::Readable*>(vm, callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
scope.release();
JSC::throwVMTypeError(globalObject, scope);
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto eventName = callFrame->argument(0).toStringOrNull(globalObject);
if (UNLIKELY(!eventName)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
ReadableEvent event = getReadableEvent(eventName->value(globalObject));
if (event == ReadableEventUser) {
// TODO:
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto listener = callFrame->argument(1);
JSC::JSObject* object = listener.getObject();
if (UNLIKELY(!object) || !listener.isCallable(vm)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
Bun__Readable__addEventListener(thisObject->state, globalObject, event,
JSC::JSValue::encode(listener), true);
auto eventName = callFrame->argument(0).toStringOrNull(globalObject);
if (UNLIKELY(!eventName)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
ReadableEvent event = getReadableEvent(eventName->value(globalObject));
if (event == ReadableEventUser) {
// TODO:
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto listener = callFrame->argument(1);
JSC::JSObject *object = listener.getObject();
if (UNLIKELY(!object) || !listener.isCallable(vm)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
Bun__Readable__addEventListener(thisObject->state, globalObject, event,
JSC::JSValue::encode(listener), true);
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
static JSC_DEFINE_HOST_FUNCTION(Writable__on,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
if (callFrame->argumentCount() < 2) { return JSC::JSValue::encode(JSC::jsUndefined()); }
JSC::VM &vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (callFrame->argumentCount() < 2) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto thisObject = JSC::jsDynamicCast<Bun::Writable *>(vm, callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
scope.release();
JSC::throwVMTypeError(globalObject, scope);
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto thisObject = JSC::jsDynamicCast<Bun::Writable*>(vm, callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
scope.release();
JSC::throwVMTypeError(globalObject, scope);
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto eventName = callFrame->argument(0).toStringOrNull(globalObject);
if (UNLIKELY(!eventName)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
WritableEvent event = getWritableEvent(eventName->value(globalObject));
if (event == WritableEventUser) {
// TODO:
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto listener = callFrame->argument(1);
JSC::JSObject* object = listener.getObject();
if (UNLIKELY(!object) || !listener.isCallable(vm)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
Bun__Writable__addEventListener(thisObject->state, globalObject, event,
JSC::JSValue::encode(listener), false);
auto eventName = callFrame->argument(0).toStringOrNull(globalObject);
if (UNLIKELY(!eventName)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
WritableEvent event = getWritableEvent(eventName->value(globalObject));
if (event == WritableEventUser) {
// TODO:
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto listener = callFrame->argument(1);
JSC::JSObject *object = listener.getObject();
if (UNLIKELY(!object) || !listener.isCallable(vm)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
Bun__Writable__addEventListener(thisObject->state, globalObject, event,
JSC::JSValue::encode(listener), false);
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
static JSC_DEFINE_HOST_FUNCTION(Writable__once,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
if (callFrame->argumentCount() < 2) { return JSC::JSValue::encode(JSC::jsUndefined()); }
JSC::VM &vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (callFrame->argumentCount() < 2) {
return JSC::JSValue::encode(JSC::jsUndefined());
}
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto thisObject = JSC::jsDynamicCast<Bun::Writable *>(vm, callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
scope.release();
JSC::throwVMTypeError(globalObject, scope);
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto thisObject = JSC::jsDynamicCast<Bun::Writable*>(vm, callFrame->thisValue());
if (UNLIKELY(!thisObject)) {
scope.release();
JSC::throwVMTypeError(globalObject, scope);
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto eventName = callFrame->argument(0).toStringOrNull(globalObject);
if (UNLIKELY(!eventName)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
WritableEvent event = getWritableEvent(eventName->value(globalObject));
if (event == WritableEventUser) {
// TODO:
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto listener = callFrame->argument(1);
JSC::JSObject* object = listener.getObject();
if (UNLIKELY(!object) || !listener.isCallable(vm)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
Bun__Writable__addEventListener(thisObject->state, globalObject, event,
JSC::JSValue::encode(listener), true);
auto eventName = callFrame->argument(0).toStringOrNull(globalObject);
if (UNLIKELY(!eventName)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
WritableEvent event = getWritableEvent(eventName->value(globalObject));
if (event == WritableEventUser) {
// TODO:
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
auto listener = callFrame->argument(1);
JSC::JSObject *object = listener.getObject();
if (UNLIKELY(!object) || !listener.isCallable(vm)) {
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
Bun__Writable__addEventListener(thisObject->state, globalObject, event,
JSC::JSValue::encode(listener), true);
scope.release();
return JSC::JSValue::encode(JSC::jsUndefined());
}
static JSC_DEFINE_HOST_FUNCTION(Readable__read,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__read);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__read);
}
static JSC_DEFINE_HOST_FUNCTION(Readable__pipe,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__pipe);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__pipe);
}
static JSC_DEFINE_HOST_FUNCTION(Readable__resume,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__resume);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__resume);
}
static JSC_DEFINE_HOST_FUNCTION(Readable__unpipe,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__unpipe);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__unpipe);
}
static JSC_DEFINE_HOST_FUNCTION(Readable__pause,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__pause);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__pause);
}
static JSC_DEFINE_HOST_FUNCTION(Readable__unshift,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__unshift);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Readable, Bun__Readable__unshift);
}
// static JSC_DECLARE_HOST_FUNCTION(Readable__isPaused);
@@ -330,156 +356,172 @@ static JSC_DEFINE_HOST_FUNCTION(Readable__unshift,
// Bun__Writable__setDefaultEncoding);
static JSC_DEFINE_HOST_FUNCTION(Writable__write,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__write);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__write);
}
static JSC_DEFINE_HOST_FUNCTION(Writable__end,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__end);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__end);
}
static JSC_DEFINE_HOST_FUNCTION(Writable__close,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__close);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__close);
}
static JSC_DEFINE_HOST_FUNCTION(Writable__destroy,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__destroy);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__destroy);
}
static JSC_DEFINE_HOST_FUNCTION(Writable__cork,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__cork);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__cork);
}
static JSC_DEFINE_HOST_FUNCTION(Writable__uncork,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__uncork);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun::Writable, Bun__Writable__uncork);
}
extern "C" JSC__JSValue Bun__Readable__create(Bun__Readable *state,
JSC__JSGlobalObject *globalObject) {
JSC::JSValue result = JSC::JSValue(Readable::create(
globalObject->vm(), state,
Readable::createStructure(globalObject->vm(), globalObject, globalObject->objectPrototype())));
extern "C" JSC__JSValue Bun__Readable__create(Bun__Readable* state,
JSC__JSGlobalObject* globalObject)
{
JSC::JSValue result = JSC::JSValue(Readable::create(
globalObject->vm(), state,
Readable::createStructure(globalObject->vm(), globalObject, globalObject->objectPrototype())));
return JSC::JSValue::encode(result);
return JSC::JSValue::encode(result);
}
extern "C" JSC__JSValue Bun__Writable__create(Bun__Writable *state,
JSC__JSGlobalObject *globalObject) {
JSC::JSValue result = JSC::JSValue(Writable::create(
globalObject->vm(), state,
Writable::createStructure(globalObject->vm(), globalObject, globalObject->objectPrototype())));
extern "C" JSC__JSValue Bun__Writable__create(Bun__Writable* state,
JSC__JSGlobalObject* globalObject)
{
JSC::JSValue result = JSC::JSValue(Writable::create(
globalObject->vm(), state,
Writable::createStructure(globalObject->vm(), globalObject, globalObject->objectPrototype())));
return JSC::JSValue::encode(result);
return JSC::JSValue::encode(result);
}
Readable::~Readable() {
if (this->state) { Bun__Readable__deinit(this->state); }
Readable::~Readable()
{
if (this->state) {
Bun__Readable__deinit(this->state);
}
}
Writable::~Writable() {
if (this->state) { Bun__Writable__deinit(this->state); }
Writable::~Writable()
{
if (this->state) {
Bun__Writable__deinit(this->state);
}
}
void Readable::finishCreation(JSC::VM &vm) {
Base::finishCreation(vm);
auto clientData = Bun::clientData(vm);
auto *globalObject = this->globalObject();
void Readable::finishCreation(JSC::VM& vm)
{
Base::finishCreation(vm);
auto clientData = Bun::clientData(vm);
auto* globalObject = this->globalObject();
putDirect(vm, clientData->builtinNames().onPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().onPublicName().string(), Readable__on),
0);
putDirect(vm, clientData->builtinNames().oncePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().oncePublicName().string(),
Readable__once),
0);
putDirect(vm, clientData->builtinNames().pausePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().pausePublicName().string(),
Readable__pause),
0);
putDirect(vm, clientData->builtinNames().pipePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().pipePublicName().string(),
Readable__pipe),
0);
putDirect(vm, clientData->builtinNames().readPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().readPublicName().string(),
Readable__read),
0);
putDirect(vm, clientData->builtinNames().resumePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().resumePublicName().string(),
Readable__resume),
0);
putDirect(vm, clientData->builtinNames().unpipePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().unpipePublicName().string(),
Readable__unpipe),
0);
putDirect(vm, clientData->builtinNames().unshiftPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().unshiftPublicName().string(),
Readable__unshift),
0);
putDirect(vm, clientData->builtinNames().onPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().onPublicName().string(), Readable__on),
0);
putDirect(vm, clientData->builtinNames().oncePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().oncePublicName().string(),
Readable__once),
0);
putDirect(vm, clientData->builtinNames().pausePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().pausePublicName().string(),
Readable__pause),
0);
putDirect(vm, clientData->builtinNames().pipePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().pipePublicName().string(),
Readable__pipe),
0);
putDirect(vm, clientData->builtinNames().readPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().readPublicName().string(),
Readable__read),
0);
putDirect(vm, clientData->builtinNames().resumePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().resumePublicName().string(),
Readable__resume),
0);
putDirect(vm, clientData->builtinNames().unpipePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().unpipePublicName().string(),
Readable__unpipe),
0);
putDirect(vm, clientData->builtinNames().unshiftPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().unshiftPublicName().string(),
Readable__unshift),
0);
}
void Writable::finishCreation(JSC::VM &vm) {
Base::finishCreation(vm);
auto clientData = Bun::clientData(vm);
void Writable::finishCreation(JSC::VM& vm)
{
Base::finishCreation(vm);
auto clientData = Bun::clientData(vm);
auto *globalObject = this->globalObject();
auto* globalObject = this->globalObject();
putDirect(vm, clientData->builtinNames().onPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().onPublicName().string(), Writable__on),
0);
putDirect(vm, clientData->builtinNames().onPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().onPublicName().string(), Writable__on),
0);
putDirect(vm, clientData->builtinNames().oncePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().oncePublicName().string(),
Writable__once),
0);
putDirect(vm, clientData->builtinNames().oncePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().oncePublicName().string(),
Writable__once),
0);
putDirect(vm, clientData->builtinNames().closePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().closePublicName().string(),
Writable__close),
0);
putDirect(vm, clientData->builtinNames().corkPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().corkPublicName().string(),
Writable__cork),
0);
putDirect(vm, clientData->builtinNames().destroyPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().destroyPublicName().string(),
Writable__destroy),
0);
putDirect(vm, clientData->builtinNames().endPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().endPublicName().string(), Writable__end),
0);
putDirect(vm, clientData->builtinNames().onPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().onPublicName().string(), Writable__on),
0);
putDirect(vm, clientData->builtinNames().oncePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().oncePublicName().string(),
Writable__once),
0);
putDirect(vm, clientData->builtinNames().uncorkPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().uncorkPublicName().string(),
Writable__uncork),
0);
putDirect(vm, clientData->builtinNames().writePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().writePublicName().string(),
Writable__write),
0);
putDirect(vm, clientData->builtinNames().closePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().closePublicName().string(),
Writable__close),
0);
putDirect(vm, clientData->builtinNames().corkPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().corkPublicName().string(),
Writable__cork),
0);
putDirect(vm, clientData->builtinNames().destroyPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().destroyPublicName().string(),
Writable__destroy),
0);
putDirect(vm, clientData->builtinNames().endPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().endPublicName().string(), Writable__end),
0);
putDirect(vm, clientData->builtinNames().onPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().onPublicName().string(), Writable__on),
0);
putDirect(vm, clientData->builtinNames().oncePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().oncePublicName().string(),
Writable__once),
0);
putDirect(vm, clientData->builtinNames().uncorkPublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().uncorkPublicName().string(),
Writable__uncork),
0);
putDirect(vm, clientData->builtinNames().writePublicName(),
JSFunction::create(vm, globalObject, 2,
clientData->builtinNames().writePublicName().string(),
Writable__write),
0);
}
} // namespace Bun

View File

@@ -9,73 +9,81 @@ namespace Bun {
using namespace JSC;
class Readable : public JSC::JSNonFinalObject {
using Base = JSC::JSNonFinalObject;
using Base = JSC::JSNonFinalObject;
public:
Bun__Readable *state;
Readable(JSC::VM &vm, Bun__Readable *readable, JSC::Structure *structure) : Base(vm, structure) {
state = readable;
}
public:
Bun__Readable* state;
Readable(JSC::VM& vm, Bun__Readable* readable, JSC::Structure* structure)
: Base(vm, structure)
{
state = readable;
}
~Readable();
~Readable();
DECLARE_INFO;
DECLARE_INFO;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static constexpr unsigned StructureFlags = Base::StructureFlags;
template <typename CellType, SubspaceAccess> static GCClient::IsoSubspace *subspaceFor(VM &vm) {
return &vm.plainObjectSpace();
}
template<typename CellType, SubspaceAccess> static GCClient::IsoSubspace* subspaceFor(VM& vm)
{
return &vm.plainObjectSpace();
}
static JSC::Structure *createStructure(JSC::VM &vm, JSC::JSGlobalObject *globalObject,
JSC::JSValue prototype) {
return JSC::Structure::create(vm, globalObject, prototype,
JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject,
JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype,
JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
static Readable *create(JSC::VM &vm, Bun__Readable *state, JSC::Structure *structure) {
Readable *accessor =
new (NotNull, JSC::allocateCell<Bun::Readable>(vm)) Readable(vm, state, structure);
accessor->finishCreation(vm);
return accessor;
}
static Readable* create(JSC::VM& vm, Bun__Readable* state, JSC::Structure* structure)
{
Readable* accessor = new (NotNull, JSC::allocateCell<Bun::Readable>(vm)) Readable(vm, state, structure);
accessor->finishCreation(vm);
return accessor;
}
void finishCreation(JSC::VM &vm);
void finishCreation(JSC::VM& vm);
};
class Writable : public JSC::JSNonFinalObject {
using Base = JSC::JSNonFinalObject;
using Base = JSC::JSNonFinalObject;
public:
Bun__Writable *state;
Writable(JSC::VM &vm, Bun__Writable *writable, JSC::Structure *structure) : Base(vm, structure) {
state = writable;
}
public:
Bun__Writable* state;
Writable(JSC::VM& vm, Bun__Writable* writable, JSC::Structure* structure)
: Base(vm, structure)
{
state = writable;
}
DECLARE_INFO;
DECLARE_INFO;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static constexpr unsigned StructureFlags = Base::StructureFlags;
template <typename CellType, SubspaceAccess> static GCClient::IsoSubspace *subspaceFor(VM &vm) {
return &vm.plainObjectSpace();
}
template<typename CellType, SubspaceAccess> static GCClient::IsoSubspace* subspaceFor(VM& vm)
{
return &vm.plainObjectSpace();
}
static JSC::Structure *createStructure(JSC::VM &vm, JSC::JSGlobalObject *globalObject,
JSC::JSValue prototype) {
return JSC::Structure::create(vm, globalObject, prototype,
JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject,
JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype,
JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
static Writable *create(JSC::VM &vm, Bun__Writable *state, JSC::Structure *structure) {
static Writable* create(JSC::VM& vm, Bun__Writable* state, JSC::Structure* structure)
{
Writable *accessor =
new (NotNull, JSC::allocateCell<Writable>(vm)) Writable(vm, state, structure);
accessor->finishCreation(vm);
return accessor;
}
~Writable();
Writable* accessor = new (NotNull, JSC::allocateCell<Writable>(vm)) Writable(vm, state, structure);
accessor->finishCreation(vm);
return accessor;
}
~Writable();
void finishCreation(JSC::VM &vm);
void finishCreation(JSC::VM& vm);
};
} // namespace Bun

View File

@@ -4,11 +4,12 @@
#pragma mark - Node.js Path
extern JSC__JSValue Bun__Path__create(JSC::JSGlobalObject *globalObject, bool isWindows) {
JSC::VM &vm = globalObject->vm();
extern JSC__JSValue Bun__Path__create(JSC::JSGlobalObject* globalObject, bool isWindows)
{
JSC::VM& vm = globalObject->vm();
return JSC::JSValue::encode(JSC::JSValue(Zig::Path::create(
vm, isWindows, Zig::Path::createStructure(vm, globalObject, globalObject->objectPrototype()))));
return JSC::JSValue::encode(JSC::JSValue(Zig::Path::create(
vm, isWindows, Zig::Path::createStructure(vm, globalObject, globalObject->objectPrototype()))));
}
namespace Zig {
@@ -55,128 +56,140 @@ namespace JSCastingHelpers = JSC::JSCastingHelpers;
static JSC_DECLARE_HOST_FUNCTION(Path_functionBasename);
static JSC_DEFINE_HOST_FUNCTION(Path_functionBasename,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__basename);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__basename);
}
static JSC_DECLARE_HOST_FUNCTION(Path_functionDirname);
static JSC_DEFINE_HOST_FUNCTION(Path_functionDirname,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__dirname);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__dirname);
}
static JSC_DECLARE_HOST_FUNCTION(Path_functionExtname);
static JSC_DEFINE_HOST_FUNCTION(Path_functionExtname,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__extname);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__extname);
}
static JSC_DECLARE_HOST_FUNCTION(Path_functionFormat);
static JSC_DEFINE_HOST_FUNCTION(Path_functionFormat,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__format);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__format);
}
static JSC_DECLARE_HOST_FUNCTION(Path_functionIsAbsolute);
static JSC_DEFINE_HOST_FUNCTION(Path_functionIsAbsolute,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__isAbsolute);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__isAbsolute);
}
static JSC_DECLARE_HOST_FUNCTION(Path_functionJoin);
static JSC_DEFINE_HOST_FUNCTION(Path_functionJoin,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__join);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__join);
}
static JSC_DECLARE_HOST_FUNCTION(Path_functionNormalize);
static JSC_DEFINE_HOST_FUNCTION(Path_functionNormalize,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__normalize);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__normalize);
}
static JSC_DECLARE_HOST_FUNCTION(Path_functionParse);
static JSC_DEFINE_HOST_FUNCTION(Path_functionParse,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__parse);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__parse);
}
static JSC_DECLARE_HOST_FUNCTION(Path_functionRelative);
static JSC_DEFINE_HOST_FUNCTION(Path_functionRelative,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__relative);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__relative);
}
static JSC_DECLARE_HOST_FUNCTION(Path_functionResolve);
static JSC_DEFINE_HOST_FUNCTION(Path_functionResolve,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__resolve);
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
DEFINE_CALLBACK_FUNCTION_BODY(Bun__Path__resolve);
}
static JSC_DECLARE_HOST_FUNCTION(Path_functionToNamespacedPath);
static JSC_DEFINE_HOST_FUNCTION(Path_functionToNamespacedPath,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
auto argCount = static_cast<uint16_t>(callFrame->argumentCount());
// TODO:
return JSC::JSValue::encode(callFrame->argument(0));
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto argCount = static_cast<uint16_t>(callFrame->argumentCount());
// TODO:
return JSC::JSValue::encode(callFrame->argument(0));
}
void Path::finishCreation(JSC::VM &vm) {
Base::finishCreation(vm);
auto clientData = Bun::clientData(vm);
void Path::finishCreation(JSC::VM& vm)
{
Base::finishCreation(vm);
auto clientData = Bun::clientData(vm);
JSC::JSGlobalObject *globalThis = globalObject();
this->putDirect(vm, clientData->builtinNames().basenamePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalThis), 0,
WTF::String("basename"), Path_functionBasename),
0);
this->putDirect(vm, clientData->builtinNames().dirnamePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalThis), 0,
WTF::String("dirname"), Path_functionDirname),
0);
this->putDirect(vm, clientData->builtinNames().extnamePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalThis), 0,
WTF::String("extname"), Path_functionExtname),
0);
this->putDirect(vm, clientData->builtinNames().formatPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalThis), 0,
WTF::String("format"), Path_functionFormat),
0);
this->putDirect(vm, clientData->builtinNames().isAbsolutePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalThis), 0,
WTF::String("isAbsolute"), Path_functionIsAbsolute),
0);
this->putDirect(vm, clientData->builtinNames().joinPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalThis), 0,
WTF::String("join"), Path_functionJoin),
0);
this->putDirect(vm, clientData->builtinNames().normalizePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalThis), 0,
WTF::String("normalize"), Path_functionNormalize),
0);
this->putDirect(vm, clientData->builtinNames().parsePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalThis), 0,
WTF::String("parse"), Path_functionParse),
0);
this->putDirect(vm, clientData->builtinNames().relativePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalThis), 0,
WTF::String("relative"), Path_functionRelative),
0);
this->putDirect(vm, clientData->builtinNames().resolvePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalThis), 0,
WTF::String("resolve"), Path_functionResolve),
0);
JSC::JSGlobalObject* globalThis = globalObject();
this->putDirect(vm, clientData->builtinNames().basenamePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0,
WTF::String("basename"), Path_functionBasename),
0);
this->putDirect(vm, clientData->builtinNames().dirnamePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0,
WTF::String("dirname"), Path_functionDirname),
0);
this->putDirect(vm, clientData->builtinNames().extnamePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0,
WTF::String("extname"), Path_functionExtname),
0);
this->putDirect(vm, clientData->builtinNames().formatPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0,
WTF::String("format"), Path_functionFormat),
0);
this->putDirect(vm, clientData->builtinNames().isAbsolutePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0,
WTF::String("isAbsolute"), Path_functionIsAbsolute),
0);
this->putDirect(vm, clientData->builtinNames().joinPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0,
WTF::String("join"), Path_functionJoin),
0);
this->putDirect(vm, clientData->builtinNames().normalizePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0,
WTF::String("normalize"), Path_functionNormalize),
0);
this->putDirect(vm, clientData->builtinNames().parsePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0,
WTF::String("parse"), Path_functionParse),
0);
this->putDirect(vm, clientData->builtinNames().relativePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0,
WTF::String("relative"), Path_functionRelative),
0);
this->putDirect(vm, clientData->builtinNames().resolvePublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0,
WTF::String("resolve"), Path_functionResolve),
0);
this->putDirect(vm, clientData->builtinNames().toNamespacedPathPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalThis), 0,
WTF::String("toNamespacedPath"),
Path_functionToNamespacedPath),
0);
this->putDirect(vm, clientData->builtinNames().toNamespacedPathPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalThis), 0,
WTF::String("toNamespacedPath"),
Path_functionToNamespacedPath),
0);
if (isWindows) {
this->putDirect(vm, clientData->builtinNames().sepPublicName(),
JSC::jsString(vm, WTF::String("\\"_s)), 0);
this->putDirect(vm, clientData->builtinNames().delimiterPublicName(),
JSC::jsString(vm, WTF::String(";"_s)), 0);
} else {
this->putDirect(vm, clientData->builtinNames().sepPublicName(),
JSC::jsString(vm, WTF::String("/"_s)), 0);
this->putDirect(vm, clientData->builtinNames().delimiterPublicName(),
JSC::jsString(vm, WTF::String(":"_s)), 0);
}
if (isWindows) {
this->putDirect(vm, clientData->builtinNames().sepPublicName(),
JSC::jsString(vm, WTF::String("\\"_s)), 0);
this->putDirect(vm, clientData->builtinNames().delimiterPublicName(),
JSC::jsString(vm, WTF::String(";"_s)), 0);
} else {
this->putDirect(vm, clientData->builtinNames().sepPublicName(),
JSC::jsString(vm, WTF::String("/"_s)), 0);
this->putDirect(vm, clientData->builtinNames().delimiterPublicName(),
JSC::jsString(vm, WTF::String(":"_s)), 0);
}
}
const JSC::ClassInfo Path::s_info = {"Path", &Base::s_info, nullptr, nullptr,
CREATE_METHOD_TABLE(Path)};
const JSC::ClassInfo Path::s_info = { "Path", &Base::s_info, nullptr, nullptr,
CREATE_METHOD_TABLE(Path) };
} // namespace Zig

View File

@@ -9,36 +9,41 @@ namespace Zig {
using namespace JSC;
class Path : public JSC::JSNonFinalObject {
using Base = JSC::JSNonFinalObject;
using Base = JSC::JSNonFinalObject;
public:
Path(JSC::VM &vm, JSC::Structure *structure, bool isWindows_) : Base(vm, structure) {
isWindows = isWindows_;
}
public:
Path(JSC::VM& vm, JSC::Structure* structure, bool isWindows_)
: Base(vm, structure)
{
isWindows = isWindows_;
}
DECLARE_INFO;
DECLARE_INFO;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static constexpr unsigned StructureFlags = Base::StructureFlags;
template <typename CellType, SubspaceAccess> static GCClient::IsoSubspace *subspaceFor(VM &vm) {
return &vm.plainObjectSpace();
}
template<typename CellType, SubspaceAccess> static GCClient::IsoSubspace* subspaceFor(VM& vm)
{
return &vm.plainObjectSpace();
}
static JSC::Structure *createStructure(JSC::VM &vm, JSC::JSGlobalObject *globalObject,
JSC::JSValue prototype) {
return JSC::Structure::create(vm, globalObject, prototype,
JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject,
JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype,
JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
static Path *create(JSC::VM &vm, bool isWindows, JSC::Structure *structure) {
Path *accessor = new (NotNull, JSC::allocateCell<Path>(vm)) Path(vm, structure, isWindows);
static Path* create(JSC::VM& vm, bool isWindows, JSC::Structure* structure)
{
Path* accessor = new (NotNull, JSC::allocateCell<Path>(vm)) Path(vm, structure, isWindows);
accessor->finishCreation(vm);
return accessor;
}
bool isWindows = false;
accessor->finishCreation(vm);
return accessor;
}
bool isWindows = false;
void finishCreation(JSC::VM &vm);
void finishCreation(JSC::VM& vm);
};
} // namespace Zig

View File

@@ -32,310 +32,327 @@ static JSC_DECLARE_HOST_FUNCTION(Process_functionCwd);
static JSC_DECLARE_HOST_FUNCTION(Process_functionNextTick);
static JSC_DEFINE_HOST_FUNCTION(Process_functionNextTick,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
JSC::VM &vm = globalObject->vm();
auto argCount = callFrame->argumentCount();
if (argCount == 0) {
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
JSC::throwTypeError(globalObject, scope, "nextTick requires 1 argument (a function)"_s);
return JSC::JSValue::encode(JSC::JSValue{});
}
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
JSC::VM& vm = globalObject->vm();
auto argCount = callFrame->argumentCount();
if (argCount == 0) {
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
JSC::throwTypeError(globalObject, scope, "nextTick requires 1 argument (a function)"_s);
return JSC::JSValue::encode(JSC::JSValue {});
}
JSC::JSValue job = callFrame->uncheckedArgument(0);
JSC::JSValue job = callFrame->uncheckedArgument(0);
if (!job.isObject() || !job.getObject()->isCallable(vm)) {
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
JSC::throwTypeError(globalObject, scope, "nextTick expects a function"_s);
return JSC::JSValue::encode(JSC::JSValue{});
}
if (!job.isObject() || !job.getObject()->isCallable(vm)) {
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
JSC::throwTypeError(globalObject, scope, "nextTick expects a function"_s);
return JSC::JSValue::encode(JSC::JSValue {});
}
switch (argCount) {
switch (argCount) {
case 1: {
// This is a JSC builtin function
globalObject->queueMicrotask(JSC::createJSMicrotask(vm, job, JSC::JSValue{}, JSC::JSValue{},
JSC::JSValue{}, JSC::JSValue{}));
break;
// This is a JSC builtin function
globalObject->queueMicrotask(JSC::createJSMicrotask(vm, job, JSC::JSValue {}, JSC::JSValue {},
JSC::JSValue {}, JSC::JSValue {}));
break;
}
case 2:
case 3:
case 4:
case 5: {
JSC::JSValue argument0 = callFrame->uncheckedArgument(1);
JSC::JSValue argument1 = argCount > 2 ? callFrame->uncheckedArgument(2) : JSC::JSValue{};
JSC::JSValue argument2 = argCount > 3 ? callFrame->uncheckedArgument(3) : JSC::JSValue{};
JSC::JSValue argument3 = argCount > 4 ? callFrame->uncheckedArgument(4) : JSC::JSValue{};
globalObject->queueMicrotask(
JSC::createJSMicrotask(vm, job, argument0, argument1, argument2, argument3));
break;
JSC::JSValue argument0 = callFrame->uncheckedArgument(1);
JSC::JSValue argument1 = argCount > 2 ? callFrame->uncheckedArgument(2) : JSC::JSValue {};
JSC::JSValue argument2 = argCount > 3 ? callFrame->uncheckedArgument(3) : JSC::JSValue {};
JSC::JSValue argument3 = argCount > 4 ? callFrame->uncheckedArgument(4) : JSC::JSValue {};
globalObject->queueMicrotask(
JSC::createJSMicrotask(vm, job, argument0, argument1, argument2, argument3));
break;
}
default: {
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
JSC::throwTypeError(globalObject, scope,
"nextTick doesn't support more than 4 arguments currently"_s);
return JSC::JSValue::encode(JSC::JSValue{});
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
JSC::throwTypeError(globalObject, scope,
"nextTick doesn't support more than 4 arguments currently"_s);
return JSC::JSValue::encode(JSC::JSValue {});
break;
break;
}
// JSC::MarkedArgumentBuffer args;
// for (unsigned i = 1; i < callFrame->argumentCount(); i++) {
// args.append(callFrame->uncheckedArgument(i));
// }
// JSC::MarkedArgumentBuffer args;
// for (unsigned i = 1; i < callFrame->argumentCount(); i++) {
// args.append(callFrame->uncheckedArgument(i));
// }
// JSC::ArgList argsList(args);
// JSC::gcProtect(job);
// JSC::JSFunction *callback = JSC::JSNativeStdFunction::create(
// vm, globalObject, 0, String(),
// [job, &argsList](JSC::JSGlobalObject *globalObject, JSC::CallFrame *callFrame) {
// JSC::VM &vm = globalObject->vm();
// auto callData = getCallData(vm, job);
// JSC::ArgList argsList(args);
// JSC::gcProtect(job);
// JSC::JSFunction *callback = JSC::JSNativeStdFunction::create(
// vm, globalObject, 0, String(),
// [job, &argsList](JSC::JSGlobalObject *globalObject, JSC::CallFrame *callFrame) {
// JSC::VM &vm = globalObject->vm();
// auto callData = getCallData(vm, job);
// return JSC::JSValue::encode(JSC::call(globalObject, job, callData, job, argsList));
// });
// return JSC::JSValue::encode(JSC::call(globalObject, job, callData, job, argsList));
// });
// globalObject->queueMicrotask(JSC::createJSMicrotask(vm, JSC::JSValue(callback)));
}
// globalObject->queueMicrotask(JSC::createJSMicrotask(vm, JSC::JSValue(callback)));
}
return JSC::JSValue::encode(JSC::jsUndefined());
return JSC::JSValue::encode(JSC::jsUndefined());
}
static JSC_DECLARE_HOST_FUNCTION(Process_functionChdir);
static JSC_DEFINE_HOST_FUNCTION(Process_functionChdir,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
ZigString str = ZigString{nullptr, 0};
if (callFrame->argumentCount() > 0) {
str = Zig::toZigString(callFrame->uncheckedArgument(0).toWTFString(globalObject));
}
ZigString str = ZigString { nullptr, 0 };
if (callFrame->argumentCount() > 0) {
str = Zig::toZigString(callFrame->uncheckedArgument(0).toWTFString(globalObject));
}
JSC::JSValue result = JSC::JSValue::decode(Bun__Process__setCwd(globalObject, &str));
JSC::JSObject *obj = result.getObject();
if (UNLIKELY(obj != nullptr && obj->isErrorInstance())) {
scope.throwException(globalObject, obj);
return JSValue::encode(JSC::jsUndefined());
}
JSC::JSValue result = JSC::JSValue::decode(Bun__Process__setCwd(globalObject, &str));
JSC::JSObject* obj = result.getObject();
if (UNLIKELY(obj != nullptr && obj->isErrorInstance())) {
scope.throwException(globalObject, obj);
return JSValue::encode(JSC::jsUndefined());
}
return JSC::JSValue::encode(result);
return JSC::JSValue::encode(result);
}
void Process::finishCreation(JSC::VM &vm) {
Base::finishCreation(vm);
auto clientData = Bun::clientData(vm);
void Process::finishCreation(JSC::VM& vm)
{
Base::finishCreation(vm);
auto clientData = Bun::clientData(vm);
putDirectCustomAccessor(vm, clientData->builtinNames().pidPublicName(),
JSC::CustomGetterSetter::create(vm, Process_getPID, nullptr),
static_cast<unsigned>(JSC::PropertyAttribute::CustomValue));
putDirectCustomAccessor(vm, clientData->builtinNames().pidPublicName(),
JSC::CustomGetterSetter::create(vm, Process_getPID, nullptr),
static_cast<unsigned>(JSC::PropertyAttribute::CustomValue));
putDirectCustomAccessor(vm, clientData->builtinNames().ppidPublicName(),
JSC::CustomGetterSetter::create(vm, Process_getPPID, nullptr),
static_cast<unsigned>(JSC::PropertyAttribute::CustomValue));
putDirectCustomAccessor(vm, clientData->builtinNames().ppidPublicName(),
JSC::CustomGetterSetter::create(vm, Process_getPPID, nullptr),
static_cast<unsigned>(JSC::PropertyAttribute::CustomValue));
putDirectCustomAccessor(vm, clientData->builtinNames().titlePublicName(),
JSC::CustomGetterSetter::create(vm, Process_getTitle, Process_setTitle),
static_cast<unsigned>(JSC::PropertyAttribute::CustomValue));
putDirectCustomAccessor(vm, clientData->builtinNames().titlePublicName(),
JSC::CustomGetterSetter::create(vm, Process_getTitle, Process_setTitle),
static_cast<unsigned>(JSC::PropertyAttribute::CustomValue));
putDirectCustomAccessor(vm, clientData->builtinNames().argvPublicName(),
JSC::CustomGetterSetter::create(vm, Process_getArgv, Process_setArgv),
static_cast<unsigned>(JSC::PropertyAttribute::CustomValue));
putDirectCustomAccessor(vm, clientData->builtinNames().argvPublicName(),
JSC::CustomGetterSetter::create(vm, Process_getArgv, Process_setArgv),
static_cast<unsigned>(JSC::PropertyAttribute::CustomValue));
this->putDirect(vm, clientData->builtinNames().nextTickPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalObject()), 0,
WTF::String("nextTick"), Process_functionNextTick),
0);
this->putDirect(vm, clientData->builtinNames().nextTickPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 0,
WTF::String("nextTick"), Process_functionNextTick),
0);
this->putDirect(vm, clientData->builtinNames().cwdPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalObject()), 0,
WTF::String("cwd"), Process_functionCwd),
0);
this->putDirect(vm, clientData->builtinNames().cwdPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 0,
WTF::String("cwd"), Process_functionCwd),
0);
this->putDirect(vm, clientData->builtinNames().chdirPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject *>(globalObject()), 0,
WTF::String("chdir"), Process_functionChdir),
0);
this->putDirect(vm, clientData->builtinNames().chdirPublicName(),
JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 0,
WTF::String("chdir"), Process_functionChdir),
0);
putDirectCustomAccessor(
vm, clientData->builtinNames().versionsPublicName(),
JSC::CustomGetterSetter::create(vm, Process_getVersionsLazy, Process_setVersionsLazy), 0);
// this should be transpiled out, but just incase
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "browser"),
JSC::JSValue(false));
putDirectCustomAccessor(
vm, clientData->builtinNames().versionsPublicName(),
JSC::CustomGetterSetter::create(vm, Process_getVersionsLazy, Process_setVersionsLazy), 0);
// this should be transpiled out, but just incase
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "browser"),
JSC::JSValue(false));
this->putDirect(this->vm(), clientData->builtinNames().versionPublicName(),
JSC::jsString(this->vm(), WTF::String(Bun__version)));
this->putDirect(this->vm(), clientData->builtinNames().versionPublicName(),
JSC::jsString(this->vm(), WTF::String(Bun__version)));
// this gives some way of identifying at runtime whether the SSR is happening in node or not.
// this should probably be renamed to what the name of the bundler is, instead of "notNodeJS"
// but it must be something that won't evaluate to truthy in Node.js
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "isBun"), JSC::JSValue(true));
// this gives some way of identifying at runtime whether the SSR is happening in node or not.
// this should probably be renamed to what the name of the bundler is, instead of "notNodeJS"
// but it must be something that won't evaluate to truthy in Node.js
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "isBun"), JSC::JSValue(true));
#if defined(__APPLE__)
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "platform"),
JSC::jsString(this->vm(), WTF::String("darwin")));
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "platform"),
JSC::jsString(this->vm(), WTF::String("darwin")));
#else
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "platform"),
JSC::jsString(this->vm(), WTF::String("linux")));
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "platform"),
JSC::jsString(this->vm(), WTF::String("linux")));
#endif
#if defined(__x86_64__)
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"),
JSC::jsString(this->vm(), WTF::String("x64")));
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"),
JSC::jsString(this->vm(), WTF::String("x64")));
#elif defined(__i386__)
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"),
JSC::jsString(this->vm(), WTF::String("x86")));
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"),
JSC::jsString(this->vm(), WTF::String("x86")));
#elif defined(__arm__)
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"),
JSC::jsString(this->vm(), WTF::String("arm")));
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"),
JSC::jsString(this->vm(), WTF::String("arm")));
#elif defined(__aarch64__)
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"),
JSC::jsString(this->vm(), WTF::String("arm64")));
this->putDirect(this->vm(), JSC::Identifier::fromString(this->vm(), "arch"),
JSC::jsString(this->vm(), WTF::String("arm64")));
#endif
}
const JSC::ClassInfo Process::s_info = {"Process", &Base::s_info, nullptr, nullptr,
CREATE_METHOD_TABLE(Process)};
const JSC::ClassInfo Process::s_info = { "Process", &Base::s_info, nullptr, nullptr,
CREATE_METHOD_TABLE(Process) };
JSC_DEFINE_CUSTOM_GETTER(Process_getTitle, (JSC::JSGlobalObject * globalObject,
JSC::EncodedJSValue thisValue, JSC::PropertyName)) {
ZigString str;
Bun__Process__getTitle(globalObject, &str);
return JSValue::encode(Zig::toJSStringValue(str, globalObject));
JSC_DEFINE_CUSTOM_GETTER(Process_getTitle, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
{
ZigString str;
Bun__Process__getTitle(globalObject, &str);
return JSValue::encode(Zig::toJSStringValue(str, globalObject));
}
JSC_DEFINE_CUSTOM_SETTER(Process_setTitle,
(JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue,
JSC::EncodedJSValue value, JSC::PropertyName)) {
JSC::VM &vm = globalObject->vm();
(JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue,
JSC::EncodedJSValue value, JSC::PropertyName))
{
JSC::VM& vm = globalObject->vm();
JSC::JSObject *thisObject = JSC::jsDynamicCast<JSC::JSObject *>(vm, JSValue::decode(thisValue));
JSC::JSString *jsString = JSC::jsDynamicCast<JSC::JSString *>(vm, JSValue::decode(value));
if (!thisObject || !jsString) { return false; }
JSC::JSObject* thisObject = JSC::jsDynamicCast<JSC::JSObject*>(vm, JSValue::decode(thisValue));
JSC::JSString* jsString = JSC::jsDynamicCast<JSC::JSString*>(vm, JSValue::decode(value));
if (!thisObject || !jsString) {
return false;
}
ZigString str = Zig::toZigString(jsString, globalObject);
Bun__Process__setTitle(globalObject, &str);
ZigString str = Zig::toZigString(jsString, globalObject);
Bun__Process__setTitle(globalObject, &str);
return true;
return true;
}
JSC_DEFINE_CUSTOM_GETTER(Process_getArgv, (JSC::JSGlobalObject * globalObject,
JSC::EncodedJSValue thisValue, JSC::PropertyName)) {
JSC::VM &vm = globalObject->vm();
JSC_DEFINE_CUSTOM_GETTER(Process_getArgv, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
{
JSC::VM& vm = globalObject->vm();
Zig::Process *thisObject = JSC::jsDynamicCast<Zig::Process *>(vm, JSValue::decode(thisValue));
if (!thisObject) { return JSValue::encode(JSC::jsUndefined()); }
auto clientData = Bun::clientData(vm);
Zig::Process* thisObject = JSC::jsDynamicCast<Zig::Process*>(vm, JSValue::decode(thisValue));
if (!thisObject) {
return JSValue::encode(JSC::jsUndefined());
}
auto clientData = Bun::clientData(vm);
if (JSC::JSValue argv = thisObject->getIfPropertyExists(
globalObject, clientData->builtinNames().argvPrivateName())) {
return JSValue::encode(argv);
}
if (JSC::JSValue argv = thisObject->getIfPropertyExists(
globalObject, clientData->builtinNames().argvPrivateName())) {
return JSValue::encode(argv);
}
JSC::EncodedJSValue argv_ = Bun__Process__getArgv(globalObject);
thisObject->putDirect(vm, clientData->builtinNames().argvPrivateName(),
JSC::JSValue::decode(argv_));
JSC::EncodedJSValue argv_ = Bun__Process__getArgv(globalObject);
thisObject->putDirect(vm, clientData->builtinNames().argvPrivateName(),
JSC::JSValue::decode(argv_));
return argv_;
return argv_;
}
JSC_DEFINE_CUSTOM_SETTER(Process_setArgv,
(JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue,
JSC::EncodedJSValue value, JSC::PropertyName)) {
JSC::VM &vm = globalObject->vm();
(JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue,
JSC::EncodedJSValue value, JSC::PropertyName))
{
JSC::VM& vm = globalObject->vm();
JSC::JSObject *thisObject = JSC::jsDynamicCast<JSC::JSObject *>(vm, JSValue::decode(thisValue));
if (!thisObject) { return false; }
JSC::JSObject* thisObject = JSC::jsDynamicCast<JSC::JSObject*>(vm, JSValue::decode(thisValue));
if (!thisObject) {
return false;
}
auto clientData = Bun::clientData(vm);
auto clientData = Bun::clientData(vm);
return thisObject->putDirect(vm, clientData->builtinNames().argvPrivateName(),
JSC::JSValue::decode(value));
return thisObject->putDirect(vm, clientData->builtinNames().argvPrivateName(),
JSC::JSValue::decode(value));
}
JSC_DEFINE_CUSTOM_GETTER(Process_getPID, (JSC::JSGlobalObject * globalObject,
JSC::EncodedJSValue thisValue, JSC::PropertyName)) {
return JSC::JSValue::encode(JSC::JSValue(getpid()));
JSC_DEFINE_CUSTOM_GETTER(Process_getPID, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
{
return JSC::JSValue::encode(JSC::JSValue(getpid()));
}
JSC_DEFINE_CUSTOM_GETTER(Process_getPPID, (JSC::JSGlobalObject * globalObject,
JSC::EncodedJSValue thisValue, JSC::PropertyName)) {
return JSC::JSValue::encode(JSC::JSValue(getppid()));
JSC_DEFINE_CUSTOM_GETTER(Process_getPPID, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
{
return JSC::JSValue::encode(JSC::JSValue(getppid()));
}
JSC_DEFINE_CUSTOM_GETTER(Process_getVersionsLazy,
(JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue,
JSC::PropertyName)) {
JSC::VM &vm = globalObject->vm();
auto clientData = Bun::clientData(vm);
(JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue,
JSC::PropertyName))
{
JSC::VM& vm = globalObject->vm();
auto clientData = Bun::clientData(vm);
Zig::Process *thisObject = JSC::jsDynamicCast<Zig::Process *>(vm, JSValue::decode(thisValue));
if (!thisObject) { return JSValue::encode(JSC::jsUndefined()); }
Zig::Process* thisObject = JSC::jsDynamicCast<Zig::Process*>(vm, JSValue::decode(thisValue));
if (!thisObject) {
return JSValue::encode(JSC::jsUndefined());
}
if (JSC::JSValue argv = thisObject->getIfPropertyExists(
globalObject, clientData->builtinNames().versionsPrivateName())) {
return JSValue::encode(argv);
}
if (JSC::JSValue argv = thisObject->getIfPropertyExists(
globalObject, clientData->builtinNames().versionsPrivateName())) {
return JSValue::encode(argv);
}
JSC::JSObject *object =
JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 9);
JSC::JSObject* object = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 9);
object->putDirect(vm, JSC::Identifier::fromString(vm, "node"),
JSC::JSValue(JSC::jsString(vm, WTF::String("17.0.0"))));
object->putDirect(
vm, JSC::Identifier::fromString(vm, "bun"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__version + 1 /* prefix with v */))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "webkit"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_webkit))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "mimalloc"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_mimalloc))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "libarchive"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_libarchive))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "picohttpparser"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_picohttpparser))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "boringssl"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_boringssl))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "zlib"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_zlib))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "zig"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_zig))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "node"),
JSC::JSValue(JSC::jsString(vm, WTF::String("17.0.0"))));
object->putDirect(
vm, JSC::Identifier::fromString(vm, "bun"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__version + 1 /* prefix with v */))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "webkit"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_webkit))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "mimalloc"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_mimalloc))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "libarchive"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_libarchive))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "picohttpparser"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_picohttpparser))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "boringssl"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_boringssl))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "zlib"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_zlib))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "zig"),
JSC::JSValue(JSC::jsString(vm, WTF::String(Bun__versions_zig))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "modules"),
JSC::JSValue(JSC::jsString(vm, WTF::String("67"))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "modules"),
JSC::JSValue(JSC::jsString(vm, WTF::String("67"))));
thisObject->putDirect(vm, clientData->builtinNames().versionsPrivateName(), object);
return JSC::JSValue::encode(object);
thisObject->putDirect(vm, clientData->builtinNames().versionsPrivateName(), object);
return JSC::JSValue::encode(object);
}
JSC_DEFINE_CUSTOM_SETTER(Process_setVersionsLazy,
(JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue,
JSC::EncodedJSValue value, JSC::PropertyName)) {
(JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue,
JSC::EncodedJSValue value, JSC::PropertyName))
{
JSC::VM &vm = globalObject->vm();
auto clientData = Bun::clientData(vm);
JSC::VM& vm = globalObject->vm();
auto clientData = Bun::clientData(vm);
Zig::Process *thisObject = JSC::jsDynamicCast<Zig::Process *>(vm, JSValue::decode(thisValue));
if (!thisObject) { return JSValue::encode(JSC::jsUndefined()); }
Zig::Process* thisObject = JSC::jsDynamicCast<Zig::Process*>(vm, JSValue::decode(thisValue));
if (!thisObject) {
return JSValue::encode(JSC::jsUndefined());
}
thisObject->putDirect(vm, clientData->builtinNames().versionsPrivateName(),
JSC::JSValue::decode(value));
thisObject->putDirect(vm, clientData->builtinNames().versionsPrivateName(),
JSC::JSValue::decode(value));
return true;
return true;
}
static JSC_DEFINE_HOST_FUNCTION(Process_functionCwd,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) {
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
JSC::JSValue result = JSC::JSValue::decode(Bun__Process__getCwd(globalObject));
JSC::JSObject *obj = result.getObject();
if (UNLIKELY(obj != nullptr && obj->isErrorInstance())) {
scope.throwException(globalObject, obj);
return JSValue::encode(JSC::jsUndefined());
}
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
JSC::JSValue result = JSC::JSValue::decode(Bun__Process__getCwd(globalObject));
JSC::JSObject* obj = result.getObject();
if (UNLIKELY(obj != nullptr && obj->isErrorInstance())) {
scope.throwException(globalObject, obj);
return JSValue::encode(JSC::jsUndefined());
}
return JSC::JSValue::encode(result);
return JSC::JSValue::encode(result);
}
} // namespace Zig

View File

@@ -9,32 +9,38 @@ namespace Zig {
using namespace JSC;
class Process : public JSC::JSNonFinalObject {
using Base = JSC::JSNonFinalObject;
using Base = JSC::JSNonFinalObject;
public:
Process(JSC::VM &vm, JSC::Structure *structure) : Base(vm, structure) {}
public:
Process(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure)
{
}
DECLARE_INFO;
DECLARE_INFO;
static constexpr unsigned StructureFlags = Base::StructureFlags;
static constexpr unsigned StructureFlags = Base::StructureFlags;
template <typename CellType, SubspaceAccess> static GCClient::IsoSubspace *subspaceFor(VM &vm) {
return &vm.plainObjectSpace();
}
template<typename CellType, SubspaceAccess> static GCClient::IsoSubspace* subspaceFor(VM& vm)
{
return &vm.plainObjectSpace();
}
static JSC::Structure *createStructure(JSC::VM &vm, JSC::JSGlobalObject *globalObject,
JSC::JSValue prototype) {
return JSC::Structure::create(vm, globalObject, prototype,
JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject,
JSC::JSValue prototype)
{
return JSC::Structure::create(vm, globalObject, prototype,
JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
}
static Process *create(JSC::VM &vm, JSC::Structure *structure) {
Process *accessor = new (NotNull, JSC::allocateCell<Process>(vm)) Process(vm, structure);
accessor->finishCreation(vm);
return accessor;
}
static Process* create(JSC::VM& vm, JSC::Structure* structure)
{
Process* accessor = new (NotNull, JSC::allocateCell<Process>(vm)) Process(vm, structure);
accessor->finishCreation(vm);
return accessor;
}
void finishCreation(JSC::VM &vm);
void finishCreation(JSC::VM& vm);
};
} // namespace Zig

View File

@@ -15,109 +15,132 @@ using String = WTF::String;
namespace JSC {
ALWAYS_INLINE GCDeferralContext::GCDeferralContext(VM &vm) : m_vm(vm) {}
ALWAYS_INLINE GCDeferralContext::GCDeferralContext(VM& vm)
: m_vm(vm)
{
}
ALWAYS_INLINE GCDeferralContext::~GCDeferralContext() {
if constexpr (validateDFGDoesGC) m_vm.verifyCanGC();
ALWAYS_INLINE GCDeferralContext::~GCDeferralContext()
{
if constexpr (validateDFGDoesGC)
m_vm.verifyCanGC();
if (UNLIKELY(m_shouldGC)) m_vm.heap.collectIfNecessaryOrDefer();
if (UNLIKELY(m_shouldGC))
m_vm.heap.collectIfNecessaryOrDefer();
}
} // namespace JSC
extern "C" {
JSC__JSValue Inspector__ScriptArguments__argumentAt(Inspector__ScriptArguments *arg0, size_t i) {
return JSC::JSValue::encode(arg0->argumentAt(i));
JSC__JSValue Inspector__ScriptArguments__argumentAt(Inspector__ScriptArguments* arg0, size_t i)
{
return JSC::JSValue::encode(arg0->argumentAt(i));
}
size_t Inspector__ScriptArguments__argumentCount(Inspector__ScriptArguments *arg0) {
return arg0->argumentCount();
size_t Inspector__ScriptArguments__argumentCount(Inspector__ScriptArguments* arg0)
{
return arg0->argumentCount();
}
bWTF__String
Inspector__ScriptArguments__getFirstArgumentAsString(Inspector__ScriptArguments *arg0) {
auto scope = DECLARE_CATCH_SCOPE(arg0->globalObject()->vm());
JSC::JSValue val0 = arg0->argumentAt(0);
auto type = val0.asCell()->type();
Wrap<WTF::String, bWTF__String> wrap;
wrap.cpp = new (wrap.alignedBuffer()) WTF::String(val0.getString(arg0->globalObject()));
scope.clearException();
return wrap.result;
Inspector__ScriptArguments__getFirstArgumentAsString(Inspector__ScriptArguments* arg0)
{
auto scope = DECLARE_CATCH_SCOPE(arg0->globalObject()->vm());
JSC::JSValue val0 = arg0->argumentAt(0);
auto type = val0.asCell()->type();
Wrap<WTF::String, bWTF__String> wrap;
wrap.cpp = new (wrap.alignedBuffer()) WTF::String(val0.getString(arg0->globalObject()));
scope.clearException();
return wrap.result;
}
bool Inspector__ScriptArguments__isEqual(Inspector__ScriptArguments *arg0,
Inspector__ScriptArguments *arg1) {
return arg0->isEqual(*arg1);
bool Inspector__ScriptArguments__isEqual(Inspector__ScriptArguments* arg0,
Inspector__ScriptArguments* arg1)
{
return arg0->isEqual(*arg1);
}
void Inspector__ScriptArguments__release(Inspector__ScriptArguments *arg0) {
auto count = arg0->argumentCount();
for (int i = 0; i < count; i++) { JSC::gcUnprotect(arg0->argumentAt(i)); }
arg0->deref();
void Inspector__ScriptArguments__release(Inspector__ScriptArguments* arg0)
{
auto count = arg0->argumentCount();
for (int i = 0; i < count; i++) {
JSC::gcUnprotect(arg0->argumentAt(i));
}
arg0->deref();
}
}
void Zig::ConsoleClient::messageWithTypeAndLevel(MessageType type, MessageLevel level,
JSC::JSGlobalObject *globalObject,
Ref<ScriptArguments> &&arguments) {
JSC::VM &vm = globalObject->vm();
JSC::GCDeferralContext deferralContext(vm);
JSC::DisallowGC disallowGC;
auto args = arguments.ptr();
JSC__JSValue jsArgs[255];
JSC::JSGlobalObject* globalObject,
Ref<ScriptArguments>&& arguments)
{
JSC::VM& vm = globalObject->vm();
JSC::GCDeferralContext deferralContext(vm);
JSC::DisallowGC disallowGC;
auto args = arguments.ptr();
JSC__JSValue jsArgs[255];
auto count = std::min(args->argumentCount(), (size_t)255);
for (size_t i = 0; i < count; i++) {
auto val = args->argumentAt(i);
// JSC::gcProtect(val);
jsArgs[i] = JSC::JSValue::encode(val);
}
auto count = std::min(args->argumentCount(), (size_t)255);
for (size_t i = 0; i < count; i++) {
auto val = args->argumentAt(i);
// JSC::gcProtect(val);
jsArgs[i] = JSC::JSValue::encode(val);
}
auto scope = DECLARE_THROW_SCOPE(vm);
Zig__ConsoleClient__messageWithTypeAndLevel(this->m_client, static_cast<uint32_t>(type),
static_cast<uint32_t>(level), globalObject, jsArgs,
count);
scope.clearException();
auto scope = DECLARE_THROW_SCOPE(vm);
Zig__ConsoleClient__messageWithTypeAndLevel(this->m_client, static_cast<uint32_t>(type),
static_cast<uint32_t>(level), globalObject, jsArgs,
count);
scope.clearException();
// for (size_t i = 0; i < count; i++) {
// JSC::gcUnprotect(JSC::JSValue::decode(jsArgs[i]));
// }
// for (size_t i = 0; i < count; i++) {
// JSC::gcUnprotect(JSC::JSValue::decode(jsArgs[i]));
// }
}
void Zig::ConsoleClient::count(JSGlobalObject *globalObject, const String &label) {
auto ptr = label.characters8();
Zig__ConsoleClient__count(this->m_client, globalObject, ptr, label.length());
void Zig::ConsoleClient::count(JSGlobalObject* globalObject, const String& label)
{
auto ptr = label.characters8();
Zig__ConsoleClient__count(this->m_client, globalObject, ptr, label.length());
}
void Zig::ConsoleClient::countReset(JSGlobalObject *globalObject, const String &label) {
auto ptr = label.characters8();
Zig__ConsoleClient__countReset(this->m_client, globalObject, ptr, label.length());
void Zig::ConsoleClient::countReset(JSGlobalObject* globalObject, const String& label)
{
auto ptr = label.characters8();
Zig__ConsoleClient__countReset(this->m_client, globalObject, ptr, label.length());
}
void Zig::ConsoleClient::profile(JSC::JSGlobalObject *globalObject, const String &label) {
auto ptr = label.characters8();
Zig__ConsoleClient__profile(this->m_client, globalObject, ptr, label.length());
void Zig::ConsoleClient::profile(JSC::JSGlobalObject* globalObject, const String& label)
{
auto ptr = label.characters8();
Zig__ConsoleClient__profile(this->m_client, globalObject, ptr, label.length());
}
void Zig::ConsoleClient::profileEnd(JSC::JSGlobalObject *globalObject, const String &label) {
auto ptr = label.characters8();
Zig__ConsoleClient__profileEnd(this->m_client, globalObject, ptr, label.length());
void Zig::ConsoleClient::profileEnd(JSC::JSGlobalObject* globalObject, const String& label)
{
auto ptr = label.characters8();
Zig__ConsoleClient__profileEnd(this->m_client, globalObject, ptr, label.length());
}
void Zig::ConsoleClient::takeHeapSnapshot(JSC::JSGlobalObject *globalObject, const String &label) {
auto ptr = label.characters8();
Zig__ConsoleClient__takeHeapSnapshot(this->m_client, globalObject, ptr, label.length());
void Zig::ConsoleClient::takeHeapSnapshot(JSC::JSGlobalObject* globalObject, const String& label)
{
auto ptr = label.characters8();
Zig__ConsoleClient__takeHeapSnapshot(this->m_client, globalObject, ptr, label.length());
}
void Zig::ConsoleClient::time(JSGlobalObject *globalObject, const String &label) {
auto ptr = label.characters8();
Zig__ConsoleClient__time(this->m_client, globalObject, ptr, label.length());
void Zig::ConsoleClient::time(JSGlobalObject* globalObject, const String& label)
{
auto ptr = label.characters8();
Zig__ConsoleClient__time(this->m_client, globalObject, ptr, label.length());
}
void Zig::ConsoleClient::timeLog(JSGlobalObject *globalObject, const String &label,
Ref<ScriptArguments> &&arguments) {
auto ptr = label.characters8();
Zig__ConsoleClient__timeLog(this->m_client, globalObject, ptr, label.length(), arguments.ptr());
void Zig::ConsoleClient::timeLog(JSGlobalObject* globalObject, const String& label,
Ref<ScriptArguments>&& arguments)
{
auto ptr = label.characters8();
Zig__ConsoleClient__timeLog(this->m_client, globalObject, ptr, label.length(), arguments.ptr());
}
void Zig::ConsoleClient::timeEnd(JSGlobalObject *globalObject, const String &label) {
auto ptr = label.characters8();
Zig__ConsoleClient__timeEnd(this->m_client, globalObject, ptr, label.length());
void Zig::ConsoleClient::timeEnd(JSGlobalObject* globalObject, const String& label)
{
auto ptr = label.characters8();
Zig__ConsoleClient__timeEnd(this->m_client, globalObject, ptr, label.length());
}
void Zig::ConsoleClient::timeStamp(JSGlobalObject *globalObject, Ref<ScriptArguments> &&args) {
Zig__ConsoleClient__timeStamp(this->m_client, globalObject, args.ptr());
void Zig::ConsoleClient::timeStamp(JSGlobalObject* globalObject, Ref<ScriptArguments>&& args)
{
Zig__ConsoleClient__timeStamp(this->m_client, globalObject, args.ptr());
}
void Zig::ConsoleClient::record(JSGlobalObject *, Ref<ScriptArguments> &&) {}
void Zig::ConsoleClient::recordEnd(JSGlobalObject *, Ref<ScriptArguments> &&) {}
void Zig::ConsoleClient::screenshot(JSGlobalObject *, Ref<ScriptArguments> &&) {}
void Zig::ConsoleClient::warnUnimplemented(const String &method) {}
void Zig::ConsoleClient::record(JSGlobalObject*, Ref<ScriptArguments>&&) {}
void Zig::ConsoleClient::recordEnd(JSGlobalObject*, Ref<ScriptArguments>&&) {}
void Zig::ConsoleClient::screenshot(JSGlobalObject*, Ref<ScriptArguments>&&) {}
void Zig::ConsoleClient::warnUnimplemented(const String& method) {}

View File

@@ -16,50 +16,55 @@ using InspectorScriptProfilerAgent = Inspector::InspectorScriptProfilerAgent;
using namespace JSC;
class ConsoleClient final : public JSC::ConsoleClient {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_FAST_ALLOCATED;
public:
~ConsoleClient() final {}
ConsoleClient(void *client) : JSC::ConsoleClient() { m_client = client; }
public:
~ConsoleClient() final {}
ConsoleClient(void* client)
: JSC::ConsoleClient()
{
m_client = client;
}
static bool logToSystemConsole();
static void setLogToSystemConsole(bool);
static bool logToSystemConsole();
static void setLogToSystemConsole(bool);
void setDebuggerAgent(InspectorDebuggerAgent *agent) { m_debuggerAgent = agent; }
void setPersistentScriptProfilerAgent(InspectorScriptProfilerAgent *agent) {
m_scriptProfilerAgent = agent;
}
void setDebuggerAgent(InspectorDebuggerAgent* agent) { m_debuggerAgent = agent; }
void setPersistentScriptProfilerAgent(InspectorScriptProfilerAgent* agent)
{
m_scriptProfilerAgent = agent;
}
void *m_client;
void* m_client;
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> &&);
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 warnUnimplemented(const String &method);
void internalAddMessage(MessageType, MessageLevel, JSC::JSGlobalObject *,
Ref<Inspector::ScriptArguments> &&);
void warnUnimplemented(const String& method);
void internalAddMessage(MessageType, MessageLevel, JSC::JSGlobalObject*,
Ref<Inspector::ScriptArguments>&&);
void startConsoleProfile();
void stopConsoleProfile();
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};
Inspector::InspectorConsoleAgent* m_consoleAgent;
Inspector::InspectorDebuggerAgent* m_debuggerAgent { nullptr };
Inspector::InspectorScriptProfilerAgent* m_scriptProfilerAgent { nullptr };
Vector<String> m_profiles;
bool m_profileRestoreBreakpointActiveValue { false };
};
} // namespace Zig

File diff suppressed because it is too large Load Diff

View File

@@ -19,77 +19,87 @@ class Identifier;
namespace Zig {
class GlobalObject : public JSC::JSGlobalObject {
using Base = JSC::JSGlobalObject;
using Base = JSC::JSGlobalObject;
public:
DECLARE_EXPORT_INFO;
static const JSC::GlobalObjectMethodTable s_globalObjectMethodTable;
Zig::Process *m_process;
static constexpr bool needsDestruction = true;
template <typename CellType, JSC::SubspaceAccess mode>
static GCClient::IsoSubspace *subspaceFor(VM &vm) {
return vm.globalObjectSpace<mode>();
}
public:
DECLARE_EXPORT_INFO;
static const JSC::GlobalObjectMethodTable s_globalObjectMethodTable;
Zig::Process* m_process;
static constexpr bool needsDestruction = true;
template<typename CellType, JSC::SubspaceAccess mode>
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)) GlobalObject(vm, structure);
object->finishCreation(vm);
return object;
}
static GlobalObject* create(JSC::VM& vm, JSC::Structure* structure)
{
auto* object = new (NotNull, JSC::allocateCell<GlobalObject>(vm)) GlobalObject(vm, structure);
object->finishCreation(vm);
return object;
}
static JSC::Structure *createStructure(JSC::VM &vm, JSC::JSValue prototype) {
auto *result = JSC::Structure::create(
vm, nullptr, prototype, JSC::TypeInfo(JSC::GlobalObjectType, Base::StructureFlags), info());
result->setTransitionWatchpointIsLikelyToBeFired(true);
return result;
}
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSValue prototype)
{
auto* result = JSC::Structure::create(
vm, nullptr, prototype, JSC::TypeInfo(JSC::GlobalObjectType, Base::StructureFlags), info());
result->setTransitionWatchpointIsLikelyToBeFired(true);
return result;
}
static void reportUncaughtExceptionAtEventLoop(JSGlobalObject *, JSC::Exception *);
static void reportUncaughtExceptionAtEventLoop(JSGlobalObject*, JSC::Exception*);
static void queueMicrotaskToEventLoop(JSC::JSGlobalObject &global, Ref<JSC::Microtask> &&task);
static JSC::JSInternalPromise *moduleLoaderImportModule(JSGlobalObject *, JSC::JSModuleLoader *,
JSC::JSString *moduleNameValue,
JSC::JSValue parameters,
const JSC::SourceOrigin &);
static JSC::Identifier moduleLoaderResolve(JSGlobalObject *, JSC::JSModuleLoader *,
JSC::JSValue keyValue, JSC::JSValue referrerValue,
JSC::JSValue);
static JSC::JSInternalPromise *moduleLoaderFetch(JSGlobalObject *, JSC::JSModuleLoader *,
JSC::JSValue, JSC::JSValue, JSC::JSValue);
static JSC::JSObject *moduleLoaderCreateImportMetaProperties(JSGlobalObject *,
JSC::JSModuleLoader *, JSC::JSValue,
JSC::JSModuleRecord *, JSC::JSValue);
static JSC::JSValue moduleLoaderEvaluate(JSGlobalObject *, JSC::JSModuleLoader *, JSC::JSValue,
JSC::JSValue, JSC::JSValue, JSC::JSValue, JSC::JSValue);
static void promiseRejectionTracker(JSGlobalObject *, JSC::JSPromise *,
JSC::JSPromiseRejectionOperation);
void setConsole(void *console);
void installAPIGlobals(JSClassRef *globals, int count);
static void queueMicrotaskToEventLoop(JSC::JSGlobalObject& global, Ref<JSC::Microtask>&& task);
static JSC::JSInternalPromise* moduleLoaderImportModule(JSGlobalObject*, JSC::JSModuleLoader*,
JSC::JSString* moduleNameValue,
JSC::JSValue parameters,
const JSC::SourceOrigin&);
static JSC::Identifier moduleLoaderResolve(JSGlobalObject*, JSC::JSModuleLoader*,
JSC::JSValue keyValue, JSC::JSValue referrerValue,
JSC::JSValue);
static JSC::JSInternalPromise* moduleLoaderFetch(JSGlobalObject*, JSC::JSModuleLoader*,
JSC::JSValue, JSC::JSValue, JSC::JSValue);
static JSC::JSObject* moduleLoaderCreateImportMetaProperties(JSGlobalObject*,
JSC::JSModuleLoader*, JSC::JSValue,
JSC::JSModuleRecord*, JSC::JSValue);
static JSC::JSValue moduleLoaderEvaluate(JSGlobalObject*, JSC::JSModuleLoader*, JSC::JSValue,
JSC::JSValue, JSC::JSValue, JSC::JSValue, JSC::JSValue);
static void promiseRejectionTracker(JSGlobalObject*, JSC::JSPromise*,
JSC::JSPromiseRejectionOperation);
void setConsole(void* console);
void installAPIGlobals(JSClassRef* globals, int count);
private:
GlobalObject(JSC::VM &vm, JSC::Structure *structure)
: JSC::JSGlobalObject(vm, structure, &s_globalObjectMethodTable) {}
private:
GlobalObject(JSC::VM& vm, JSC::Structure* structure)
: JSC::JSGlobalObject(vm, structure, &s_globalObjectMethodTable)
{
}
};
class JSMicrotaskCallback : public RefCounted<JSMicrotaskCallback> {
public:
static Ref<JSMicrotaskCallback> create(JSC::JSGlobalObject &globalObject,
Ref<JSC::Microtask> &&task) {
return adoptRef(*new JSMicrotaskCallback(globalObject, WTFMove(task).leakRef()));
}
public:
static Ref<JSMicrotaskCallback> create(JSC::JSGlobalObject& globalObject,
Ref<JSC::Microtask>&& task)
{
return adoptRef(*new JSMicrotaskCallback(globalObject, WTFMove(task).leakRef()));
}
void call() {
JSC::VM &vm = m_globalObject->vm();
auto task = &m_task.get();
task->run(m_globalObject.get());
}
void call()
{
JSC::VM& vm = m_globalObject->vm();
auto task = &m_task.get();
task->run(m_globalObject.get());
}
private:
JSMicrotaskCallback(JSC::JSGlobalObject &globalObject, Ref<JSC::Microtask> &&task)
: m_globalObject{globalObject.vm(), &globalObject}, m_task{WTFMove(task)} {}
private:
JSMicrotaskCallback(JSC::JSGlobalObject& globalObject, Ref<JSC::Microtask>&& task)
: m_globalObject { globalObject.vm(), &globalObject }
, m_task { WTFMove(task) }
{
}
JSC::Strong<JSC::JSGlobalObject> m_globalObject;
Ref<JSC::Microtask> m_task;
JSC::Strong<JSC::JSGlobalObject> m_globalObject;
Ref<JSC::Microtask> m_task;
};
} // namespace Zig

View File

@@ -23,147 +23,168 @@ using SourceOrigin = JSC::SourceOrigin;
using String = WTF::String;
using SourceProviderSourceType = JSC::SourceProviderSourceType;
Ref<SourceProvider> SourceProvider::create(ResolvedSource resolvedSource) {
void *allocator = resolvedSource.allocator;
Ref<SourceProvider> SourceProvider::create(ResolvedSource resolvedSource)
{
void* allocator = resolvedSource.allocator;
WTF::StringImpl *stringImpl = nullptr;
if (allocator) {
Ref<WTF::ExternalStringImpl> stringImpl_ = WTF::ExternalStringImpl::create(
resolvedSource.source_code.ptr, resolvedSource.source_code.len,
[allocator](WTF::ExternalStringImpl *str, void *ptr, unsigned int len) {
ZigString__free((const unsigned char *)ptr, len, allocator);
});
return adoptRef(*new SourceProvider(
resolvedSource, reinterpret_cast<WTF::StringImpl *>(stringImpl_.ptr()),
JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(toString(resolvedSource.source_url))),
toStringNotConst(resolvedSource.source_url), TextPosition(),
JSC::SourceProviderSourceType::Module));
WTF::StringImpl* stringImpl = nullptr;
if (allocator) {
Ref<WTF::ExternalStringImpl> stringImpl_ = WTF::ExternalStringImpl::create(
resolvedSource.source_code.ptr, resolvedSource.source_code.len,
[allocator](WTF::ExternalStringImpl* str, void* ptr, unsigned int len) {
ZigString__free((const unsigned char*)ptr, len, allocator);
});
return adoptRef(*new SourceProvider(
resolvedSource, reinterpret_cast<WTF::StringImpl*>(stringImpl_.ptr()),
JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(toString(resolvedSource.source_url))),
toStringNotConst(resolvedSource.source_url), TextPosition(),
JSC::SourceProviderSourceType::Module));
} else {
Ref<WTF::ExternalStringImpl> stringImpl_ = WTF::ExternalStringImpl::createStatic(
resolvedSource.source_code.ptr, resolvedSource.source_code.len);
return adoptRef(*new SourceProvider(
resolvedSource, reinterpret_cast<WTF::StringImpl *>(stringImpl_.ptr()),
JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(toString(resolvedSource.source_url))),
toStringNotConst(resolvedSource.source_url), TextPosition(),
JSC::SourceProviderSourceType::Module));
}
} else {
Ref<WTF::ExternalStringImpl> stringImpl_ = WTF::ExternalStringImpl::createStatic(
resolvedSource.source_code.ptr, resolvedSource.source_code.len);
return adoptRef(*new SourceProvider(
resolvedSource, reinterpret_cast<WTF::StringImpl*>(stringImpl_.ptr()),
JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(toString(resolvedSource.source_url))),
toStringNotConst(resolvedSource.source_url), TextPosition(),
JSC::SourceProviderSourceType::Module));
}
}
unsigned SourceProvider::getHash() {
if (m_hash) { return m_hash; }
unsigned SourceProvider::getHash()
{
if (m_hash) {
return m_hash;
}
m_hash = WTF::StringHash::hash(m_source.get());
return m_hash;
m_hash = WTF::StringHash::hash(m_source.get());
return m_hash;
}
void SourceProvider::freeSourceCode() {
if (did_free_source_code) { return; }
did_free_source_code = true;
if (m_resolvedSource.allocator != 0) { // // WTF::ExternalStringImpl::destroy(m_source.ptr());
this->m_source = WTF::StringImpl::empty()->isolatedCopy();
this->m_hash = 0;
m_resolvedSource.allocator = 0;
}
// if (m_resolvedSource.allocator != 0) {
// ZigString__free(m_resolvedSource.source_code.ptr, m_resolvedSource.source_code.len,
// m_resolvedSource.allocator);
// }
void SourceProvider::freeSourceCode()
{
if (did_free_source_code) {
return;
}
did_free_source_code = true;
if (m_resolvedSource.allocator != 0) { // // WTF::ExternalStringImpl::destroy(m_source.ptr());
this->m_source = WTF::StringImpl::empty()->isolatedCopy();
this->m_hash = 0;
m_resolvedSource.allocator = 0;
}
// if (m_resolvedSource.allocator != 0) {
// ZigString__free(m_resolvedSource.source_code.ptr, m_resolvedSource.source_code.len,
// m_resolvedSource.allocator);
// }
}
void SourceProvider::updateCache(const UnlinkedFunctionExecutable *executable, const SourceCode &,
CodeSpecializationKind kind,
const UnlinkedFunctionCodeBlock *codeBlock) {
if (!m_resolvedSource.bytecodecache_fd || !m_cachedBytecode) return;
void SourceProvider::updateCache(const UnlinkedFunctionExecutable* executable, const SourceCode&,
CodeSpecializationKind kind,
const UnlinkedFunctionCodeBlock* codeBlock)
{
if (!m_resolvedSource.bytecodecache_fd || !m_cachedBytecode)
return;
JSC::BytecodeCacheError error;
RefPtr<JSC::CachedBytecode> cachedBytecode =
JSC::encodeFunctionCodeBlock(executable->vm(), codeBlock, error);
if (cachedBytecode && !error.isValid())
m_cachedBytecode->addFunctionUpdate(executable, kind, *cachedBytecode);
JSC::BytecodeCacheError error;
RefPtr<JSC::CachedBytecode> cachedBytecode = JSC::encodeFunctionCodeBlock(executable->vm(), codeBlock, error);
if (cachedBytecode && !error.isValid())
m_cachedBytecode->addFunctionUpdate(executable, kind, *cachedBytecode);
}
void SourceProvider::cacheBytecode(const BytecodeCacheGenerator &generator) {
if (!m_resolvedSource.bytecodecache_fd) return;
void SourceProvider::cacheBytecode(const BytecodeCacheGenerator& generator)
{
if (!m_resolvedSource.bytecodecache_fd)
return;
if (!m_cachedBytecode) m_cachedBytecode = JSC::CachedBytecode::create();
auto update = generator();
if (update) m_cachedBytecode->addGlobalUpdate(*update);
if (!m_cachedBytecode)
m_cachedBytecode = JSC::CachedBytecode::create();
auto update = generator();
if (update)
m_cachedBytecode->addGlobalUpdate(*update);
}
void SourceProvider::commitCachedBytecode() {
if (!m_resolvedSource.bytecodecache_fd || !m_cachedBytecode || !m_cachedBytecode->hasUpdates())
return;
void SourceProvider::commitCachedBytecode()
{
if (!m_resolvedSource.bytecodecache_fd || !m_cachedBytecode || !m_cachedBytecode->hasUpdates())
return;
auto clearBytecode = WTF::makeScopeExit([&] { m_cachedBytecode = nullptr; });
const auto fd = m_resolvedSource.bytecodecache_fd;
auto clearBytecode = WTF::makeScopeExit([&] { m_cachedBytecode = nullptr; });
const auto fd = m_resolvedSource.bytecodecache_fd;
auto fileSize = FileSystem::fileSize(fd);
if (!fileSize) return;
auto fileSize = FileSystem::fileSize(fd);
if (!fileSize)
return;
size_t cacheFileSize;
if (!WTF::convertSafely(*fileSize, cacheFileSize) || cacheFileSize != m_cachedBytecode->size()) {
// The bytecode cache has already been updated
return;
}
size_t cacheFileSize;
if (!WTF::convertSafely(*fileSize, cacheFileSize) || cacheFileSize != m_cachedBytecode->size()) {
// The bytecode cache has already been updated
return;
}
if (!FileSystem::truncateFile(fd, m_cachedBytecode->sizeForUpdate())) return;
if (!FileSystem::truncateFile(fd, m_cachedBytecode->sizeForUpdate()))
return;
m_cachedBytecode->commitUpdates([&](off_t offset, const void *data, size_t size) {
long long result = FileSystem::seekFile(fd, offset, FileSystem::FileSeekOrigin::Beginning);
ASSERT_UNUSED(result, result != -1);
size_t bytesWritten = static_cast<size_t>(FileSystem::writeToFile(fd, data, size));
ASSERT_UNUSED(bytesWritten, bytesWritten == size);
});
m_cachedBytecode->commitUpdates([&](off_t offset, const void* data, size_t size) {
long long result = FileSystem::seekFile(fd, offset, FileSystem::FileSeekOrigin::Beginning);
ASSERT_UNUSED(result, result != -1);
size_t bytesWritten = static_cast<size_t>(FileSystem::writeToFile(fd, data, size));
ASSERT_UNUSED(bytesWritten, bytesWritten == size);
});
}
bool SourceProvider::isBytecodeCacheEnabled() const {
return m_resolvedSource.bytecodecache_fd > 0;
bool SourceProvider::isBytecodeCacheEnabled() const
{
return m_resolvedSource.bytecodecache_fd > 0;
}
void SourceProvider::readOrGenerateByteCodeCache(JSC::VM &vm, const JSC::SourceCode &sourceCode) {
auto status = this->readCache(vm, sourceCode);
switch (status) {
void SourceProvider::readOrGenerateByteCodeCache(JSC::VM& vm, const JSC::SourceCode& sourceCode)
{
auto status = this->readCache(vm, sourceCode);
switch (status) {
case -1: {
m_resolvedSource.bytecodecache_fd = 0;
break;
m_resolvedSource.bytecodecache_fd = 0;
break;
}
case 0: {
JSC::BytecodeCacheError err;
m_cachedBytecode =
JSC::generateModuleBytecode(vm, sourceCode, m_resolvedSource.bytecodecache_fd, err);
JSC::BytecodeCacheError err;
m_cachedBytecode = JSC::generateModuleBytecode(vm, sourceCode, m_resolvedSource.bytecodecache_fd, err);
if (err.isValid()) {
m_resolvedSource.bytecodecache_fd = 0;
m_cachedBytecode = JSC::CachedBytecode::create();
}
if (err.isValid()) {
m_resolvedSource.bytecodecache_fd = 0;
m_cachedBytecode = JSC::CachedBytecode::create();
}
}
// TODO: read the bytecode into a JSC::SourceCode object here
case 1: {
}
}
}
}
int SourceProvider::readCache(JSC::VM &vm, const JSC::SourceCode &sourceCode) {
if (m_resolvedSource.bytecodecache_fd == 0) return -1;
if (!FileSystem::isHandleValid(m_resolvedSource.bytecodecache_fd)) return -1;
const auto fd = m_resolvedSource.bytecodecache_fd;
int SourceProvider::readCache(JSC::VM& vm, const JSC::SourceCode& sourceCode)
{
if (m_resolvedSource.bytecodecache_fd == 0)
return -1;
if (!FileSystem::isHandleValid(m_resolvedSource.bytecodecache_fd))
return -1;
const auto fd = m_resolvedSource.bytecodecache_fd;
bool success;
FileSystem::MappedFileData mappedFile(fd, FileSystem::MappedFileMode::Shared, success);
if (!success) return -1;
bool success;
FileSystem::MappedFileData mappedFile(fd, FileSystem::MappedFileMode::Shared, success);
if (!success)
return -1;
const uint8_t *fileData = reinterpret_cast<const uint8_t *>(mappedFile.data());
unsigned fileTotalSize = mappedFile.size();
if (fileTotalSize == 0) return 0;
const uint8_t* fileData = reinterpret_cast<const uint8_t*>(mappedFile.data());
unsigned fileTotalSize = mappedFile.size();
if (fileTotalSize == 0)
return 0;
Ref<JSC::CachedBytecode> cachedBytecode = JSC::CachedBytecode::create(WTFMove(mappedFile));
// auto key = JSC::sourceCodeKeyForSerializedModule(vm, sourceCode);
// if (isCachedBytecodeStillValid(vm, cachedBytecode.copyRef(), key,
// JSC::SourceCodeType::ModuleType)) {
m_cachedBytecode = WTFMove(cachedBytecode);
return 1;
// } else {
// FileSystem::truncateFile(fd, 0);
// return 0;
// }
Ref<JSC::CachedBytecode> cachedBytecode = JSC::CachedBytecode::create(WTFMove(mappedFile));
// auto key = JSC::sourceCodeKeyForSerializedModule(vm, sourceCode);
// if (isCachedBytecodeStillValid(vm, cachedBytecode.copyRef(), key,
// JSC::SourceCodeType::ModuleType)) {
m_cachedBytecode = WTFMove(cachedBytecode);
return 1;
// } else {
// FileSystem::truncateFile(fd, 0);
// return 0;
// }
}
}; // namespace Zig

View File

@@ -22,60 +22,66 @@ class SourceProvider;
namespace Zig {
class SourceProvider final : public JSC::SourceProvider {
WTF_MAKE_FAST_ALLOCATED;
using Base = JSC::SourceProvider;
using BytecodeCacheGenerator = JSC::BytecodeCacheGenerator;
using UnlinkedFunctionExecutable = JSC::UnlinkedFunctionExecutable;
using CachedBytecode = JSC::CachedBytecode;
using UnlinkedFunctionCodeBlock = JSC::UnlinkedFunctionCodeBlock;
using SourceCode = JSC::SourceCode;
using CodeSpecializationKind = JSC::CodeSpecializationKind;
using SourceOrigin = JSC::SourceOrigin;
WTF_MAKE_FAST_ALLOCATED;
using Base = JSC::SourceProvider;
using BytecodeCacheGenerator = JSC::BytecodeCacheGenerator;
using UnlinkedFunctionExecutable = JSC::UnlinkedFunctionExecutable;
using CachedBytecode = JSC::CachedBytecode;
using UnlinkedFunctionCodeBlock = JSC::UnlinkedFunctionCodeBlock;
using SourceCode = JSC::SourceCode;
using CodeSpecializationKind = JSC::CodeSpecializationKind;
using SourceOrigin = JSC::SourceOrigin;
public:
static Ref<SourceProvider> create(ResolvedSource resolvedSource);
~SourceProvider() {
freeSourceCode();
public:
static Ref<SourceProvider> create(ResolvedSource resolvedSource);
~SourceProvider()
{
freeSourceCode();
commitCachedBytecode();
}
commitCachedBytecode();
}
unsigned hash() const { return m_hash; };
StringView source() const { return StringView(m_source.get()); }
RefPtr<JSC::CachedBytecode> cachedBytecode() {
if (m_resolvedSource.bytecodecache_fd == 0) { return nullptr; }
unsigned hash() const { return m_hash; };
StringView source() const { return StringView(m_source.get()); }
RefPtr<JSC::CachedBytecode> cachedBytecode()
{
if (m_resolvedSource.bytecodecache_fd == 0) {
return nullptr;
}
return m_cachedBytecode;
};
return m_cachedBytecode;
};
void updateCache(const UnlinkedFunctionExecutable *executable, const SourceCode &,
CodeSpecializationKind kind, const UnlinkedFunctionCodeBlock *codeBlock);
void cacheBytecode(const BytecodeCacheGenerator &generator);
void commitCachedBytecode();
bool isBytecodeCacheEnabled() const;
void readOrGenerateByteCodeCache(JSC::VM &vm, const JSC::SourceCode &sourceCode);
ResolvedSource m_resolvedSource;
int readCache(JSC::VM &vm, const JSC::SourceCode &sourceCode);
void freeSourceCode();
void updateCache(const UnlinkedFunctionExecutable* executable, const SourceCode&,
CodeSpecializationKind kind, const UnlinkedFunctionCodeBlock* codeBlock);
void cacheBytecode(const BytecodeCacheGenerator& generator);
void commitCachedBytecode();
bool isBytecodeCacheEnabled() const;
void readOrGenerateByteCodeCache(JSC::VM& vm, const JSC::SourceCode& sourceCode);
ResolvedSource m_resolvedSource;
int readCache(JSC::VM& vm, const JSC::SourceCode& sourceCode);
void freeSourceCode();
private:
SourceProvider(ResolvedSource resolvedSource, WTF::StringImpl *sourceImpl,
const SourceOrigin &sourceOrigin, WTF::String &&sourceURL,
const TextPosition &startPosition, JSC::SourceProviderSourceType sourceType)
: Base(sourceOrigin, WTFMove(sourceURL), startPosition, sourceType), m_source(*sourceImpl) {
private:
SourceProvider(ResolvedSource resolvedSource, WTF::StringImpl* sourceImpl,
const SourceOrigin& sourceOrigin, WTF::String&& sourceURL,
const TextPosition& startPosition, JSC::SourceProviderSourceType sourceType)
: Base(sourceOrigin, WTFMove(sourceURL), startPosition, sourceType)
, m_source(*sourceImpl)
{
m_resolvedSource = resolvedSource;
m_resolvedSource = resolvedSource;
m_hash = resolvedSource.hash;
getHash();
}
m_hash = resolvedSource.hash;
getHash();
}
unsigned m_hash;
unsigned getHash();
RefPtr<JSC::CachedBytecode> m_cachedBytecode;
Ref<WTF::StringImpl> m_source;
bool did_free_source_code = false;
// JSC::SourceCodeKey key;
unsigned m_hash;
unsigned getHash();
RefPtr<JSC::CachedBytecode> m_cachedBytecode;
Ref<WTF::StringImpl> m_source;
bool did_free_source_code = false;
// JSC::SourceCodeKey key;
};
} // namespace Zig

File diff suppressed because it is too large Load Diff

View File

@@ -3,44 +3,44 @@
typedef uint16_t ZigErrorCode;
typedef struct ZigString {
const unsigned char *ptr;
size_t len;
const unsigned char* ptr;
size_t len;
} ZigString;
typedef struct ZigErrorType {
ZigErrorCode code;
void *ptr;
ZigErrorCode code;
void* ptr;
} ZigErrorType;
typedef union ErrorableZigStringResult {
ZigString value;
ZigErrorType err;
ZigString value;
ZigErrorType err;
} ErrorableZigStringResult;
typedef struct ErrorableZigString {
ErrorableZigStringResult result;
bool success;
ErrorableZigStringResult result;
bool success;
} ErrorableZigString;
typedef struct ResolvedSource {
ZigString specifier;
ZigString source_code;
ZigString source_url;
uint32_t hash;
void *allocator;
uint64_t bytecodecache_fd;
ZigString specifier;
ZigString source_code;
ZigString source_url;
uint32_t hash;
void* allocator;
uint64_t bytecodecache_fd;
} ResolvedSource;
typedef union ErrorableResolvedSourceResult {
ResolvedSource value;
ZigErrorType err;
ResolvedSource value;
ZigErrorType err;
} ErrorableResolvedSourceResult;
typedef struct ErrorableResolvedSource {
ErrorableResolvedSourceResult result;
bool success;
ErrorableResolvedSourceResult result;
bool success;
} ErrorableResolvedSource;
typedef struct SystemError {
int errno_;
ZigString code;
ZigString message;
ZigString path;
ZigString syscall;
int errno_;
ZigString code;
ZigString message;
ZigString path;
ZigString syscall;
} SystemError;
typedef uint8_t ZigStackFrameCode;
@@ -53,43 +53,43 @@ const ZigStackFrameCode ZigStackFrameCodeWasm = 5;
const ZigStackFrameCode ZigStackFrameCodeConstructor = 6;
typedef struct ZigStackFramePosition {
int32_t source_offset;
int32_t line;
int32_t line_start;
int32_t line_stop;
int32_t column_start;
int32_t column_stop;
int32_t expression_start;
int32_t expression_stop;
int32_t source_offset;
int32_t line;
int32_t line_start;
int32_t line_stop;
int32_t column_start;
int32_t column_stop;
int32_t expression_start;
int32_t expression_stop;
} ZigStackFramePosition;
typedef struct ZigStackFrame {
ZigString function_name;
ZigString source_url;
ZigStackFramePosition position;
ZigStackFrameCode code_type;
ZigString function_name;
ZigString source_url;
ZigStackFramePosition position;
ZigStackFrameCode code_type;
} ZigStackFrame;
typedef struct ZigStackTrace {
ZigString *source_lines_ptr;
int32_t *source_lines_numbers;
uint8_t source_lines_len;
uint8_t source_lines_to_collect;
ZigStackFrame *frames_ptr;
uint8_t frames_len;
ZigString* source_lines_ptr;
int32_t* source_lines_numbers;
uint8_t source_lines_len;
uint8_t source_lines_to_collect;
ZigStackFrame* frames_ptr;
uint8_t frames_len;
} ZigStackTrace;
typedef struct ZigException {
unsigned char code;
uint16_t runtime_type;
int errno_;
ZigString syscall;
ZigString code_;
ZigString path;
ZigString name;
ZigString message;
ZigStackTrace stack;
void *exception;
unsigned char code;
uint16_t runtime_type;
int errno_;
ZigString syscall;
ZigString code_;
ZigString path;
ZigString name;
ZigString message;
ZigStackTrace stack;
void* exception;
} ZigException;
typedef uint8_t JSErrorCode;
@@ -141,55 +141,55 @@ const ReadableEvent ReadableEvent__Open = 7;
const ReadableEvent ReadableEventUser = 254;
typedef struct {
uint32_t highwater_mark;
Encoding encoding;
int32_t start;
int32_t end;
bool readable;
bool aborted;
bool did_read;
bool ended;
uint8_t flowing;
bool emit_close;
bool emit_end;
uint32_t highwater_mark;
Encoding encoding;
int32_t start;
int32_t end;
bool readable;
bool aborted;
bool did_read;
bool ended;
uint8_t flowing;
bool emit_close;
bool emit_end;
} Bun__Readable;
typedef struct {
uint32_t highwater_mark;
Encoding encoding;
uint32_t start;
bool destroyed;
bool ended;
bool corked;
bool finished;
bool emit_close;
uint32_t highwater_mark;
Encoding encoding;
uint32_t start;
bool destroyed;
bool ended;
bool corked;
bool finished;
bool emit_close;
} Bun__Writable;
typedef struct {
char *ptr;
uint32_t offset;
uint32_t len;
uint32_t byte_len;
uint8_t cell_type;
char* ptr;
uint32_t offset;
uint32_t len;
uint32_t byte_len;
uint8_t cell_type;
} Bun__ArrayBuffer;
#ifdef __cplusplus
extern "C" ZigErrorCode Zig_ErrorCodeParserError;
extern "C" void ZigString__free(const unsigned char *ptr, size_t len, void *allocator);
extern "C" void Microtask__run(void *ptr, void *global);
extern "C" void ZigString__free(const unsigned char* ptr, size_t len, void* allocator);
extern "C" void Microtask__run(void* ptr, void* global);
// Used in process.version
extern "C" const char *Bun__version;
extern "C" const char* Bun__version;
// Used in process.versions
extern "C" const char *Bun__versions_webkit;
extern "C" const char *Bun__versions_mimalloc;
extern "C" const char *Bun__versions_libarchive;
extern "C" const char *Bun__versions_picohttpparser;
extern "C" const char *Bun__versions_boringssl;
extern "C" const char *Bun__versions_zlib;
extern "C" const char *Bun__versions_zig;
extern "C" const char* Bun__versions_webkit;
extern "C" const char* Bun__versions_mimalloc;
extern "C" const char* Bun__versions_libarchive;
extern "C" const char* Bun__versions_picohttpparser;
extern "C" const char* Bun__versions_boringssl;
extern "C" const char* Bun__versions_zlib;
extern "C" const char* Bun__versions_zig;
#endif

View File

@@ -2,16 +2,16 @@
//-- AUTOGENERATED FILE -- 1645447009
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
#define AUTO_EXTERN_C extern "C"
#define AUTO_EXTERN_C_ZIG extern "C" __attribute__((weak))
#define AUTO_EXTERN_C extern "C"
#define AUTO_EXTERN_C_ZIG extern "C" __attribute__((weak))
#else
#define AUTO_EXTERN_C
#define AUTO_EXTERN_C_ZIG __attribute__((weak))
#define AUTO_EXTERN_C
#define AUTO_EXTERN_C_ZIG __attribute__((weak))
#endif
#define ZIG_DECL AUTO_EXTERN_C_ZIG
#define CPP_DECL AUTO_EXTERN_C
@@ -26,227 +26,276 @@ typedef void* JSClassRef;
#include <JavaScriptCore/JSClassRef.h>
#endif
#include "headers-handwritten.h"
typedef struct bJSC__JSModuleRecord { unsigned char bytes[216]; } bJSC__JSModuleRecord;
typedef char* bJSC__JSModuleRecord_buf;
typedef struct bJSC__ThrowScope { unsigned char bytes[8]; } bJSC__ThrowScope;
typedef char* bJSC__ThrowScope_buf;
typedef struct bJSC__CallFrame { unsigned char bytes[8]; } bJSC__CallFrame;
typedef char* bJSC__CallFrame_buf;
typedef struct bJSC__PropertyName { unsigned char bytes[8]; } bJSC__PropertyName;
typedef char* bJSC__PropertyName_buf;
typedef struct bJSC__CatchScope { unsigned char bytes[8]; } bJSC__CatchScope;
typedef char* bJSC__CatchScope_buf;
typedef struct bWTF__String { unsigned char bytes[8]; } bWTF__String;
typedef char* bWTF__String_buf;
typedef struct bWTF__StringView { unsigned char bytes[16]; } bWTF__StringView;
typedef char* bWTF__StringView_buf;
typedef struct bJSC__JSModuleLoader { unsigned char bytes[16]; } bJSC__JSModuleLoader;
typedef char* bJSC__JSModuleLoader_buf;
typedef struct bJSC__Exception { unsigned char bytes[40]; } bJSC__Exception;
typedef char* bJSC__Exception_buf;
typedef struct bJSC__VM { unsigned char bytes[48824]; } bJSC__VM;
typedef char* bJSC__VM_buf;
typedef struct bJSC__JSString { unsigned char bytes[16]; } bJSC__JSString;
typedef char* bJSC__JSString_buf;
typedef struct bJSC__SourceOrigin { unsigned char bytes[48]; } bJSC__SourceOrigin;
typedef char* bJSC__SourceOrigin_buf;
typedef struct bWTF__ExternalStringImpl { unsigned char bytes[32]; } bWTF__ExternalStringImpl;
typedef char* bWTF__ExternalStringImpl_buf;
typedef struct bWTF__StringImpl { unsigned char bytes[24]; } bWTF__StringImpl;
typedef char* bWTF__StringImpl_buf;
typedef struct bJSC__SourceCode { unsigned char bytes[24]; } bJSC__SourceCode;
typedef char* bJSC__SourceCode_buf;
typedef struct bJSC__JSPromise { unsigned char bytes[32]; } bJSC__JSPromise;
typedef char* bJSC__JSPromise_buf;
typedef struct bWTF__URL { unsigned char bytes[40]; } bWTF__URL;
typedef char* bWTF__URL_buf;
typedef struct bJSC__JSFunction { unsigned char bytes[32]; } bJSC__JSFunction;
typedef char* bJSC__JSFunction_buf;
typedef struct bJSC__JSGlobalObject { unsigned char bytes[2400]; } bJSC__JSGlobalObject;
typedef char* bJSC__JSGlobalObject_buf;
typedef struct bJSC__JSCell { unsigned char bytes[8]; } bJSC__JSCell;
typedef char* bJSC__JSCell_buf;
typedef struct bJSC__JSLock { unsigned char bytes[40]; } bJSC__JSLock;
typedef char* bJSC__JSLock_buf;
typedef struct bInspector__ScriptArguments { unsigned char bytes[32]; } bInspector__ScriptArguments;
typedef char* bInspector__ScriptArguments_buf;
typedef struct bJSC__JSInternalPromise { unsigned char bytes[32]; } bJSC__JSInternalPromise;
typedef char* bJSC__JSInternalPromise_buf;
typedef struct bJSC__JSObject { unsigned char bytes[16]; } bJSC__JSObject;
typedef char* bJSC__JSObject_buf;
typedef struct bJSC__Identifier { unsigned char bytes[8]; } bJSC__Identifier;
typedef char* bJSC__Identifier_buf;
typedef struct bJSC__JSModuleRecord {
unsigned char bytes[216];
} bJSC__JSModuleRecord;
typedef char* bJSC__JSModuleRecord_buf;
typedef struct bJSC__ThrowScope {
unsigned char bytes[8];
} bJSC__ThrowScope;
typedef char* bJSC__ThrowScope_buf;
typedef struct bJSC__CallFrame {
unsigned char bytes[8];
} bJSC__CallFrame;
typedef char* bJSC__CallFrame_buf;
typedef struct bJSC__PropertyName {
unsigned char bytes[8];
} bJSC__PropertyName;
typedef char* bJSC__PropertyName_buf;
typedef struct bJSC__CatchScope {
unsigned char bytes[8];
} bJSC__CatchScope;
typedef char* bJSC__CatchScope_buf;
typedef struct bWTF__String {
unsigned char bytes[8];
} bWTF__String;
typedef char* bWTF__String_buf;
typedef struct bWTF__StringView {
unsigned char bytes[16];
} bWTF__StringView;
typedef char* bWTF__StringView_buf;
typedef struct bJSC__JSModuleLoader {
unsigned char bytes[16];
} bJSC__JSModuleLoader;
typedef char* bJSC__JSModuleLoader_buf;
typedef struct bJSC__Exception {
unsigned char bytes[40];
} bJSC__Exception;
typedef char* bJSC__Exception_buf;
typedef struct bJSC__VM {
unsigned char bytes[48824];
} bJSC__VM;
typedef char* bJSC__VM_buf;
typedef struct bJSC__JSString {
unsigned char bytes[16];
} bJSC__JSString;
typedef char* bJSC__JSString_buf;
typedef struct bJSC__SourceOrigin {
unsigned char bytes[48];
} bJSC__SourceOrigin;
typedef char* bJSC__SourceOrigin_buf;
typedef struct bWTF__ExternalStringImpl {
unsigned char bytes[32];
} bWTF__ExternalStringImpl;
typedef char* bWTF__ExternalStringImpl_buf;
typedef struct bWTF__StringImpl {
unsigned char bytes[24];
} bWTF__StringImpl;
typedef char* bWTF__StringImpl_buf;
typedef struct bJSC__SourceCode {
unsigned char bytes[24];
} bJSC__SourceCode;
typedef char* bJSC__SourceCode_buf;
typedef struct bJSC__JSPromise {
unsigned char bytes[32];
} bJSC__JSPromise;
typedef char* bJSC__JSPromise_buf;
typedef struct bWTF__URL {
unsigned char bytes[40];
} bWTF__URL;
typedef char* bWTF__URL_buf;
typedef struct bJSC__JSFunction {
unsigned char bytes[32];
} bJSC__JSFunction;
typedef char* bJSC__JSFunction_buf;
typedef struct bJSC__JSGlobalObject {
unsigned char bytes[2400];
} bJSC__JSGlobalObject;
typedef char* bJSC__JSGlobalObject_buf;
typedef struct bJSC__JSCell {
unsigned char bytes[8];
} bJSC__JSCell;
typedef char* bJSC__JSCell_buf;
typedef struct bJSC__JSLock {
unsigned char bytes[40];
} bJSC__JSLock;
typedef char* bJSC__JSLock_buf;
typedef struct bInspector__ScriptArguments {
unsigned char bytes[32];
} bInspector__ScriptArguments;
typedef char* bInspector__ScriptArguments_buf;
typedef struct bJSC__JSInternalPromise {
unsigned char bytes[32];
} bJSC__JSInternalPromise;
typedef char* bJSC__JSInternalPromise_buf;
typedef struct bJSC__JSObject {
unsigned char bytes[16];
} bJSC__JSObject;
typedef char* bJSC__JSObject_buf;
typedef struct bJSC__Identifier {
unsigned char bytes[8];
} bJSC__Identifier;
typedef char* bJSC__Identifier_buf;
#ifndef __cplusplus
typedef bJSC__CatchScope JSC__CatchScope; // JSC::CatchScope
typedef struct JSC__GeneratorPrototype JSC__GeneratorPrototype; // JSC::GeneratorPrototype
typedef struct JSC__ArrayIteratorPrototype JSC__ArrayIteratorPrototype; // JSC::ArrayIteratorPrototype
typedef ErrorableResolvedSource ErrorableResolvedSource;
typedef struct JSC__JSPromisePrototype JSC__JSPromisePrototype; // JSC::JSPromisePrototype
typedef ErrorableZigString ErrorableZigString;
typedef bJSC__PropertyName JSC__PropertyName; // JSC::PropertyName
typedef bJSC__JSObject JSC__JSObject; // JSC::JSObject
typedef bWTF__ExternalStringImpl WTF__ExternalStringImpl; // WTF::ExternalStringImpl
typedef struct JSC__AsyncIteratorPrototype JSC__AsyncIteratorPrototype; // JSC::AsyncIteratorPrototype
typedef bJSC__JSLock JSC__JSLock; // JSC::JSLock
typedef bJSC__JSModuleLoader JSC__JSModuleLoader; // JSC::JSModuleLoader
typedef struct JSC__AsyncGeneratorPrototype JSC__AsyncGeneratorPrototype; // JSC::AsyncGeneratorPrototype
typedef struct JSC__AsyncGeneratorFunctionPrototype JSC__AsyncGeneratorFunctionPrototype; // JSC::AsyncGeneratorFunctionPrototype
typedef bJSC__Identifier JSC__Identifier; // JSC::Identifier
typedef struct JSC__ArrayPrototype JSC__ArrayPrototype; // JSC::ArrayPrototype
typedef struct Zig__JSMicrotaskCallback Zig__JSMicrotaskCallback; // Zig::JSMicrotaskCallback
typedef bJSC__JSPromise JSC__JSPromise; // JSC::JSPromise
typedef struct JSC__SetIteratorPrototype JSC__SetIteratorPrototype; // JSC::SetIteratorPrototype
typedef SystemError SystemError;
typedef bJSC__JSCell JSC__JSCell; // JSC::JSCell
typedef bJSC__SourceOrigin JSC__SourceOrigin; // JSC::SourceOrigin
typedef bJSC__JSModuleRecord JSC__JSModuleRecord; // JSC::JSModuleRecord
typedef bWTF__String WTF__String; // WTF::String
typedef bWTF__URL WTF__URL; // WTF::URL
typedef struct JSC__IteratorPrototype JSC__IteratorPrototype; // JSC::IteratorPrototype
typedef Bun__Readable Bun__Readable;
typedef bJSC__JSInternalPromise JSC__JSInternalPromise; // JSC::JSInternalPromise
typedef Bun__Writable Bun__Writable;
typedef struct JSC__RegExpPrototype JSC__RegExpPrototype; // JSC::RegExpPrototype
typedef bJSC__CallFrame JSC__CallFrame; // JSC::CallFrame
typedef struct JSC__MapIteratorPrototype JSC__MapIteratorPrototype; // JSC::MapIteratorPrototype
typedef bWTF__StringView WTF__StringView; // WTF::StringView
typedef bJSC__ThrowScope JSC__ThrowScope; // JSC::ThrowScope
typedef bWTF__StringImpl WTF__StringImpl; // WTF::StringImpl
typedef bJSC__VM JSC__VM; // JSC::VM
typedef JSClassRef JSClassRef;
typedef Bun__ArrayBuffer Bun__ArrayBuffer;
typedef bJSC__JSGlobalObject JSC__JSGlobalObject; // JSC::JSGlobalObject
typedef bJSC__JSFunction JSC__JSFunction; // JSC::JSFunction
typedef struct JSC__AsyncFunctionPrototype JSC__AsyncFunctionPrototype; // JSC::AsyncFunctionPrototype
typedef ZigException ZigException;
typedef bJSC__SourceCode JSC__SourceCode; // JSC::SourceCode
typedef struct JSC__BigIntPrototype JSC__BigIntPrototype; // JSC::BigIntPrototype
typedef struct JSC__GeneratorFunctionPrototype JSC__GeneratorFunctionPrototype; // JSC::GeneratorFunctionPrototype
typedef ZigString ZigString;
typedef int64_t JSC__JSValue;
typedef struct JSC__FunctionPrototype JSC__FunctionPrototype; // JSC::FunctionPrototype
typedef bInspector__ScriptArguments Inspector__ScriptArguments; // Inspector::ScriptArguments
typedef bJSC__Exception JSC__Exception; // JSC::Exception
typedef bJSC__JSString JSC__JSString; // JSC::JSString
typedef struct JSC__ObjectPrototype JSC__ObjectPrototype; // JSC::ObjectPrototype
typedef struct JSC__StringPrototype JSC__StringPrototype; // JSC::StringPrototype
typedef bJSC__CatchScope JSC__CatchScope; // JSC::CatchScope
typedef struct JSC__GeneratorPrototype JSC__GeneratorPrototype; // JSC::GeneratorPrototype
typedef struct JSC__ArrayIteratorPrototype JSC__ArrayIteratorPrototype; // JSC::ArrayIteratorPrototype
typedef ErrorableResolvedSource ErrorableResolvedSource;
typedef struct JSC__JSPromisePrototype JSC__JSPromisePrototype; // JSC::JSPromisePrototype
typedef ErrorableZigString ErrorableZigString;
typedef bJSC__PropertyName JSC__PropertyName; // JSC::PropertyName
typedef bJSC__JSObject JSC__JSObject; // JSC::JSObject
typedef bWTF__ExternalStringImpl WTF__ExternalStringImpl; // WTF::ExternalStringImpl
typedef struct JSC__AsyncIteratorPrototype JSC__AsyncIteratorPrototype; // JSC::AsyncIteratorPrototype
typedef bJSC__JSLock JSC__JSLock; // JSC::JSLock
typedef bJSC__JSModuleLoader JSC__JSModuleLoader; // JSC::JSModuleLoader
typedef struct JSC__AsyncGeneratorPrototype JSC__AsyncGeneratorPrototype; // JSC::AsyncGeneratorPrototype
typedef struct JSC__AsyncGeneratorFunctionPrototype JSC__AsyncGeneratorFunctionPrototype; // JSC::AsyncGeneratorFunctionPrototype
typedef bJSC__Identifier JSC__Identifier; // JSC::Identifier
typedef struct JSC__ArrayPrototype JSC__ArrayPrototype; // JSC::ArrayPrototype
typedef struct Zig__JSMicrotaskCallback Zig__JSMicrotaskCallback; // Zig::JSMicrotaskCallback
typedef bJSC__JSPromise JSC__JSPromise; // JSC::JSPromise
typedef struct JSC__SetIteratorPrototype JSC__SetIteratorPrototype; // JSC::SetIteratorPrototype
typedef SystemError SystemError;
typedef bJSC__JSCell JSC__JSCell; // JSC::JSCell
typedef bJSC__SourceOrigin JSC__SourceOrigin; // JSC::SourceOrigin
typedef bJSC__JSModuleRecord JSC__JSModuleRecord; // JSC::JSModuleRecord
typedef bWTF__String WTF__String; // WTF::String
typedef bWTF__URL WTF__URL; // WTF::URL
typedef struct JSC__IteratorPrototype JSC__IteratorPrototype; // JSC::IteratorPrototype
typedef Bun__Readable Bun__Readable;
typedef bJSC__JSInternalPromise JSC__JSInternalPromise; // JSC::JSInternalPromise
typedef Bun__Writable Bun__Writable;
typedef struct JSC__RegExpPrototype JSC__RegExpPrototype; // JSC::RegExpPrototype
typedef bJSC__CallFrame JSC__CallFrame; // JSC::CallFrame
typedef struct JSC__MapIteratorPrototype JSC__MapIteratorPrototype; // JSC::MapIteratorPrototype
typedef bWTF__StringView WTF__StringView; // WTF::StringView
typedef bJSC__ThrowScope JSC__ThrowScope; // JSC::ThrowScope
typedef bWTF__StringImpl WTF__StringImpl; // WTF::StringImpl
typedef bJSC__VM JSC__VM; // JSC::VM
typedef JSClassRef JSClassRef;
typedef Bun__ArrayBuffer Bun__ArrayBuffer;
typedef bJSC__JSGlobalObject JSC__JSGlobalObject; // JSC::JSGlobalObject
typedef bJSC__JSFunction JSC__JSFunction; // JSC::JSFunction
typedef struct JSC__AsyncFunctionPrototype JSC__AsyncFunctionPrototype; // JSC::AsyncFunctionPrototype
typedef ZigException ZigException;
typedef bJSC__SourceCode JSC__SourceCode; // JSC::SourceCode
typedef struct JSC__BigIntPrototype JSC__BigIntPrototype; // JSC::BigIntPrototype
typedef struct JSC__GeneratorFunctionPrototype JSC__GeneratorFunctionPrototype; // JSC::GeneratorFunctionPrototype
typedef ZigString ZigString;
typedef int64_t JSC__JSValue;
typedef struct JSC__FunctionPrototype JSC__FunctionPrototype; // JSC::FunctionPrototype
typedef bInspector__ScriptArguments Inspector__ScriptArguments; // Inspector::ScriptArguments
typedef bJSC__Exception JSC__Exception; // JSC::Exception
typedef bJSC__JSString JSC__JSString; // JSC::JSString
typedef struct JSC__ObjectPrototype JSC__ObjectPrototype; // JSC::ObjectPrototype
typedef struct JSC__StringPrototype JSC__StringPrototype; // JSC::StringPrototype
#endif
#ifdef __cplusplus
namespace JSC {
class JSCell;
class Exception;
class JSPromisePrototype;
class StringPrototype;
class GeneratorFunctionPrototype;
class ArrayPrototype;
class JSString;
class JSObject;
class AsyncIteratorPrototype;
class AsyncGeneratorFunctionPrototype;
class Identifier;
class JSPromise;
class RegExpPrototype;
class AsyncFunctionPrototype;
class CatchScope;
class VM;
class BigIntPrototype;
class SourceOrigin;
class ThrowScope;
class SetIteratorPrototype;
class AsyncGeneratorPrototype;
class PropertyName;
class MapIteratorPrototype;
class JSModuleRecord;
class JSInternalPromise;
class ArrayIteratorPrototype;
class JSFunction;
class JSModuleLoader;
class GeneratorPrototype;
class JSGlobalObject;
class SourceCode;
class JSLock;
class FunctionPrototype;
class IteratorPrototype;
class CallFrame;
class ObjectPrototype;
}
namespace WTF {
class URL;
class StringImpl;
class String;
class StringView;
class ExternalStringImpl;
}
namespace Zig {
class JSMicrotaskCallback;
}
namespace Inspector {
class ScriptArguments;
}
namespace JSC {
class JSCell;
class Exception;
class JSPromisePrototype;
class StringPrototype;
class GeneratorFunctionPrototype;
class ArrayPrototype;
class JSString;
class JSObject;
class AsyncIteratorPrototype;
class AsyncGeneratorFunctionPrototype;
class Identifier;
class JSPromise;
class RegExpPrototype;
class AsyncFunctionPrototype;
class CatchScope;
class VM;
class BigIntPrototype;
class SourceOrigin;
class ThrowScope;
class SetIteratorPrototype;
class AsyncGeneratorPrototype;
class PropertyName;
class MapIteratorPrototype;
class JSModuleRecord;
class JSInternalPromise;
class ArrayIteratorPrototype;
class JSFunction;
class JSModuleLoader;
class GeneratorPrototype;
class JSGlobalObject;
class SourceCode;
class JSLock;
class FunctionPrototype;
class IteratorPrototype;
class CallFrame;
class ObjectPrototype;
}
namespace WTF {
class URL;
class StringImpl;
class String;
class StringView;
class ExternalStringImpl;
}
namespace Zig {
class JSMicrotaskCallback;
}
namespace Inspector {
class ScriptArguments;
}
typedef ErrorableResolvedSource ErrorableResolvedSource;
typedef ErrorableZigString ErrorableZigString;
typedef SystemError SystemError;
typedef Bun__Readable Bun__Readable;
typedef Bun__Writable Bun__Writable;
typedef JSClassRef JSClassRef;
typedef Bun__ArrayBuffer Bun__ArrayBuffer;
typedef ZigException ZigException;
typedef ZigString ZigString;
typedef int64_t JSC__JSValue;
using JSC__JSCell = JSC::JSCell;
using JSC__Exception = JSC::Exception;
using JSC__JSPromisePrototype = JSC::JSPromisePrototype;
using JSC__StringPrototype = JSC::StringPrototype;
using JSC__GeneratorFunctionPrototype = JSC::GeneratorFunctionPrototype;
using JSC__ArrayPrototype = JSC::ArrayPrototype;
using JSC__JSString = JSC::JSString;
using JSC__JSObject = JSC::JSObject;
using JSC__AsyncIteratorPrototype = JSC::AsyncIteratorPrototype;
using JSC__AsyncGeneratorFunctionPrototype = JSC::AsyncGeneratorFunctionPrototype;
using JSC__Identifier = JSC::Identifier;
using JSC__JSPromise = JSC::JSPromise;
using JSC__RegExpPrototype = JSC::RegExpPrototype;
using JSC__AsyncFunctionPrototype = JSC::AsyncFunctionPrototype;
using JSC__CatchScope = JSC::CatchScope;
using JSC__VM = JSC::VM;
using JSC__BigIntPrototype = JSC::BigIntPrototype;
using JSC__SourceOrigin = JSC::SourceOrigin;
using JSC__ThrowScope = JSC::ThrowScope;
using JSC__SetIteratorPrototype = JSC::SetIteratorPrototype;
using JSC__AsyncGeneratorPrototype = JSC::AsyncGeneratorPrototype;
using JSC__PropertyName = JSC::PropertyName;
using JSC__MapIteratorPrototype = JSC::MapIteratorPrototype;
using JSC__JSModuleRecord = JSC::JSModuleRecord;
using JSC__JSInternalPromise = JSC::JSInternalPromise;
using JSC__ArrayIteratorPrototype = JSC::ArrayIteratorPrototype;
using JSC__JSFunction = JSC::JSFunction;
using JSC__JSModuleLoader = JSC::JSModuleLoader;
using JSC__GeneratorPrototype = JSC::GeneratorPrototype;
using JSC__JSGlobalObject = JSC::JSGlobalObject;
using JSC__SourceCode = JSC::SourceCode;
using JSC__JSLock = JSC::JSLock;
using JSC__FunctionPrototype = JSC::FunctionPrototype;
using JSC__IteratorPrototype = JSC::IteratorPrototype;
using JSC__CallFrame = JSC::CallFrame;
using JSC__ObjectPrototype = JSC::ObjectPrototype;
using WTF__URL = WTF::URL;
using WTF__StringImpl = WTF::StringImpl;
using WTF__String = WTF::String;
using WTF__StringView = WTF::StringView;
using WTF__ExternalStringImpl = WTF::ExternalStringImpl;
using Zig__JSMicrotaskCallback = Zig::JSMicrotaskCallback;
using Inspector__ScriptArguments = Inspector::ScriptArguments;
typedef ErrorableResolvedSource ErrorableResolvedSource;
typedef ErrorableZigString ErrorableZigString;
typedef SystemError SystemError;
typedef Bun__Readable Bun__Readable;
typedef Bun__Writable Bun__Writable;
typedef JSClassRef JSClassRef;
typedef Bun__ArrayBuffer Bun__ArrayBuffer;
typedef ZigException ZigException;
typedef ZigString ZigString;
typedef int64_t JSC__JSValue;
using JSC__JSCell = JSC::JSCell;
using JSC__Exception = JSC::Exception;
using JSC__JSPromisePrototype = JSC::JSPromisePrototype;
using JSC__StringPrototype = JSC::StringPrototype;
using JSC__GeneratorFunctionPrototype = JSC::GeneratorFunctionPrototype;
using JSC__ArrayPrototype = JSC::ArrayPrototype;
using JSC__JSString = JSC::JSString;
using JSC__JSObject = JSC::JSObject;
using JSC__AsyncIteratorPrototype = JSC::AsyncIteratorPrototype;
using JSC__AsyncGeneratorFunctionPrototype = JSC::AsyncGeneratorFunctionPrototype;
using JSC__Identifier = JSC::Identifier;
using JSC__JSPromise = JSC::JSPromise;
using JSC__RegExpPrototype = JSC::RegExpPrototype;
using JSC__AsyncFunctionPrototype = JSC::AsyncFunctionPrototype;
using JSC__CatchScope = JSC::CatchScope;
using JSC__VM = JSC::VM;
using JSC__BigIntPrototype = JSC::BigIntPrototype;
using JSC__SourceOrigin = JSC::SourceOrigin;
using JSC__ThrowScope = JSC::ThrowScope;
using JSC__SetIteratorPrototype = JSC::SetIteratorPrototype;
using JSC__AsyncGeneratorPrototype = JSC::AsyncGeneratorPrototype;
using JSC__PropertyName = JSC::PropertyName;
using JSC__MapIteratorPrototype = JSC::MapIteratorPrototype;
using JSC__JSModuleRecord = JSC::JSModuleRecord;
using JSC__JSInternalPromise = JSC::JSInternalPromise;
using JSC__ArrayIteratorPrototype = JSC::ArrayIteratorPrototype;
using JSC__JSFunction = JSC::JSFunction;
using JSC__JSModuleLoader = JSC::JSModuleLoader;
using JSC__GeneratorPrototype = JSC::GeneratorPrototype;
using JSC__JSGlobalObject = JSC::JSGlobalObject;
using JSC__SourceCode = JSC::SourceCode;
using JSC__JSLock = JSC::JSLock;
using JSC__FunctionPrototype = JSC::FunctionPrototype;
using JSC__IteratorPrototype = JSC::IteratorPrototype;
using JSC__CallFrame = JSC::CallFrame;
using JSC__ObjectPrototype = JSC::ObjectPrototype;
using WTF__URL = WTF::URL;
using WTF__StringImpl = WTF::StringImpl;
using WTF__String = WTF::String;
using WTF__StringView = WTF::StringView;
using WTF__ExternalStringImpl = WTF::ExternalStringImpl;
using Zig__JSMicrotaskCallback = Zig::JSMicrotaskCallback;
using Inspector__ScriptArguments = Inspector::ScriptArguments;
#endif
#pragma mark - JSC::JSObject
CPP_DECL JSC__JSValue JSC__JSObject__create(JSC__JSGlobalObject* arg0, size_t arg1, void* arg2, void (* ArgFn3)(void* arg0, JSC__JSObject* arg1, JSC__JSGlobalObject* arg2));
CPP_DECL JSC__JSValue JSC__JSObject__create(JSC__JSGlobalObject* arg0, size_t arg1, void* arg2, void (*ArgFn3)(void* arg0, JSC__JSObject* arg1, JSC__JSGlobalObject* arg2));
CPP_DECL size_t JSC__JSObject__getArrayLength(JSC__JSObject* arg0);
CPP_DECL JSC__JSValue JSC__JSObject__getDirect(JSC__JSObject* arg0, JSC__JSGlobalObject* arg1, const ZigString* arg2);
CPP_DECL JSC__JSValue JSC__JSObject__getIndex(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, uint32_t arg2);
@@ -343,7 +392,7 @@ CPP_DECL JSC__JSValue JSC__JSFunction__constructWithArguments(JSC__JSValue JSVal
CPP_DECL JSC__JSValue JSC__JSFunction__constructWithArgumentsAndNewTarget(JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSGlobalObject* arg2, JSC__JSValue* arg3, size_t arg4, JSC__Exception** arg5, const unsigned char* arg6);
CPP_DECL JSC__JSValue JSC__JSFunction__constructWithNewTarget(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2, JSC__Exception** arg3, const unsigned char* arg4);
CPP_DECL JSC__JSValue JSC__JSFunction__constructWithoutAnyArgumentsOrNewTarget(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__Exception** arg2, const unsigned char* arg3);
CPP_DECL JSC__JSFunction* JSC__JSFunction__createFromNative(JSC__JSGlobalObject* arg0, uint16_t arg1, const WTF__String* arg2, void* arg3, JSC__JSValue (* ArgFn4)(void* arg0, JSC__JSGlobalObject* arg1, JSC__CallFrame* arg2));
CPP_DECL JSC__JSFunction* JSC__JSFunction__createFromNative(JSC__JSGlobalObject* arg0, uint16_t arg1, const WTF__String* arg2, void* arg3, JSC__JSValue (*ArgFn4)(void* arg0, JSC__JSGlobalObject* arg1, JSC__CallFrame* arg2));
CPP_DECL bWTF__String JSC__JSFunction__displayName(JSC__JSFunction* arg0, JSC__VM* arg1);
CPP_DECL bWTF__String JSC__JSFunction__getName(JSC__JSFunction* arg0, JSC__VM* arg1);
@@ -442,7 +491,7 @@ CPP_DECL JSC__JSValue JSC__JSValue__createStringArray(JSC__JSGlobalObject* arg0,
CPP_DECL JSC__JSValue JSC__JSValue__createTypeError(const ZigString* arg0, const ZigString* arg1, JSC__JSGlobalObject* arg2);
CPP_DECL bool JSC__JSValue__eqlCell(JSC__JSValue JSValue0, JSC__JSCell* arg1);
CPP_DECL bool JSC__JSValue__eqlValue(JSC__JSValue JSValue0, JSC__JSValue JSValue1);
CPP_DECL void JSC__JSValue__forEach(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, void (* ArgFn2)(JSC__VM* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2));
CPP_DECL void JSC__JSValue__forEach(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, void (*ArgFn2)(JSC__VM* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2));
CPP_DECL JSC__JSValue JSC__JSValue__fromEntries(JSC__JSGlobalObject* arg0, ZigString* arg1, ZigString* arg2, size_t arg3, bool arg4);
CPP_DECL void JSC__JSValue__getClassName(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, ZigString* arg2);
CPP_DECL JSC__JSValue JSC__JSValue__getErrorsProperty(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1);
@@ -527,7 +576,7 @@ CPP_DECL void JSC__VM__deinit(JSC__VM* arg0, JSC__JSGlobalObject* arg1);
CPP_DECL void JSC__VM__deleteAllCode(JSC__VM* arg0, JSC__JSGlobalObject* arg1);
CPP_DECL void JSC__VM__drainMicrotasks(JSC__VM* arg0);
CPP_DECL bool JSC__VM__executionForbidden(JSC__VM* arg0);
CPP_DECL void JSC__VM__holdAPILock(JSC__VM* arg0, void* arg1, void (* ArgFn2)(void* arg0));
CPP_DECL void JSC__VM__holdAPILock(JSC__VM* arg0, void* arg1, void (*ArgFn2)(void* arg0));
CPP_DECL bool JSC__VM__isEntered(JSC__VM* arg0);
CPP_DECL bool JSC__VM__isJITEnabled();
CPP_DECL JSC__JSValue JSC__VM__runGC(JSC__VM* arg0, bool arg1);
@@ -535,7 +584,7 @@ CPP_DECL void JSC__VM__setExecutionForbidden(JSC__VM* arg0, bool arg1);
CPP_DECL void JSC__VM__setExecutionTimeLimit(JSC__VM* arg0, double arg1);
CPP_DECL void JSC__VM__shrinkFootprint(JSC__VM* arg0);
CPP_DECL bool JSC__VM__throwError(JSC__VM* arg0, JSC__JSGlobalObject* arg1, JSC__ThrowScope* arg2, const unsigned char* arg3, size_t arg4);
CPP_DECL void JSC__VM__whenIdle(JSC__VM* arg0, void (* ArgFn1)());
CPP_DECL void JSC__VM__whenIdle(JSC__VM* arg0, void (*ArgFn1)());
#pragma mark - JSC::ThrowScope
@@ -593,7 +642,7 @@ CPP_DECL size_t WTF__StringImpl__length(const WTF__StringImpl* arg0);
CPP_DECL const uint16_t* WTF__ExternalStringImpl__characters16(const WTF__ExternalStringImpl* arg0);
CPP_DECL const unsigned char* WTF__ExternalStringImpl__characters8(const WTF__ExternalStringImpl* arg0);
CPP_DECL bWTF__ExternalStringImpl WTF__ExternalStringImpl__create(const unsigned char* arg0, size_t arg1, void (* ArgFn2)(void* arg0, unsigned char* arg1, size_t arg2));
CPP_DECL bWTF__ExternalStringImpl WTF__ExternalStringImpl__create(const unsigned char* arg0, size_t arg1, void (*ArgFn2)(void* arg0, unsigned char* arg1, size_t arg2));
CPP_DECL bool WTF__ExternalStringImpl__is16Bit(const WTF__ExternalStringImpl* arg0);
CPP_DECL bool WTF__ExternalStringImpl__is8Bit(const WTF__ExternalStringImpl* arg0);
CPP_DECL bool WTF__ExternalStringImpl__isEmpty(const WTF__ExternalStringImpl* arg0);
@@ -704,7 +753,6 @@ CPP_DECL ZigException ZigException__fromException(JSC__Exception* arg0);
#pragma mark - Zig::ConsoleClient
#ifdef __cplusplus
ZIG_DECL void Zig__ConsoleClient__count(void* arg0, JSC__JSGlobalObject* arg1, const unsigned char* arg2, size_t arg3);
@@ -725,7 +773,6 @@ ZIG_DECL void Zig__ConsoleClient__timeStamp(void* arg0, JSC__JSGlobalObject* arg
#pragma mark - Bun__Timer
#ifdef __cplusplus
ZIG_DECL JSC__JSValue Bun__Timer__clearInterval(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1);

View File

@@ -12,56 +12,63 @@
#include <JavaScriptCore/ThrowScope.h>
#include <JavaScriptCore/VM.h>
template <class CppType, typename ZigType> class Wrap {
public:
Wrap(){};
template<class CppType, typename ZigType> class Wrap {
public:
Wrap() {};
Wrap(ZigType zig) {
result = zig;
cpp = static_cast<CppType *>(static_cast<void *>(&zig));
};
Wrap(ZigType zig)
{
result = zig;
cpp = static_cast<CppType*>(static_cast<void*>(&zig));
};
Wrap(ZigType *zig) { cpp = static_cast<CppType *>(static_cast<void *>(&zig)); };
Wrap(ZigType* zig) { cpp = static_cast<CppType*>(static_cast<void*>(&zig)); };
Wrap(CppType _cpp) {
auto buffer = alignedBuffer();
cpp = new (buffer) CppType(_cpp);
};
Wrap(CppType _cpp)
{
auto buffer = alignedBuffer();
cpp = new (buffer) CppType(_cpp);
};
~Wrap(){};
~Wrap() {};
unsigned char *alignedBuffer() {
return result.bytes + alignof(CppType) -
reinterpret_cast<intptr_t>(result.bytes) % alignof(CppType);
}
unsigned char* alignedBuffer()
{
return result.bytes + alignof(CppType) - reinterpret_cast<intptr_t>(result.bytes) % alignof(CppType);
}
ZigType result;
CppType *cpp;
ZigType result;
CppType* cpp;
static ZigType wrap(CppType obj) { return *static_cast<ZigType *>(static_cast<void *>(&obj)); }
static ZigType wrap(CppType obj) { return *static_cast<ZigType*>(static_cast<void*>(&obj)); }
static CppType unwrap(ZigType obj) { return *static_cast<CppType *>(static_cast<void *>(&obj)); }
static CppType unwrap(ZigType obj) { return *static_cast<CppType*>(static_cast<void*>(&obj)); }
static CppType *unwrap(ZigType *obj) { return static_cast<CppType *>(static_cast<void *>(obj)); }
static CppType* unwrap(ZigType* obj) { return static_cast<CppType*>(static_cast<void*>(obj)); }
};
template <class To, class From> To cast(From v) {
return *static_cast<To *>(static_cast<void *>(v));
template<class To, class From> To cast(From v)
{
return *static_cast<To*>(static_cast<void*>(v));
}
template <class To, class From> To ccast(From v) {
return *static_cast<const To *>(static_cast<const void *>(v));
template<class To, class From> To ccast(From v)
{
return *static_cast<const To*>(static_cast<const void*>(v));
}
typedef JSC__JSValue (*NativeCallbackFunction)(void *arg0, JSC__JSGlobalObject *arg1,
JSC__CallFrame *arg2);
typedef JSC__JSValue (*NativeCallbackFunction)(void* arg0, JSC__JSGlobalObject* arg1,
JSC__CallFrame* arg2);
static const JSC::ArgList makeArgs(JSC__JSValue *v, size_t count) {
JSC::MarkedArgumentBuffer args = JSC::MarkedArgumentBuffer();
args.ensureCapacity(count);
for (size_t i = 0; i < count; ++i) { args.append(JSC::JSValue::decode(v[i])); }
static const JSC::ArgList makeArgs(JSC__JSValue* v, size_t count)
{
JSC::MarkedArgumentBuffer args = JSC::MarkedArgumentBuffer();
args.ensureCapacity(count);
for (size_t i = 0; i < count; ++i) {
args.append(JSC::JSValue::decode(v[i]));
}
return JSC::ArgList(args);
return JSC::ArgList(args);
}
namespace Zig {
@@ -70,159 +77,189 @@ namespace Zig {
// we tag the final two bits
// so 56 bits are copied over
// rest we zero out for consistentcy
static const unsigned char *untag(const unsigned char *ptr) {
return reinterpret_cast<const unsigned char *>(
((reinterpret_cast<uintptr_t>(ptr) & ~(static_cast<uint64_t>(1) << 63) &
~(static_cast<uint64_t>(1) << 62)) &
~(static_cast<uint64_t>(1) << 61)));
static const unsigned char* untag(const unsigned char* ptr)
{
return reinterpret_cast<const unsigned char*>(
((reinterpret_cast<uintptr_t>(ptr) & ~(static_cast<uint64_t>(1) << 63) & ~(static_cast<uint64_t>(1) << 62)) & ~(static_cast<uint64_t>(1) << 61)));
}
static const JSC::Identifier toIdentifier(ZigString str, JSC::JSGlobalObject *global) {
if (str.len == 0 || str.ptr == nullptr) { return JSC::Identifier::EmptyIdentifier; }
static const JSC::Identifier toIdentifier(ZigString str, JSC::JSGlobalObject* global)
{
if (str.len == 0 || str.ptr == nullptr) {
return JSC::Identifier::EmptyIdentifier;
}
return JSC::Identifier::fromString(global->vm(), untag(str.ptr), str.len);
return JSC::Identifier::fromString(global->vm(), untag(str.ptr), str.len);
}
static bool isTaggedUTF16Ptr(const unsigned char *ptr) {
return (reinterpret_cast<uintptr_t>(ptr) & (static_cast<uint64_t>(1) << 63)) != 0;
static bool isTaggedUTF16Ptr(const unsigned char* ptr)
{
return (reinterpret_cast<uintptr_t>(ptr) & (static_cast<uint64_t>(1) << 63)) != 0;
}
// Do we need to convert the string from UTF-8 to UTF-16?
static bool isTaggedUTF8Ptr(const unsigned char *ptr) {
return (reinterpret_cast<uintptr_t>(ptr) & (static_cast<uint64_t>(1) << 61)) != 0;
static bool isTaggedUTF8Ptr(const unsigned char* ptr)
{
return (reinterpret_cast<uintptr_t>(ptr) & (static_cast<uint64_t>(1) << 61)) != 0;
}
static bool isTaggedExternalPtr(const unsigned char *ptr) {
return (reinterpret_cast<uintptr_t>(ptr) & (static_cast<uint64_t>(1) << 62)) != 0;
static bool isTaggedExternalPtr(const unsigned char* ptr)
{
return (reinterpret_cast<uintptr_t>(ptr) & (static_cast<uint64_t>(1) << 62)) != 0;
}
static const WTF::String toString(ZigString str) {
if (str.len == 0 || str.ptr == nullptr) { return WTF::String(); }
if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) { return WTF::String::fromUTF8(untag(str.ptr), str.len); }
static const WTF::String toString(ZigString str)
{
if (str.len == 0 || str.ptr == nullptr) {
return WTF::String();
}
if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) {
return WTF::String::fromUTF8(untag(str.ptr), str.len);
}
return !isTaggedUTF16Ptr(str.ptr)
? WTF::String(WTF::StringImpl::createWithoutCopying(untag(str.ptr), str.len))
: WTF::String(WTF::StringImpl::createWithoutCopying(
reinterpret_cast<const UChar *>(untag(str.ptr)), str.len));
return !isTaggedUTF16Ptr(str.ptr)
? WTF::String(WTF::StringImpl::createWithoutCopying(untag(str.ptr), str.len))
: WTF::String(WTF::StringImpl::createWithoutCopying(
reinterpret_cast<const UChar*>(untag(str.ptr)), str.len));
}
static const WTF::String toStringCopy(ZigString str) {
if (str.len == 0 || str.ptr == nullptr) { return WTF::String(); }
if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) { return WTF::String::fromUTF8(untag(str.ptr), str.len); }
static const WTF::String toStringCopy(ZigString str)
{
if (str.len == 0 || str.ptr == nullptr) {
return WTF::String();
}
if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) {
return WTF::String::fromUTF8(untag(str.ptr), str.len);
}
return !isTaggedUTF16Ptr(str.ptr) ? WTF::String(WTF::StringImpl::create(untag(str.ptr), str.len))
: WTF::String(WTF::StringImpl::create(
reinterpret_cast<const UChar *>(untag(str.ptr)), str.len));
return !isTaggedUTF16Ptr(str.ptr) ? WTF::String(WTF::StringImpl::create(untag(str.ptr), str.len))
: WTF::String(WTF::StringImpl::create(
reinterpret_cast<const UChar*>(untag(str.ptr)), str.len));
}
static WTF::String toStringNotConst(ZigString str) { return toString(str); }
static const JSC::JSString *toJSString(ZigString str, JSC::JSGlobalObject *global) {
return JSC::jsOwnedString(global->vm(), toString(str));
static const JSC::JSString* toJSString(ZigString str, JSC::JSGlobalObject* global)
{
return JSC::jsOwnedString(global->vm(), toString(str));
}
static const JSC::JSValue toJSStringValue(ZigString str, JSC::JSGlobalObject *global) {
return JSC::JSValue(toJSString(str, global));
static const JSC::JSValue toJSStringValue(ZigString str, JSC::JSGlobalObject* global)
{
return JSC::JSValue(toJSString(str, global));
}
static const JSC::JSString *toJSStringGC(ZigString str, JSC::JSGlobalObject *global) {
return JSC::jsString(global->vm(), toStringCopy(str));
static const JSC::JSString* toJSStringGC(ZigString str, JSC::JSGlobalObject* global)
{
return JSC::jsString(global->vm(), toStringCopy(str));
}
static const JSC::JSValue toJSStringValueGC(ZigString str, JSC::JSGlobalObject *global) {
return JSC::JSValue(toJSString(str, global));
static const JSC::JSValue toJSStringValueGC(ZigString str, JSC::JSGlobalObject* global)
{
return JSC::JSValue(toJSString(str, global));
}
static const ZigString ZigStringEmpty = ZigString{nullptr, 0};
static const ZigString ZigStringEmpty = ZigString { nullptr, 0 };
static const unsigned char __dot_char = '.';
static const ZigString ZigStringCwd = ZigString{&__dot_char, 1};
static const ZigString ZigStringCwd = ZigString { &__dot_char, 1 };
static const unsigned char *taggedUTF16Ptr(const UChar *ptr) {
return reinterpret_cast<const unsigned char *>(reinterpret_cast<uintptr_t>(ptr) |
(static_cast<uint64_t>(1) << 63));
static const unsigned char* taggedUTF16Ptr(const UChar* ptr)
{
return reinterpret_cast<const unsigned char*>(reinterpret_cast<uintptr_t>(ptr) | (static_cast<uint64_t>(1) << 63));
}
static ZigString toZigString(WTF::String str) {
return str.isEmpty()
? ZigStringEmpty
: ZigString{str.is8Bit() ? str.characters8() : taggedUTF16Ptr(str.characters16()),
str.length()};
static ZigString toZigString(WTF::String str)
{
return str.isEmpty()
? ZigStringEmpty
: ZigString { str.is8Bit() ? str.characters8() : taggedUTF16Ptr(str.characters16()),
str.length() };
}
static ZigString toZigString(WTF::String *str) {
return str->isEmpty()
? ZigStringEmpty
: ZigString{str->is8Bit() ? str->characters8() : taggedUTF16Ptr(str->characters16()),
str->length()};
static ZigString toZigString(WTF::String* str)
{
return str->isEmpty()
? ZigStringEmpty
: ZigString { str->is8Bit() ? str->characters8() : taggedUTF16Ptr(str->characters16()),
str->length() };
}
static ZigString toZigString(WTF::StringImpl &str) {
return str.isEmpty()
? ZigStringEmpty
: ZigString{str.is8Bit() ? str.characters8() : taggedUTF16Ptr(str.characters16()),
str.length()};
static ZigString toZigString(WTF::StringImpl& str)
{
return str.isEmpty()
? ZigStringEmpty
: ZigString { str.is8Bit() ? str.characters8() : taggedUTF16Ptr(str.characters16()),
str.length() };
}
static ZigString toZigString(WTF::StringView &str) {
return str.isEmpty()
? ZigStringEmpty
: ZigString{str.is8Bit() ? str.characters8() : taggedUTF16Ptr(str.characters16()),
str.length()};
static ZigString toZigString(WTF::StringView& str)
{
return str.isEmpty()
? ZigStringEmpty
: ZigString { str.is8Bit() ? str.characters8() : taggedUTF16Ptr(str.characters16()),
str.length() };
}
static ZigString toZigString(JSC::JSString &str, JSC::JSGlobalObject *global) {
return toZigString(str.value(global));
static ZigString toZigString(JSC::JSString& str, JSC::JSGlobalObject* global)
{
return toZigString(str.value(global));
}
static ZigString toZigString(JSC::JSString *str, JSC::JSGlobalObject *global) {
return toZigString(str->value(global));
static ZigString toZigString(JSC::JSString* str, JSC::JSGlobalObject* global)
{
return toZigString(str->value(global));
}
static ZigString toZigString(JSC::Identifier &str, JSC::JSGlobalObject *global) {
return toZigString(str.string());
static ZigString toZigString(JSC::Identifier& str, JSC::JSGlobalObject* global)
{
return toZigString(str.string());
}
static ZigString toZigString(JSC::Identifier *str, JSC::JSGlobalObject *global) {
return toZigString(str->string());
static ZigString toZigString(JSC::Identifier* str, JSC::JSGlobalObject* global)
{
return toZigString(str->string());
}
static WTF::StringView toStringView(ZigString str) {
return WTF::StringView(untag(str.ptr), str.len);
static WTF::StringView toStringView(ZigString str)
{
return WTF::StringView(untag(str.ptr), str.len);
}
static void throwException(JSC::ThrowScope &scope, ZigErrorType err, JSC::JSGlobalObject *global) {
scope.throwException(global,
JSC::Exception::create(global->vm(), JSC::JSValue((JSC::JSCell *)err.ptr)));
static void throwException(JSC::ThrowScope& scope, ZigErrorType err, JSC::JSGlobalObject* global)
{
scope.throwException(global,
JSC::Exception::create(global->vm(), JSC::JSValue((JSC::JSCell*)err.ptr)));
}
static ZigString toZigString(JSC::JSValue val, JSC::JSGlobalObject *global) {
auto scope = DECLARE_THROW_SCOPE(global->vm());
WTF::String str = val.toWTFString(global);
static ZigString toZigString(JSC::JSValue val, JSC::JSGlobalObject* global)
{
auto scope = DECLARE_THROW_SCOPE(global->vm());
WTF::String str = val.toWTFString(global);
if (scope.exception()) {
scope.clearException();
scope.release();
return ZigStringEmpty;
}
if (scope.exception()) {
scope.clearException();
scope.release();
return ZigStringEmpty;
}
scope.release();
return toZigString(str);
return toZigString(str);
}
static JSC::JSValue getErrorInstance(const ZigString *str, JSC__JSGlobalObject *globalObject) {
JSC::VM &vm = globalObject->vm();
static JSC::JSValue getErrorInstance(const ZigString* str, JSC__JSGlobalObject* globalObject)
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSC::JSValue message = Zig::toJSString(*str, globalObject);
JSC::JSValue options = JSC::jsUndefined();
JSC::Structure *errorStructure = globalObject->errorStructure();
JSC::JSObject *result =
JSC::ErrorInstance::create(globalObject, errorStructure, message, options);
RETURN_IF_EXCEPTION(scope, JSC::JSValue());
scope.release();
auto scope = DECLARE_THROW_SCOPE(vm);
JSC::JSValue message = Zig::toJSString(*str, globalObject);
JSC::JSValue options = JSC::jsUndefined();
JSC::Structure* errorStructure = globalObject->errorStructure();
JSC::JSObject* result = JSC::ErrorInstance::create(globalObject, errorStructure, message, options);
RETURN_IF_EXCEPTION(scope, JSC::JSValue());
scope.release();
return JSC::JSValue(result);
return JSC::JSValue(result);
}
}; // namespace Zig

View File

@@ -30,7 +30,6 @@
// return object;
// }
// static JSC::JSObject* createPrototype(JSC::VM&, JSC::JSGlobalObject&);
// static JSC::JSObject* prototype(JSC::VM&, JSC::JSGlobalObject&);
@@ -47,7 +46,7 @@
// };
// void finishCreation(JSC::VM&, JSC::JSGlobalObject*, void* zigBase);
// void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
// };
// class ModuleExportsMap final : public JSC::JSNonFinalObject {
@@ -71,7 +70,6 @@
// return object;
// }
// static JSC::JSObject* createPrototype(JSC::VM&, JSC::JSGlobalObject&);
// static JSC::JSObject* prototype(JSC::VM&, JSC::JSGlobalObject&);
@@ -88,14 +86,11 @@
// };
// void finishCreation(JSC::VM&, JSC::JSGlobalObject*, void* zigBase);
// void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
// };
// }
// namespace Zig {
// class HeadersPrototype final : public JSC::JSNonFinalObject {
@@ -126,7 +121,6 @@
// return object;
// }
// JSC::JSValue get(JSC::JSGlobalObject&, JSC::JSValue);
// bool put(JSC::JSGlobalObject&, JSC::JSValue, JSC::JSValue);
// bool has(JSC::JSGlobalObject&, JSC::JSValue);
@@ -149,9 +143,8 @@
// };
// void finishCreation(JSC::VM&, JSC::JSGlobalObject*, void* zigBase);
// void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
// };
// };
// JSC_DECLARE_HOST_FUNCTION(headersFuncPrototypeGet);
// JSC_DECLARE_HOST_FUNCTION(headersFuncPrototypePut);
@@ -185,8 +178,6 @@
// JSC_DECLARE_HOST_FUNCTION(headersFuncConstructor);
// class RequestConstructor final : public JSC::InternalFunction {
// public:
// typedef InternalFunction Base;
@@ -257,10 +248,7 @@
// };
// void finishCreation(JSC::VM&, JSC::JSGlobalObject*, void* zigBase);
// void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
// };
// }

View File

@@ -46,7 +46,6 @@
#endif
#ifdef __cplusplus
#undef new
#undef delete
@@ -60,12 +59,11 @@
Make sure this warning does not turn into an error.
*/
#if COMPILER(MSVC)
#pragma warning(disable:4206)
#pragma warning(disable : 4206)
#endif
#ifdef USE_FOUNDATION
#include <CoreFoundation/CoreFoundation.h>
#endif
#include <JavaScriptCore/Heap.h>