Fixed a segfault I noticed related to require and shutdown.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3292 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2016-07-31 15:07:08 +00:00
parent 085b44752a
commit 313efbe2d6
3 changed files with 41 additions and 1 deletions

View File

@ -106,6 +106,7 @@ Task::Task() {
Task::~Task() {
_exportObject.Reset();
_sourceObject.Reset();
_scriptExports.clear();
{
v8::Isolate::Scope isolateScope(_isolate);
@ -286,7 +287,7 @@ bool Task::execute(const char* fileName) {
if (position != std::string::npos) {
path.resize(position + 1);
} else {
path = ".";
path = "./";
}
_path.push_back(path);
}
@ -721,6 +722,7 @@ std::string Task::resolveRequire(const std::string& require) {
if (test.size() && (require.size() < 3 || require.rfind(".js") != require.size() - 3)) {
test += ".js";
}
std::cout << "Testing " << test << "\n";
uv_fs_t request;
if (uv_fs_access(_loop, &request, test.c_str(), R_OK, 0) == 0) {
result = test;

28
tests/11-require Normal file
View File

@ -0,0 +1,28 @@
#!/bin/bash
cat > required.js << EOF
function foo() {
return 12345;
}
exports.foo = foo;
EOF
cat > test.js << EOF
if (require("required").foo() != 12345) {
exit(1);
}
var gotError = false;
try {
require("missing");
} catch (error) {
print("nope");
gotError = true;
}
if (!gotError) {
exit(2);
}
exit(0);
EOF
$TILDEFRIENDS test.js

10
tests/12-exit Normal file
View File

@ -0,0 +1,10 @@
#!/bin/bash
cat > blah.js << EOF
EOF
cat > test.js << EOF
require("blah");
EOF
$TILDEFRIENDS test.js