Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ node_modules
build/*
npm-debug.log

src/colony/modules/events.js
src/colony/modules/domain.js

out
gyp

Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ else
ninja -C out/$(CONFIG)
endif

NODE_FILES = deps/node-libs/events.js deps/node-libs/domain.js

.PHONY: all test test-colony test-node

all: colony
Expand All @@ -31,7 +29,6 @@ nuke:

update:
git submodule update --init --recursive
cp $(NODE_FILES) src/colony/modules/
npm install

test: test-node test-colony
Expand Down
3 changes: 2 additions & 1 deletion libcolony.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
'src/colony/modules/crypto.js',
'src/colony/modules/dgram.js',
'src/colony/modules/dns.js',
'src/colony/modules/events.js',
'deps/node-libs/domain.js',
'deps/node-libs/events.js',
'src/colony/modules/fs.js',
'src/colony/modules/http.js',
'src/colony/modules/https.js',
Expand Down
22 changes: 17 additions & 5 deletions src/colony/lua/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ local colony = require('colony')

-- This is temporary until we can add files to builtin array easily.
if _tessel_lib then
colony.precache['tessel'] = _tessel_lib
colony.run('tessel')
colony.precache['tessel'] = _tessel_lib
colony.run('tessel')
end

-- also temporary.
if _wifi_cc3000_lib then
colony.precache['wifi-cc3000'] = _wifi_cc3000_lib
colony.run('wifi-cc3000')
colony.precache['wifi-cc3000'] = _wifi_cc3000_lib
colony.run('wifi-cc3000')
end

-- Command line invocation
Expand All @@ -37,5 +37,17 @@ if string.sub(p, 1, 1) ~= '.' then
end

colony.global:setImmediate(function ()
colony.run(p)
-- TODO move uncaughtException handling to an appropriate file
local status, err = pcall(function ()
colony.run(p)
end)
if not status then
if colony.global.process.domain then
colony.global.process.domain:emit('error', err)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If process.domain is set, don't fire an uncaughtException.

elseif colony.global.process:listeners('uncaughtException').length then
colony.global.process:emit('uncaughtException', err)
else
error(err)
end
end
end)
37 changes: 37 additions & 0 deletions src/colony/lua/colony-js.lua
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,43 @@ arr_proto.indexOf = function (this, searchElement, fromIndex)
return -1
end

arr_proto.lastIndexOf = function (this, searchElement, fromIndex)
local len = this.length
local start

if len == 0 then
return -1
end

if fromIndex ~= nil then
fromIndex = tonumber(fromIndex)
else
fromIndex = len
end

if fromIndex >= 0 then
start = fromIndex
else
start = len + fromIndex

if start < 0 then
start = 0
end
end

if start >= len then
start = len - 1
end

for i=start,0,-1 do
if this[i] == searchElement then
return i
end
end

return -1
end

arr_proto.map = function (this, fn, ...)
local a = js_arr({}, 0)
local args = table.pack(...)
Expand Down
4 changes: 4 additions & 0 deletions src/colony/lua/preload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ do
global.process.cwd = function ()
return tm.cwd()
end
global.process._usingDomains = function ()
-- process._usingDomains called by domain.js in Node
-- here it's a no-op
end
global.process.hrtime = function (this, prev)
-- This number exceeds the 53-bit limit on integer representation, but with
-- microsecond resolution, there are only ~50 bits of actual data
Expand Down
11 changes: 10 additions & 1 deletion test/suite/array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var tap = require('../tap');

tap.count(50);
tap.count(56);

function arreq (a, b) {
if (a.length != b.length) {
Expand Down Expand Up @@ -178,3 +178,12 @@ arr.sort(function (a, b) {
});

tap.eq(arr.join(','), '-11,-6,2,10');

// lastIndexOf
var array = [2, 5, 9, 2];
tap.eq(array.lastIndexOf(2), 3, 'lastIndexOf')
tap.eq(array.lastIndexOf(7), -1, 'lastIndexOf')
tap.eq(array.lastIndexOf(2, 3), 3, 'lastIndexOf')
tap.eq(array.lastIndexOf(2, 2), 0, 'lastIndexOf')
tap.eq(array.lastIndexOf(2, -2), 0, 'lastIndexOf')
tap.eq(array.lastIndexOf(2, -1), 3, 'lastIndexOf')
29 changes: 29 additions & 0 deletions test/suite/domain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var tap = require('../tap')
var domain = require('domain');
var EventEmitter = require('events').EventEmitter;

tap.count(2);

test1();

function test1 () {
var d = domain.create();
d.on('error', function(er) {
tap.ok(true, 'thrown error caught')
test2();
});
d.run(function() {
throw new Error('lol')
});
}

function test2 () {
var d = domain.create();
d.on('error', function(er) {
tap.ok(true, 'emitted error caught')
});
d.run(function() {
var e = new EventEmitter();
e.emit('error', new Error('lol'))
});
}