mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 20:39:05 +00:00
[autofix.ci] apply automated fixes
This commit is contained in:
@@ -107,16 +107,16 @@ JSC_DEFINE_HOST_FUNCTION(callSiteProtoFuncGetTypeName, (JSGlobalObject * globalO
|
||||
{
|
||||
ENTER_PROTO_FUNC();
|
||||
JSValue thisValue = callSite->thisValue();
|
||||
|
||||
|
||||
// Return null for undefined to match V8 behavior
|
||||
if (thisValue.isUndefinedOrNull()) {
|
||||
return JSC::JSValue::encode(jsNull());
|
||||
}
|
||||
|
||||
|
||||
// For objects, try to get the constructor name or class name
|
||||
if (thisValue.isObject()) {
|
||||
JSObject* obj = asObject(thisValue);
|
||||
|
||||
|
||||
// Try to get the class name
|
||||
auto catchScope = DECLARE_CATCH_SCOPE(vm);
|
||||
String className = obj->calculatedClassName(obj);
|
||||
@@ -124,15 +124,15 @@ JSC_DEFINE_HOST_FUNCTION(callSiteProtoFuncGetTypeName, (JSGlobalObject * globalO
|
||||
catchScope.clearException();
|
||||
return JSC::JSValue::encode(jsNull());
|
||||
}
|
||||
|
||||
|
||||
if (!className.isEmpty()) {
|
||||
return JSC::JSValue::encode(jsString(vm, className));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fallback to type string
|
||||
JSString* typeString = jsTypeStringForValue(globalObject, thisValue);
|
||||
|
||||
|
||||
// Return null if the type string is "undefined"
|
||||
if (typeString) {
|
||||
String typeStr = typeString->tryGetValue();
|
||||
@@ -140,7 +140,7 @@ JSC_DEFINE_HOST_FUNCTION(callSiteProtoFuncGetTypeName, (JSGlobalObject * globalO
|
||||
return JSC::JSValue::encode(jsNull());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return JSC::JSValue::encode(typeString);
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ JSC_DEFINE_HOST_FUNCTION(callSiteProtoFuncIsAsync, (JSGlobalObject * globalObjec
|
||||
if (!functionValue.isCell()) {
|
||||
return JSC::JSValue::encode(JSC::jsBoolean(false));
|
||||
}
|
||||
|
||||
|
||||
auto* function = jsDynamicCast<JSFunction*>(functionValue);
|
||||
if (!function || function->isHostFunction()) {
|
||||
return JSC::JSValue::encode(JSC::jsBoolean(false));
|
||||
@@ -291,13 +291,10 @@ JSC_DEFINE_HOST_FUNCTION(callSiteProtoFuncIsAsync, (JSGlobalObject * globalObjec
|
||||
// Cast to FunctionExecutable to access parseMode
|
||||
if (auto* funcExecutable = jsDynamicCast<FunctionExecutable*>(executable)) {
|
||||
SourceParseMode mode = funcExecutable->parseMode();
|
||||
|
||||
|
||||
// Check if it's any kind of async function
|
||||
bool isAsync = isAsyncFunctionWrapperParseMode(mode) ||
|
||||
isAsyncGeneratorWrapperParseMode(mode) ||
|
||||
isAsyncFunctionParseMode(mode) ||
|
||||
funcExecutable->isAsyncGenerator();
|
||||
|
||||
bool isAsync = isAsyncFunctionWrapperParseMode(mode) || isAsyncGeneratorWrapperParseMode(mode) || isAsyncFunctionParseMode(mode) || funcExecutable->isAsyncGenerator();
|
||||
|
||||
if (isAsync) {
|
||||
return JSC::JSValue::encode(JSC::jsBoolean(true));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, describe } from "bun:test";
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
describe("CallSite API", () => {
|
||||
describe("getFunctionName", () => {
|
||||
@@ -11,16 +11,16 @@ describe("CallSite API", () => {
|
||||
return "";
|
||||
};
|
||||
|
||||
const anonymousFunc = function() {
|
||||
const anonymousFunc = function () {
|
||||
return new Error().stack;
|
||||
};
|
||||
|
||||
|
||||
anonymousFunc();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(0);
|
||||
const firstCallSite = callSites[0];
|
||||
|
||||
|
||||
// Should return null, not empty string
|
||||
expect(firstCallSite.getFunctionName()).toBe(null);
|
||||
});
|
||||
@@ -37,13 +37,13 @@ describe("CallSite API", () => {
|
||||
function namedFunction() {
|
||||
return new Error().stack;
|
||||
}
|
||||
|
||||
|
||||
namedFunction();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(0);
|
||||
const firstCallSite = callSites[0];
|
||||
|
||||
|
||||
expect(firstCallSite.getFunctionName()).toBe("namedFunction");
|
||||
});
|
||||
});
|
||||
@@ -59,17 +59,17 @@ describe("CallSite API", () => {
|
||||
};
|
||||
|
||||
const obj = {
|
||||
method: function() {
|
||||
method: function () {
|
||||
return new Error().stack;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
obj.method();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(0);
|
||||
const firstCallSite = callSites[0];
|
||||
|
||||
|
||||
// For now, getMethodName should return null for empty names
|
||||
const methodName = firstCallSite.getMethodName();
|
||||
expect(methodName === null || methodName === "method").toBe(true);
|
||||
@@ -87,17 +87,17 @@ describe("CallSite API", () => {
|
||||
};
|
||||
|
||||
// In strict mode, 'this' is undefined
|
||||
"use strict";
|
||||
("use strict");
|
||||
function strictFunction() {
|
||||
return new Error().stack;
|
||||
}
|
||||
|
||||
|
||||
strictFunction();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(0);
|
||||
const firstCallSite = callSites[0];
|
||||
|
||||
|
||||
// Should return null, not "undefined"
|
||||
expect(firstCallSite.getTypeName()).toBe(null);
|
||||
});
|
||||
@@ -114,15 +114,15 @@ describe("CallSite API", () => {
|
||||
const obj = {
|
||||
method() {
|
||||
return new Error().stack;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
obj.method();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(0);
|
||||
const firstCallSite = callSites[0];
|
||||
|
||||
|
||||
// Should return "Object" for plain objects
|
||||
expect(firstCallSite.getTypeName()).toBe("Object");
|
||||
});
|
||||
@@ -141,13 +141,13 @@ describe("CallSite API", () => {
|
||||
async function asyncFunc() {
|
||||
return new Error().stack;
|
||||
}
|
||||
|
||||
|
||||
await asyncFunc();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(0);
|
||||
const firstCallSite = callSites[0];
|
||||
|
||||
|
||||
// Should return true for async functions
|
||||
expect(firstCallSite.isAsync()).toBe(true);
|
||||
});
|
||||
@@ -164,13 +164,13 @@ describe("CallSite API", () => {
|
||||
function regularFunc() {
|
||||
return new Error().stack;
|
||||
}
|
||||
|
||||
|
||||
regularFunc();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(0);
|
||||
const firstCallSite = callSites[0];
|
||||
|
||||
|
||||
// Should return false for regular functions
|
||||
expect(firstCallSite.isAsync()).toBe(false);
|
||||
});
|
||||
@@ -188,7 +188,7 @@ describe("CallSite API", () => {
|
||||
new Error().stack;
|
||||
yield 1;
|
||||
}
|
||||
|
||||
|
||||
const gen = asyncGenFunc();
|
||||
await gen.next();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
@@ -220,13 +220,13 @@ describe("CallSite API", () => {
|
||||
function outerFunc() {
|
||||
return innerFunc();
|
||||
}
|
||||
|
||||
|
||||
outerFunc();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(1);
|
||||
const innerCallSite = callSites[0];
|
||||
|
||||
|
||||
// innerFunc is not top-level, it's called from outerFunc
|
||||
expect(innerCallSite.isToplevel()).toBe(false);
|
||||
});
|
||||
@@ -242,13 +242,13 @@ describe("CallSite API", () => {
|
||||
|
||||
// This runs at module level
|
||||
new Error().stack;
|
||||
|
||||
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
if (callSites.length > 0) {
|
||||
// Find the top-most frame (module level)
|
||||
const topFrame = callSites[callSites.length - 1];
|
||||
|
||||
|
||||
// Module-level code should be considered top-level
|
||||
// Though in test context this might not always be true
|
||||
expect(typeof topFrame.isToplevel()).toBe("boolean");
|
||||
@@ -267,15 +267,15 @@ describe("CallSite API", () => {
|
||||
const obj = {
|
||||
method() {
|
||||
return new Error().stack;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
obj.method();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(0);
|
||||
const firstCallSite = callSites[0];
|
||||
|
||||
|
||||
// Method calls should not be top-level
|
||||
expect(firstCallSite.isToplevel()).toBe(false);
|
||||
});
|
||||
@@ -294,19 +294,19 @@ describe("CallSite API", () => {
|
||||
function testFunc() {
|
||||
return new Error().stack;
|
||||
}
|
||||
|
||||
|
||||
testFunc();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(0);
|
||||
const firstCallSite = callSites[0];
|
||||
|
||||
|
||||
// Get original toString result
|
||||
const originalToString = firstCallSite.toString();
|
||||
|
||||
|
||||
// Try to override getFunctionName (shouldn't affect toString)
|
||||
firstCallSite.getFunctionName = () => "overridden";
|
||||
|
||||
|
||||
// toString should still return the original result
|
||||
expect(firstCallSite.toString()).toBe(originalToString);
|
||||
});
|
||||
@@ -325,13 +325,13 @@ describe("CallSite API", () => {
|
||||
function testFunc() {
|
||||
return new Error().stack;
|
||||
}
|
||||
|
||||
|
||||
testFunc();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(0);
|
||||
const cs = callSites[0];
|
||||
|
||||
|
||||
// Check that all V8 CallSite methods exist
|
||||
expect(typeof cs.getThis).toBe("function");
|
||||
expect(typeof cs.getTypeName).toBe("function");
|
||||
@@ -362,20 +362,20 @@ describe("CallSite API", () => {
|
||||
return "";
|
||||
};
|
||||
|
||||
"use strict";
|
||||
("use strict");
|
||||
function strictFunc() {
|
||||
return new Error().stack;
|
||||
}
|
||||
|
||||
|
||||
strictFunc();
|
||||
Error.prepareStackTrace = originalPrepare;
|
||||
|
||||
expect(callSites.length).toBeGreaterThan(0);
|
||||
const firstCallSite = callSites[0];
|
||||
|
||||
|
||||
// In strict mode, getThis and getFunction should return undefined
|
||||
expect(firstCallSite.getThis()).toBe(undefined);
|
||||
expect(firstCallSite.getFunction()).toBe(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user