File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff 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;
You can’t perform that action at this time.
0 commit comments