Skip to content

Commit fc85f2d

Browse files
Added test
1 parent b8bede4 commit fc85f2d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

bin/NativeTests/JsRTApiTest.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,44 @@ namespace JsRTApiTest
142142
JsRTApiTest::RunWithAttributes(JsRTApiTest::WeakReferenceTest);
143143
}
144144

145+
TEST_CASE("ApiTest_GC_ClearStack", "[ApiTest]")
146+
{
147+
struct Helper
148+
{
149+
struct Locals {
150+
volatile uint8_t buffer[64];
151+
volatile uint8_t *p = buffer;
152+
};
153+
154+
// The stack-layout of the following two functions has to be identical
155+
156+
DECLSPEC_NOINLINE static void WritePattern(uint8_t pattern)
157+
{
158+
Locals locals = {};
159+
while (locals.p < locals.buffer + sizeof(locals.buffer))
160+
{
161+
*locals.p++ = pattern;
162+
}
163+
}
164+
165+
DECLSPEC_NOINLINE static bool VerifyPattern(uint8_t pattern)
166+
{
167+
Locals locals; // Value of whatever is on the stack right now
168+
while (locals.p < locals.buffer + sizeof(locals.buffer))
169+
{
170+
if (*locals.p++ != pattern)
171+
return false;
172+
}
173+
return true;
174+
}
175+
};
176+
177+
Helper::WritePattern(0x42);
178+
REQUIRE(Helper::VerifyPattern(0x42) == true);
179+
REQUIRE(JsGarbageCollectionClearStack() == JsNoError);
180+
REQUIRE(Helper::VerifyPattern(0x00) == true);
181+
}
182+
145183
void ObjectsAndPropertiesTest1(JsRuntimeAttributes attributes, JsRuntimeHandle runtime)
146184
{
147185
JsValueRef object = JS_INVALID_REFERENCE;

0 commit comments

Comments
 (0)