aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/bindings/JSMockFunction.cpp34
-rw-r--r--src/bun.js/bindings/JSSink.cpp2
-rw-r--r--src/bun.js/bindings/JSSink.h2
-rw-r--r--src/bun.js/bindings/JSSinkLookupTable.h2
-rw-r--r--src/bun.js/test/jest.zig2
5 files changed, 38 insertions, 4 deletions
diff --git a/src/bun.js/bindings/JSMockFunction.cpp b/src/bun.js/bindings/JSMockFunction.cpp
index 6aeb44ded..5607f4042 100644
--- a/src/bun.js/bindings/JSMockFunction.cpp
+++ b/src/bun.js/bindings/JSMockFunction.cpp
@@ -23,6 +23,7 @@ namespace Bun {
JSC_DECLARE_HOST_FUNCTION(jsMockFunctionCall);
JSC_DECLARE_CUSTOM_GETTER(jsMockFunctionGetter_protoImpl);
JSC_DECLARE_CUSTOM_GETTER(jsMockFunctionGetter_mock);
+JSC_DECLARE_CUSTOM_GETTER(jsMockFunctionGetter_mockGetLastCall);
JSC_DECLARE_HOST_FUNCTION(jsMockFunctionGetMockImplementation);
JSC_DECLARE_HOST_FUNCTION(jsMockFunctionGetMockName);
JSC_DECLARE_HOST_FUNCTION(jsMockFunctionMockClear);
@@ -218,6 +219,9 @@ public:
object->putDirectOffset(init.vm, 1, mock->getContexts());
object->putDirectOffset(init.vm, 2, mock->getInstances());
object->putDirectOffset(init.vm, 3, mock->getReturnValues());
+ object->putDirectCustomAccessor(init.vm, JSC::Identifier::fromString(init.vm, "lastCall"_s),
+ JSC::CustomGetterSetter::create(init.vm, jsMockFunctionGetter_mockGetLastCall, nullptr),
+ JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
init.set(object);
});
}
@@ -582,7 +586,7 @@ JSMockModule JSMockModule::create(JSC::JSGlobalObject* globalObject)
JSC::Structure* structure = globalObject->structureCache().emptyObjectStructureForPrototype(
globalObject,
globalObject->objectPrototype(),
- 4);
+ 5);
JSC::PropertyOffset offset;
structure = structure->addPropertyTransition(
init.vm,
@@ -608,6 +612,12 @@ JSMockModule JSMockModule::create(JSC::JSGlobalObject* globalObject)
JSC::Identifier::fromString(init.vm, "results"_s),
JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly,
offset);
+ structure = structure->addPropertyTransition(
+ init.vm,
+ structure,
+ JSC::Identifier::fromString(init.vm, "lastCall"_s),
+ JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Accessor,
+ offset);
init.set(structure);
});
@@ -841,6 +851,27 @@ JSC_DEFINE_CUSTOM_GETTER(jsMockFunctionGetter_protoImpl, (JSC::JSGlobalObject *
return JSValue::encode(jsUndefined());
}
+JSC_DEFINE_CUSTOM_GETTER(jsMockFunctionGetter_mockGetLastCall, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
+{
+ JSValue thisObject = JSValue::decode(thisValue);
+ auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
+ if (UNLIKELY(!thisObject.isObject())) {
+ throwTypeError(globalObject, scope, "Expected Mock"_s);
+ return {};
+ }
+ JSValue callsValue = thisObject.get(globalObject, Identifier::fromString(globalObject->vm(), "calls"_s));
+ if (UNLIKELY(!callsValue.isCell() || !callsValue.asCell()->inherits<JSArray>())) {
+ throwTypeError(globalObject, scope, "Expected Mock"_s);
+ return {};
+ }
+ JSArray *callsArray = jsCast<JSArray*>(callsValue);
+ auto len = callsArray->length();
+ if (len == 0)
+ return JSValue::encode(jsUndefined());
+
+ return JSValue::encode(callsArray->getIndex(globalObject, len - 1));
+}
+
extern "C" EncodedJSValue JSMockFunction__createObject(Zig::GlobalObject* globalObject)
{
return JSValue::encode(
@@ -858,6 +889,7 @@ extern "C" EncodedJSValue JSMockFunction__getCalls(EncodedJSValue encodedValue)
return JSValue::encode({});
}
+
extern "C" EncodedJSValue JSMockFunction__getReturns(EncodedJSValue encodedValue)
{
JSValue value = JSValue::decode(encodedValue);
diff --git a/src/bun.js/bindings/JSSink.cpp b/src/bun.js/bindings/JSSink.cpp
index 36be334dd..f0887d907 100644
--- a/src/bun.js/bindings/JSSink.cpp
+++ b/src/bun.js/bindings/JSSink.cpp
@@ -1,6 +1,6 @@
// AUTO-GENERATED FILE. DO NOT EDIT.
-// Generated by 'make generate-sink' at 2023-05-18T01:04:00.447Z
+// Generated by 'make generate-sink' at 2023-06-10T17:38:55.944Z
// To regenerate this file, run:
//
// make generate-sink
diff --git a/src/bun.js/bindings/JSSink.h b/src/bun.js/bindings/JSSink.h
index 5bbfab777..4785f637a 100644
--- a/src/bun.js/bindings/JSSink.h
+++ b/src/bun.js/bindings/JSSink.h
@@ -1,6 +1,6 @@
// AUTO-GENERATED FILE. DO NOT EDIT.
-// Generated by 'make generate-sink' at 2023-05-18T01:04:00.446Z
+// Generated by 'make generate-sink' at 2023-06-10T17:38:55.943Z
//
#pragma once
diff --git a/src/bun.js/bindings/JSSinkLookupTable.h b/src/bun.js/bindings/JSSinkLookupTable.h
index a4ace6dc3..7ff4c3f9c 100644
--- a/src/bun.js/bindings/JSSinkLookupTable.h
+++ b/src/bun.js/bindings/JSSinkLookupTable.h
@@ -1,4 +1,4 @@
-// Automatically generated from src/bun.js/bindings/JSSink.cpp using /Users/jarred/Code/bun/src/bun.js/WebKit/Source/JavaScriptCore/create_hash_table. DO NOT EDIT!
+// Automatically generated from src/bun.js/bindings/JSSink.cpp using /Users/ashcon/Desktop/code/bun/src/bun.js/WebKit/Source/JavaScriptCore/create_hash_table. DO NOT EDIT!
diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig
index 93edb8abd..b33c5131a 100644
--- a/src/bun.js/test/jest.zig
+++ b/src/bun.js/test/jest.zig
@@ -3861,6 +3861,7 @@ pub const Expect = struct {
return .zero;
};
+ JSC.markBinding(@src());
const calls = JSMockFunction__getCalls(value);
active_test_expectation_counter.actual += 1;
@@ -3911,6 +3912,7 @@ pub const Expect = struct {
active_test_expectation_counter.actual += 1;
+ JSC.markBinding(@src());
const calls = JSMockFunction__getCalls(value);
if (calls == .zero or !calls.jsType().isArray()) {