#!/bin/bash

cat > test.js << EOF
var task = new Task();
task.activate();
task.execute({name: "child.js", source: utf8Decode(File.readFile("child.js"))}).then(function() {
	task.getExports().then(function(exp) {
		return exp.add(1, 1);
	}).then(function(sum) {
		exit(1);
	}).catch(function(error) {
		print("Caught: " + error.message);
		if (error.stack) {
			print("stack: " + error.stack);
		}
		exit(0);
	});
}).catch(function(e) {
	print("caught", e.message);
});
EOF

cat > child.js << EOF
exports = {
	add: function(left, right) {
		throw new Error("fail");
	}
};
EOF

$TILDEFRIENDS test.js