diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 67bcb8c794..eb9e48ec3d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -222,6 +222,9 @@ $ git -C vendor/WebKit checkout # Optionally, you can use `make jsc` for a release build $ make jsc-debug && rm vendor/WebKit/WebKitBuild/Debug/JavaScriptCore/DerivedSources/inspector/InspectorProtocolObjects.h +# After an initial run of `make jsc-debug`, you can rebuild JSC with: +$ cmake --build vendor/WebKit/WebKitBuild/Debug --target jsc && rm vendor/WebKit/WebKitBuild/Debug/JavaScriptCore/DerivedSources/inspector/InspectorProtocolObjects.h + # Build bun with the local JSC build $ bun run build:local ``` diff --git a/Makefile b/Makefile index 99040c82e9..408c2af3ee 100644 --- a/Makefile +++ b/Makefile @@ -1392,7 +1392,7 @@ jsc-build-linux-compile-build-debug: cmake --build $(WEBKIT_DEBUG_DIR) --config Debug --target jsc -jsc-build-mac: jsc-force-fastjit jsc-build-mac-compile jsc-build-copy +jsc-build-mac: jsc-force-fastjit jsc-build-mac-compile jsc-build-mac-debug: jsc-force-fastjit jsc-build-mac-compile-debug jsc-build-linux: jsc-build-linux-compile-config jsc-build-linux-compile-build jsc-build-copy diff --git a/cmake/tools/SetupWebKit.cmake b/cmake/tools/SetupWebKit.cmake index bdae252939..123b78a762 100644 --- a/cmake/tools/SetupWebKit.cmake +++ b/cmake/tools/SetupWebKit.cmake @@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use") option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading") if(NOT WEBKIT_VERSION) - set(WEBKIT_VERSION 06820714a7990ea77c78157f9eeaabaf56c2098a) + set(WEBKIT_VERSION 74f9b63795643765f601068191c3f9ae4596976b) endif() string(SUBSTRING ${WEBKIT_VERSION} 0 16 WEBKIT_VERSION_PREFIX) diff --git a/src/bun.js/bindings/ErrorCode.cpp b/src/bun.js/bindings/ErrorCode.cpp index 1b40ed8972..2f9d05d876 100644 --- a/src/bun.js/bindings/ErrorCode.cpp +++ b/src/bun.js/bindings/ErrorCode.cpp @@ -907,7 +907,7 @@ JSC::EncodedJSValue INVALID_ARG_VALUE(JSC::ThrowScope& throwScope, JSC::JSGlobal { WTF::StringBuilder builder; builder.append("The "_s); - if (WTF::StringView(name).contains('.')) { + if (WTF::find(name.span(), '.') != WTF::notFound) { builder.append("property '"_s); } else { builder.append("argument '"_s); @@ -935,7 +935,7 @@ JSC::EncodedJSValue INVALID_ARG_VALUE(JSC::ThrowScope& throwScope, JSC::JSGlobal { WTF::StringBuilder builder; builder.append("The "_s); - if (WTF::StringView(name).contains('.')) { + if (WTF::find(name.span(), '.') != WTF::notFound) { builder.append("property '"_s); } else { builder.append("argument '"_s); diff --git a/src/bun.js/bindings/ErrorStackTrace.cpp b/src/bun.js/bindings/ErrorStackTrace.cpp index ef09b69384..674ad768fc 100644 --- a/src/bun.js/bindings/ErrorStackTrace.cpp +++ b/src/bun.js/bindings/ErrorStackTrace.cpp @@ -122,11 +122,10 @@ void JSCStackTrace::getFramesForCaller(JSC::VM& vm, JSC::CallFrame* callFrame, J WTF::String callerName {}; if (JSC::JSFunction* callerFunction = JSC::jsDynamicCast(caller)) { callerName = callerFunction->name(vm); - if (callerName.isEmpty() && callerFunction->jsExecutable()) { + if (callerName.isEmpty() && !callerFunction->isHostFunction() && callerFunction->jsExecutable()) { callerName = callerFunction->jsExecutable()->name().string(); } - } - if (JSC::InternalFunction* callerFunctionInternal = JSC::jsDynamicCast(caller)) { + } else if (JSC::InternalFunction* callerFunctionInternal = JSC::jsDynamicCast(caller)) { callerName = callerFunctionInternal->name(); } @@ -255,116 +254,6 @@ void JSCStackTrace::getFramesForCaller(JSC::VM& vm, JSC::CallFrame* callFrame, J }); } -JSCStackTrace JSCStackTrace::captureCurrentJSStackTrace(Zig::GlobalObject* globalObject, JSC::CallFrame* callFrame, size_t frameLimit, JSC::JSValue caller) -{ - auto& vm = JSC::getVM(globalObject); - if (!callFrame) { - return JSCStackTrace(); - } - - WTF::Vector stackFrames; - size_t framesCount = 0; - - bool belowCaller = false; - int32_t skipFrames = 0; - - WTF::String callerName {}; - if (JSC::JSFunction* callerFunction = JSC::jsDynamicCast(caller)) { - callerName = callerFunction->name(vm); - if (!callerFunction->name(vm).isEmpty() || callerFunction->isHostOrBuiltinFunction()) { - callerName = callerFunction->name(vm); - } else { - callerName = callerFunction->jsExecutable()->name().string(); - } - } - if (JSC::InternalFunction* callerFunctionInternal = JSC::jsDynamicCast(caller)) { - callerName = callerFunctionInternal->name(); - } - - if (!callerName.isEmpty()) { - JSC::StackVisitor::visit(callFrame, vm, [&](JSC::StackVisitor& visitor) -> WTF::IterationStatus { - if (isImplementationVisibilityPrivate(visitor)) { - return WTF::IterationStatus::Continue; - } - - framesCount += 1; - - // skip caller frame and all frames above it - if (!belowCaller) { - skipFrames += 1; - - if (visitor->functionName() == callerName) { - belowCaller = true; - return WTF::IterationStatus::Continue; - } - } - - return WTF::IterationStatus::Continue; - }); - } else if (caller && caller.isCell()) { - JSC::StackVisitor::visit(callFrame, vm, [&](JSC::StackVisitor& visitor) -> WTF::IterationStatus { - if (isImplementationVisibilityPrivate(visitor)) { - return WTF::IterationStatus::Continue; - } - - framesCount += 1; - - // skip caller frame and all frames above it - if (!belowCaller) { - auto callee = visitor->callee(); - skipFrames += 1; - if (callee.isCell() && callee.asCell() == caller) { - belowCaller = true; - return WTF::IterationStatus::Continue; - } - } - - return WTF::IterationStatus::Continue; - }); - } else if (caller.isEmpty() || caller.isUndefined()) { - // Skip the first frame. - JSC::StackVisitor::visit(callFrame, vm, [&](JSC::StackVisitor& visitor) -> WTF::IterationStatus { - if (isImplementationVisibilityPrivate(visitor)) { - return WTF::IterationStatus::Continue; - } - - framesCount += 1; - - if (!belowCaller) { - skipFrames += 1; - belowCaller = true; - } - - return WTF::IterationStatus::Continue; - }); - } - - framesCount = std::min(frameLimit, framesCount); - - // Create the actual stack frames - size_t i = 0; - stackFrames.reserveInitialCapacity(framesCount); - JSC::StackVisitor::visit(callFrame, vm, [&](JSC::StackVisitor& visitor) -> WTF::IterationStatus { - // Skip native frames - if (isImplementationVisibilityPrivate(visitor)) { - return WTF::IterationStatus::Continue; - } - - // Skip frames if needed - if (skipFrames > 0) { - skipFrames--; - return WTF::IterationStatus::Continue; - } - - stackFrames.constructAndAppend(vm, visitor); - i++; - - return (i == framesCount) ? WTF::IterationStatus::Done : WTF::IterationStatus::Continue; - }); - - return JSCStackTrace(stackFrames); -} - JSCStackTrace JSCStackTrace::getStackTraceForThrownValue(JSC::VM& vm, JSC::JSValue thrownValue) { const WTF::Vector* jscStackTrace = nullptr; @@ -752,6 +641,25 @@ String functionName(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, JSC:: } } + { + if (functionName.isEmpty()) { + if (jstype == JSC::JSFunctionType) { + auto* function = jsCast(object); + if (function) { + functionName = function->nameWithoutGC(vm); + if (functionName.isEmpty() && !function->isHostFunction()) { + functionName = function->jsExecutable()->ecmaName().string(); + } + } + } else if (jstype == JSC::InternalFunctionType) { + auto* function = jsCast(object); + if (function) { + functionName = function->name(); + } + } + } + } + return functionName; } @@ -813,14 +721,17 @@ String functionName(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, const // Lastly, try type-specific properties. if (jstype == JSC::JSFunctionType) { - auto* function = jsDynamicCast(object); + auto* function = jsCast(object); if (function) { functionName = function->nameWithoutGC(vm); + if (functionName.isEmpty() && !function->isHostFunction()) { + functionName = function->jsExecutable()->ecmaName().string(); + } setTypeFlagsIfNecessary(); return functionName; } } else if (jstype == JSC::InternalFunctionType) { - auto* function = jsDynamicCast(object); + auto* function = jsCast(object); if (function) { functionName = function->name(); setTypeFlagsIfNecessary(); diff --git a/src/bun.js/bindings/ErrorStackTrace.h b/src/bun.js/bindings/ErrorStackTrace.h index e34e8daea5..617e416b71 100644 --- a/src/bun.js/bindings/ErrorStackTrace.h +++ b/src/bun.js/bindings/ErrorStackTrace.h @@ -179,15 +179,6 @@ public: static JSCStackTrace fromExisting(JSC::VM& vm, const WTF::Vector& existingFrames); - /* This is based on JSC::Interpreter::getStackTrace, but skips native (non js and not wasm) - * frames, which is what v8 does. Note that we could have just called JSC::Interpreter::getStackTrace - * and and filter it later (or let our callers filter it), but that would have been both inefficient, and - * problematic with the requested stack size limit (as it should only refer to the non-native frames, - * thus we would have needed to pass a large limit to JSC::Interpreter::getStackTrace, and filter out - * maxStackSize non-native frames). - * - * Return value must remain stack allocated. */ - static JSCStackTrace captureCurrentJSStackTrace(Zig::GlobalObject* globalObject, JSC::CallFrame* callFrame, size_t frameLimit, JSC::JSValue caller); static void getFramesForCaller(JSC::VM& vm, JSC::CallFrame* callFrame, JSC::JSCell* owner, JSC::JSValue caller, WTF::Vector& stackTrace, size_t stackTraceLimit); /* In JSC, JSC::Exception points to the actual value that was thrown, usually diff --git a/src/bun.js/bindings/NodeValidator.cpp b/src/bun.js/bindings/NodeValidator.cpp index 15dab6aa44..f141ec5744 100644 --- a/src/bun.js/bindings/NodeValidator.cpp +++ b/src/bun.js/bindings/NodeValidator.cpp @@ -659,7 +659,7 @@ JSC::EncodedJSValue V::validateOneOf(JSC::ThrowScope& scope, JSC::JSGlobalObject JSC::JSString* valueStr = value.toString(globalObject); RETURN_IF_EXCEPTION(scope, JSValue::encode({})); - WTF::StringView valueView = valueStr->view(globalObject); + auto valueView = valueStr->view(globalObject); for (ASCIILiteral oneOfStr : oneOf) { diff --git a/src/bun.js/bindings/node/crypto/JSHash.cpp b/src/bun.js/bindings/node/crypto/JSHash.cpp index 2227ed3577..cbc4ccc623 100644 --- a/src/bun.js/bindings/node/crypto/JSHash.cpp +++ b/src/bun.js/bindings/node/crypto/JSHash.cpp @@ -171,7 +171,7 @@ JSC_DEFINE_HOST_FUNCTION(jsHashProtoFuncUpdate, (JSC::JSGlobalObject * globalObj return Bun::ERR::INVALID_ARG_VALUE(scope, globalObject, "encoding"_s, encodingValue, makeString("is invalid for data of length "_s, inputString->length())); } - WTF::StringView inputView = inputString->view(globalObject); + auto inputView = inputString->view(globalObject); RETURN_IF_EXCEPTION(scope, {}); JSValue converted = JSValue::decode(WebCore::constructFromEncoding(globalObject, inputView, encoding)); diff --git a/src/bun.js/bindings/node/crypto/JSHmac.cpp b/src/bun.js/bindings/node/crypto/JSHmac.cpp index a49827acc4..8d6a6b5773 100644 --- a/src/bun.js/bindings/node/crypto/JSHmac.cpp +++ b/src/bun.js/bindings/node/crypto/JSHmac.cpp @@ -140,7 +140,7 @@ JSC_DEFINE_HOST_FUNCTION(jsHmacProtoFuncUpdate, (JSC::JSGlobalObject * globalObj return Bun::ERR::INVALID_ARG_VALUE(scope, globalObject, "encoding"_s, encodingValue, makeString("is invalid for data of length "_s, inputString->length())); } - WTF::StringView inputView = inputString->view(globalObject); + auto inputView = inputString->view(globalObject); RETURN_IF_EXCEPTION(scope, {}); JSValue converted = JSValue::decode(WebCore::constructFromEncoding(globalObject, inputView, encoding)); diff --git a/src/bun.js/bindings/webcore/DOMJITIDLConvert.h b/src/bun.js/bindings/webcore/DOMJITIDLConvert.h index fbc95f7ebb..b5cd6001bd 100644 --- a/src/bun.js/bindings/webcore/DOMJITIDLConvert.h +++ b/src/bun.js/bindings/webcore/DOMJITIDLConvert.h @@ -45,7 +45,7 @@ template<> struct DirectConverter> { static AtomString directConvert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSString* string) { - return string->toAtomString(&lexicalGlobalObject); + return string->toAtomString(&lexicalGlobalObject).data; } }; @@ -53,7 +53,7 @@ template<> struct DirectConverter> { static AtomString directConvert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSString* string) { - return string->toExistingAtomString(&lexicalGlobalObject); + return string->toExistingAtomString(&lexicalGlobalObject).data; } }; diff --git a/src/bun.js/bindings/webcore/JSDOMConvertStrings.cpp b/src/bun.js/bindings/webcore/JSDOMConvertStrings.cpp index 53003fa258..a9f1035700 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertStrings.cpp +++ b/src/bun.js/bindings/webcore/JSDOMConvertStrings.cpp @@ -81,7 +81,7 @@ AtomString valueToByteAtomString(JSC::JSGlobalObject& lexicalGlobalObject, JSC:: VM& vm = lexicalGlobalObject.vm(); auto scope = DECLARE_THROW_SCOPE(vm); - auto string = value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject); + AtomString string = value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject).data; RETURN_IF_EXCEPTION(scope, {}); if (UNLIKELY(throwIfInvalidByteString(lexicalGlobalObject, scope, string.string()))) @@ -114,7 +114,7 @@ AtomString valueToUSVAtomString(JSGlobalObject& lexicalGlobalObject, JSValue val auto string = value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject); RETURN_IF_EXCEPTION(scope, {}); - return replaceUnpairedSurrogatesWithReplacementCharacter(WTFMove(string)); + return replaceUnpairedSurrogatesWithReplacementCharacter(AtomString(string)); } } // namespace WebCore diff --git a/src/bun.js/bindings/webcore/JSDOMConvertStrings.h b/src/bun.js/bindings/webcore/JSDOMConvertStrings.h index 450caf7e9c..38fc9eccac 100644 --- a/src/bun.js/bindings/webcore/JSDOMConvertStrings.h +++ b/src/bun.js/bindings/webcore/JSDOMConvertStrings.h @@ -194,7 +194,7 @@ template struct Converter> : DefaultConverte { static_assert(std::is_same::value, "This adaptor is only supported for IDLDOMString at the moment."); - return value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject); + return value.toString(&lexicalGlobalObject)->toAtomString(&lexicalGlobalObject).data; } }; @@ -267,7 +267,7 @@ template struct Converter> : { static_assert(std::is_same::value, "This adaptor is only supported for IDLDOMString at the moment."); - return value.toString(&lexicalGlobalObject)->toExistingAtomString(&lexicalGlobalObject); + return value.toString(&lexicalGlobalObject)->toExistingAtomString(&lexicalGlobalObject).data; } }; @@ -283,4 +283,4 @@ template struct JSConverter> } }; -} // namespace WebCore \ No newline at end of file +} // namespace WebCore diff --git a/test/js/bun/util/reportError.test.ts b/test/js/bun/util/reportError.test.ts index d2849fe901..7ec0f8d7ac 100644 --- a/test/js/bun/util/reportError.test.ts +++ b/test/js/bun/util/reportError.test.ts @@ -24,6 +24,7 @@ test("reportError", () => { ^ error: reportError Test! at [file]:1:13 + at loadAndEvaluateModule (2:1) error: true true error: false diff --git a/test/js/web/console/console-log.test.ts b/test/js/web/console/console-log.test.ts index 17cb8994cd..66fbc24373 100644 --- a/test/js/web/console/console-log.test.ts +++ b/test/js/web/console/console-log.test.ts @@ -119,6 +119,7 @@ Quote"Backslash "Warning log warn: console.warn an error at :56:14 + at loadAndEvaluateModule (2:1) 52 | console.group("Different logs"); 53 | console.log("Regular log"); @@ -129,6 +130,7 @@ Quote"Backslash ^ error: console.error an error at :57:15 + at loadAndEvaluateModule (2:1) 41 | console.groupEnd(); // Extra 42 | console.groupEnd(); // Extra @@ -140,10 +142,12 @@ error: console.error an error NamedError: console.error a named error at new NamedError (:46:5) at :58:15 + at loadAndEvaluateModule (2:1) NamedError: console.warn a named error at new NamedError (:46:5) at :59:14 + at loadAndEvaluateModule (2:1) Error log" `);