test: remove AtExit() addon test

Move the one bit of the addon test that was not covered by the
cctest into the latter and delete the former.

Refs: https://github.com/nodejs/node/pull/30227#discussion_r341879242

PR-URL: https://github.com/nodejs/node/pull/30275
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Anna Henningsen authored and Myles Borins committed 2019-11-16 23:59:11 -08:00
1 parent b744070d74
commit ab5bca379f
4 files changed
+22 -71

No files matched your search

-59
View File
@@ -1,59 +0,0 @@
#include <assert.h>
#include <stdlib.h>
#include <node.h>
#include <v8.h>
// TODO(addaleax): Maybe merge this file with the cctest for AtExit()?
using node::AtExit;
using node::Environment;
using node::GetCurrentEnvironment;
using v8::HandleScope;
using v8::Isolate;
using v8::Local;
using v8::Object;
#if defined(_MSC_VER)
#pragma section(".CRT$XPU", read)
#define NODE_C_DTOR(fn) \
NODE_CTOR_PREFIX void __cdecl fn(void); \
__declspec(dllexport, allocate(".CRT$XPU")) \
void (__cdecl*fn ## _)(void) = fn; \
NODE_CTOR_PREFIX void __cdecl fn(void)
#else
#define NODE_C_DTOR(fn) \
NODE_CTOR_PREFIX void fn(void) __attribute__((destructor)); \
NODE_CTOR_PREFIX void fn(void)
#endif
static char cookie[] = "yum yum";
static int at_exit_cb1_called = 0;
static int at_exit_cb2_called = 0;
static void at_exit_cb1(void* arg) {
Isolate* isolate = static_cast<Isolate*>(arg);
HandleScope handle_scope(isolate);
Local<Object> obj = Object::New(isolate);
assert(!obj.IsEmpty()); // Assert VM is still alive.
assert(obj->IsObject());
at_exit_cb1_called++;
}
static void at_exit_cb2(void* arg) {
assert(arg == static_cast<void*>(cookie));
at_exit_cb2_called++;
}
NODE_C_DTOR(sanity_check) {
assert(at_exit_cb1_called == 1);
assert(at_exit_cb2_called == 2);
}
void init(Local<Object> exports) {
Environment* env = GetCurrentEnvironment(exports->CreationContext());
AtExit(env, at_exit_cb1, exports->GetIsolate());
AtExit(env, at_exit_cb2, cookie);
AtExit(env, at_exit_cb2, cookie);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, init)
-9
View File
@@ -1,9 +0,0 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ],
'includes': ['../common.gypi'],
}
]
}
-3
View File
@@ -1,3 +0,0 @@
'use strict';
const common = require('../../common');
require(`./build/${common.buildType}/binding`);
+22
View File
@@ -12,10 +12,12 @@ 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 bool called_at_exit_js = 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 void at_exit_js(void* arg);
static std::string cb_1_arg; // NOLINT(runtime/string)
class EnvironmentTest : public EnvironmentTestFixture {
@@ -91,6 +93,17 @@ TEST_F(EnvironmentTest, AtExitWithArgument) {
EXPECT_EQ(arg, cb_1_arg);
}
TEST_F(EnvironmentTest, AtExitRunsJS) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env {handle_scope, argv};
AtExit(*env, at_exit_js, static_cast<void*>(isolate_));
EXPECT_FALSE(called_at_exit_js);
RunAtExit(*env);
EXPECT_TRUE(called_at_exit_js);
}
TEST_F(EnvironmentTest, MultipleEnvironmentsPerIsolate) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
@@ -163,3 +176,12 @@ static void at_exit_callback_ordered2(void* arg) {
EXPECT_FALSE(called_cb_ordered_1);
called_cb_ordered_2 = true;
}
static void at_exit_js(void* arg) {
v8::Isolate* isolate = static_cast<v8::Isolate*>(arg);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Object> obj = v8::Object::New(isolate);
assert(!obj.IsEmpty()); // Assert VM is still alive.
assert(obj->IsObject());
called_at_exit_js = true;
}