aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/JSMockFunction.cpp
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-06-26 22:27:12 -0400
committerGravatar GitHub <noreply@github.com> 2023-06-26 19:27:12 -0700
commitecb0bd39b6f7a0a69f0b92ddedc0af5d0e88e945 (patch)
treef478ff1a29c1fd9dc022d440142d368a438aac5e /src/bun.js/bindings/JSMockFunction.cpp
parent4e4cae0fc308c448fb73d59228fb30bd994453ed (diff)
downloadbun-ecb0bd39b6f7a0a69f0b92ddedc0af5d0e88e945.tar.gz
bun-ecb0bd39b6f7a0a69f0b92ddedc0af5d0e88e945.tar.zst
bun-ecb0bd39b6f7a0a69f0b92ddedc0af5d0e88e945.zip
fix #3412 (#3422)
Diffstat (limited to 'src/bun.js/bindings/JSMockFunction.cpp')
-rw-r--r--src/bun.js/bindings/JSMockFunction.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/bun.js/bindings/JSMockFunction.cpp b/src/bun.js/bindings/JSMockFunction.cpp
index fbfcf0c9e..33922c2b7 100644
--- a/src/bun.js/bindings/JSMockFunction.cpp
+++ b/src/bun.js/bindings/JSMockFunction.cpp
@@ -569,15 +569,19 @@ extern "C" EncodedJSValue JSMock__jsSpyOn(JSC::JSGlobalObject* lexicalGlobalObje
// easymode: regular property or missing property
if (!hasValue || slot.isValue()) {
+ JSValue value = jsUndefined();
+ if (hasValue) {
+ value = slot.getValue(globalObject, propertyKey);
+ if (jsDynamicCast<JSMockFunction*>(value)) {
+ return JSValue::encode(value);
+ }
+ }
+
auto* mock = JSMockFunction::create(vm, globalObject, globalObject->mockModule.mockFunctionStructure.getInitializedOnMainThread(globalObject), CallbackKind::GetterSetter);
mock->spyTarget = JSC::Weak<JSObject>(object, &weakValueHandleOwner(), nullptr);
mock->spyIdentifier = propertyKey.isSymbol() ? Identifier::fromUid(vm, propertyKey.uid()) : Identifier::fromString(vm, propertyKey.publicName());
mock->spyAttributes = hasValue ? slot.attributes() : 0;
unsigned attributes = 0;
- JSValue value = jsUndefined();
-
- if (hasValue)
- value = slot.getValue(globalObject, propertyKey);
if (hasValue && ((slot.attributes() & PropertyAttribute::Function) != 0 || (value.isCell() && value.isCallable()))) {
if (hasValue)