#include "root.h" #include "JavaScriptCore/ArgList.h" #include "headers.h" #include "ConsoleObject.h" #include #include #include #include #include #include #include #include #include "GCDefferalContext.h" #include #include #include namespace Bun { using namespace JSC; using namespace Inspector; using ScriptArguments = Inspector::ScriptArguments; using MessageType = JSC::MessageType; using MessageLevel = JSC::MessageLevel; using JSGlobalObject = JSC::JSGlobalObject; using String = WTF::String; void ConsoleObject::messageWithTypeAndLevel(MessageType type, MessageLevel level, JSC::JSGlobalObject* globalObject, Ref&& arguments) { if (globalObject->inspectable()) { if (auto client = globalObject->inspectorController().consoleClient()) { client->messageWithTypeAndLevel(type, level, globalObject, arguments.copyRef()); } } auto& vm = JSC::getVM(globalObject); auto args = arguments.ptr(); JSC::EncodedJSValue jsArgs[255]; auto count = std::min(args->argumentCount(), (size_t)255); for (size_t i = 0; i < count; i++) { auto val = args->argumentAt(i); jsArgs[i] = JSC::JSValue::encode(val); } if (type == MessageType::Table && count >= 2 && !args->argumentAt(1).isUndefined() && (!args->argumentAt(1).isCell() || args->argumentAt(1).asCell()->type() != JSC::JSType::ArrayType)) [[unlikely]] { auto scope = DECLARE_THROW_SCOPE(vm); JSC::throwTypeError(globalObject, scope, "The \"properties\" argument must be an instance of Array."_s); return; } Bun__ConsoleObject__messageWithTypeAndLevel(this->m_client, static_cast(type), static_cast(level), globalObject, jsArgs, count); } void ConsoleObject::count(JSGlobalObject* globalObject, const String& label) { auto input = label.tryGetUTF8().value(); Bun__ConsoleObject__count(this->m_client, globalObject, reinterpret_cast(input.data()), input.length()); } void ConsoleObject::countReset(JSGlobalObject* globalObject, const String& label) { auto input = label.tryGetUTF8().value(); Bun__ConsoleObject__countReset(this->m_client, globalObject, reinterpret_cast(input.data()), input.length()); } void ConsoleObject::takeHeapSnapshot(JSC::JSGlobalObject* globalObject, const String& label) { auto input = label.tryGetUTF8().value(); Bun__ConsoleObject__takeHeapSnapshot(this->m_client, globalObject, reinterpret_cast(input.data()), input.length()); } void ConsoleObject::time(JSGlobalObject* globalObject, const String& label) { auto input = label.tryGetUTF8().value(); Bun__ConsoleObject__time(this->m_client, globalObject, reinterpret_cast(input.data()), input.length()); } void ConsoleObject::timeLog(JSGlobalObject* globalObject, const String& label, Ref&& arguments) { auto input = label.tryGetUTF8().value(); auto args = arguments.ptr(); JSC::EncodedJSValue jsArgs[255]; auto count = std::min(args->argumentCount(), (size_t)255); for (size_t i = 0; i < count; i++) { auto val = args->argumentAt(i); jsArgs[i] = JSC::JSValue::encode(val); } Bun__ConsoleObject__timeLog(this->m_client, globalObject, reinterpret_cast(input.data()), input.length(), jsArgs, count); } void ConsoleObject::timeEnd(JSGlobalObject* globalObject, const String& label) { auto input = label.tryGetUTF8().value(); Bun__ConsoleObject__timeEnd(this->m_client, globalObject, reinterpret_cast(input.data()), input.length()); } void ConsoleObject::timeStamp(JSGlobalObject* globalObject, Ref&& args) { Bun__ConsoleObject__timeStamp(this->m_client, globalObject, args.ptr()); } void ConsoleObject::record(JSGlobalObject*, Ref&&) {} void ConsoleObject::recordEnd(JSGlobalObject*, Ref&&) {} void ConsoleObject::screenshot(JSGlobalObject*, Ref&&) { } void ConsoleObject::warnUnimplemented(const String& method) {} void ConsoleObject::profile(JSC::JSGlobalObject* globalObject, const String& title) { if (globalObject->inspectable()) { if (auto client = globalObject->inspectorController().consoleClient()) { client->profile(globalObject, title); } } } void ConsoleObject::profileEnd(JSC::JSGlobalObject* globalObject, const String& title) { if (globalObject->inspectable()) { if (auto client = globalObject->inspectorController().consoleClient()) { client->profileEnd(globalObject, title); } } } }