diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-11-02 20:28:41 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-11-05 20:37:27 +0100 |
commit | a4123a86ef5e951d9f193d3ec331759b1b4fdee1 (patch) | |
tree | 7bfc18a9faf7cc14add90c27f2197f01e014f348 /test | |
parent | 7fc1d00204f33d3b1af0e865791fd4e38b1ab457 (diff) | |
download | android-node-v8-a4123a86ef5e951d9f193d3ec331759b1b4fdee1.tar.gz android-node-v8-a4123a86ef5e951d9f193d3ec331759b1b4fdee1.tar.bz2 android-node-v8-a4123a86ef5e951d9f193d3ec331759b1b4fdee1.zip |
src: make AtExit() callbacks run in reverse order
This makes the actual behaviour match the documented (and arguably
the correct) behaviour.
PR-URL: https://github.com/nodejs/node/pull/30230
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/cctest/test_environment.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/cctest/test_environment.cc b/test/cctest/test_environment.cc index aabaeb985b..4045a7d2a4 100644 --- a/test/cctest/test_environment.cc +++ b/test/cctest/test_environment.cc @@ -10,8 +10,12 @@ using node::RunAtExit; static bool called_cb_1 = false; static bool called_cb_2 = false; +static bool called_cb_ordered_1 = false; +static bool called_cb_ordered_2 = false; static void at_exit_callback1(void* arg); static void at_exit_callback2(void* arg); +static void at_exit_callback_ordered1(void* arg); +static void at_exit_callback_ordered2(void* arg); static std::string cb_1_arg; // NOLINT(runtime/string) class EnvironmentTest : public EnvironmentTestFixture { @@ -20,6 +24,8 @@ class EnvironmentTest : public EnvironmentTestFixture { NodeTestFixture::TearDown(); called_cb_1 = false; called_cb_2 = false; + called_cb_ordered_1 = false; + called_cb_ordered_2 = false; } }; @@ -61,6 +67,19 @@ TEST_F(EnvironmentTest, AtExitWithoutEnvironment) { EXPECT_TRUE(called_cb_1); } +TEST_F(EnvironmentTest, AtExitOrder) { + const v8::HandleScope handle_scope(isolate_); + const Argv argv; + Env env {handle_scope, argv}; + + // Test that callbacks are run in reverse order. + AtExit(*env, at_exit_callback_ordered1); + AtExit(*env, at_exit_callback_ordered2); + RunAtExit(*env); + EXPECT_TRUE(called_cb_ordered_1); + EXPECT_TRUE(called_cb_ordered_2); +} + TEST_F(EnvironmentTest, AtExitWithArgument) { const v8::HandleScope handle_scope(isolate_); const Argv argv; @@ -134,3 +153,13 @@ static void at_exit_callback1(void* arg) { static void at_exit_callback2(void* arg) { called_cb_2 = true; } + +static void at_exit_callback_ordered1(void* arg) { + EXPECT_TRUE(called_cb_ordered_2); + called_cb_ordered_1 = true; +} + +static void at_exit_callback_ordered2(void* arg) { + EXPECT_FALSE(called_cb_ordered_1); + called_cb_ordered_2 = true; +} |