From 313efbe2d68cf00a0c0ad88fa4fe772792a2b0e0 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 31 Jul 2016 15:07:08 +0000 Subject: [PATCH] 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 --- src/Task.cpp | 4 +++- tests/11-require | 28 ++++++++++++++++++++++++++++ tests/12-exit | 10 ++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/11-require create mode 100644 tests/12-exit diff --git a/src/Task.cpp b/src/Task.cpp index 208e09de..d994681b 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -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; diff --git a/tests/11-require b/tests/11-require new file mode 100644 index 00000000..dbeb2dde --- /dev/null +++ b/tests/11-require @@ -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 diff --git a/tests/12-exit b/tests/12-exit new file mode 100644 index 00000000..7b9fdbb1 --- /dev/null +++ b/tests/12-exit @@ -0,0 +1,10 @@ +#!/bin/bash + +cat > blah.js << EOF +EOF + +cat > test.js << EOF +require("blah"); +EOF + +$TILDEFRIENDS test.js