Comparing version 1.0.5 to 1.0.6-b
@@ -10,2 +10,3 @@ #!/usr/bin/env node | ||
arch = process.arch, | ||
version = process.version, | ||
platform = process.platform, | ||
@@ -19,2 +20,7 @@ v8 = /[0-9]+\.[0-9]+/.exec(process.versions.v8)[0]; | ||
arch = arg.substring(14); | ||
} else if (arg.substring(0, 8) === '--target') { | ||
version = arg.substring(9); | ||
} else if (arg.substring(0, 4) === '--v8') { | ||
v8 = arg.substring(5); | ||
return false; | ||
} else if (arg === '--debug') { | ||
@@ -60,3 +66,3 @@ debug = true; | ||
['rebuild'].concat(args), | ||
{customFds: [0, 1, 2]}) | ||
{stdio: [process.stdin, process.stdout, process.stderr]}) | ||
.on('exit', function(err) { | ||
@@ -63,0 +69,0 @@ if (err) { |
@@ -5,6 +5,10 @@ "use strict"; | ||
module.exports = Future; | ||
Function.prototype.future = function() { | ||
Function.prototype.future = function(detach) { | ||
var fn = this; | ||
var ret = function() { | ||
return new FiberFuture(fn, this, arguments); | ||
var future = new FiberFuture(fn, this, arguments); | ||
if (detach) { | ||
future.detach(); | ||
} | ||
return future; | ||
}; | ||
@@ -197,22 +201,40 @@ ret.toString = function() { | ||
// Link the stack traces up | ||
var stack = {}, error = this.error instanceof Object ? this.error : new Error(this.error); | ||
var longError = Object.create(error); | ||
Error.captureStackTrace(stack, Future.prototype.get); | ||
Object.defineProperty(longError, 'stack', { | ||
get: function() { | ||
var baseStack = error.stack; | ||
if (baseStack) { | ||
baseStack = baseStack.split('\n'); | ||
return [baseStack[0]] | ||
.concat(stack.stack.split('\n').slice(1)) | ||
.concat(' - - - - -') | ||
.concat(baseStack.slice(1)) | ||
.join('\n'); | ||
} else { | ||
return stack.stack; | ||
} | ||
}, | ||
enumerable: true, | ||
}); | ||
throw longError; | ||
var error = this.error; | ||
var localStack = {}; | ||
Error.captureStackTrace(localStack, Future.prototype.get); | ||
var futureStack = Object.getOwnPropertyDescriptor(error, 'futureStack'); | ||
if (!futureStack) { | ||
futureStack = Object.getOwnPropertyDescriptor(error, 'stack'); | ||
if (futureStack) { | ||
Object.defineProperty(error, 'futureStack', futureStack); | ||
} | ||
} | ||
if (futureStack && futureStack.get) { | ||
Object.defineProperty(error, 'stack', { | ||
get: function() { | ||
var stack = futureStack.get.apply(error); | ||
if (stack) { | ||
stack = stack.split('\n'); | ||
return [stack[0]] | ||
.concat(localStack.stack.split('\n').slice(1)) | ||
.concat(' - - - - -') | ||
.concat(stack.slice(1)) | ||
.join('\n'); | ||
} else { | ||
return localStack.stack; | ||
} | ||
}, | ||
set: function(stack) { | ||
Object.defineProperty(error, 'stack', { | ||
value: stack, | ||
configurable: true, | ||
enumerable: false, | ||
writable: true, | ||
}); | ||
}, | ||
configurable: true, | ||
enumerable: false, | ||
}); | ||
} | ||
throw error; | ||
} else { | ||
@@ -219,0 +241,0 @@ return this.value; |
{ | ||
"name": "fibers", | ||
"version": "1.0.5", | ||
"version": "1.0.6-b", | ||
"description": "Cooperative multi-tasking for Javascript", | ||
@@ -11,4 +11,4 @@ "keywords": [ | ||
"scripts": { | ||
"install": "node ./build.js", | ||
"test": "node ./test.js" | ||
"install": "node build.js || nodejs build.js", | ||
"test": "node test.js || nodejs test.js" | ||
}, | ||
@@ -19,2 +19,3 @@ "repository": { | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
@@ -21,0 +22,0 @@ "node": ">=0.5.2" |
16
test.js
@@ -6,2 +6,3 @@ #!/usr/bin/env node | ||
var ret = 0; | ||
function runTest(test, cb) { | ||
@@ -32,2 +33,3 @@ var env = {}; | ||
if (stdout !== 'pass\n' || stderr !== '') { | ||
ret = 1; | ||
console.error( | ||
@@ -39,2 +41,5 @@ test+ ': *fail*\n'+ | ||
); | ||
} else if (code !== 0) { | ||
ret = 1; | ||
console.error(test+ ': fail ('+ code+ ')'); | ||
} else { | ||
@@ -47,10 +52,7 @@ console.log(test+ ': '+ 'pass'); | ||
var cb = function(err) { | ||
if (err) { | ||
console.error(String(err)); | ||
process.exit(1); | ||
} | ||
var cb = function() { | ||
process.exit(ret); | ||
}; | ||
fs.readdirSync('./test').reverse().forEach(function(file) { | ||
cb = new function(cb, file) { | ||
cb = new function(cb) { | ||
return function(err) { | ||
@@ -60,4 +62,4 @@ if (err) return cb(err); | ||
}; | ||
}(cb, file); | ||
}(cb); | ||
}); | ||
cb(); |
var Fiber = require('fibers'); | ||
Fiber(function() { | ||
// Because of how v8 handles strings, the call to new RegExp chews up a lot of stack space | ||
// outside of JS. | ||
function fn() { | ||
var foo = ''; | ||
for (var ii = 0; ii < 1024; ++ii) { | ||
foo += 'a'; | ||
} | ||
new RegExp(foo, 'g'); | ||
} | ||
// Calculate how far we can go recurse without hitting the JS stack limit | ||
// Calculate how far we can go recurse without hitting the JS stack limit | ||
function calculateStackSpace() { | ||
var max = 0; | ||
@@ -22,3 +13,15 @@ function testRecursion(ii) { | ||
} catch (err) {} | ||
return max; | ||
} | ||
// Invoke a RepExp operation that eats a lot of stack space | ||
function pathologicRegExp(preStack) { | ||
function fn() { | ||
var foo = ''; | ||
for (var ii = 0; ii < 1024; ++ii) { | ||
foo += 'a'; | ||
} | ||
new RegExp(foo, 'g'); | ||
} | ||
// Recurse to the limit and then invoke a stack-heavy C++ operation | ||
@@ -28,4 +31,17 @@ function wasteStack(ii) { | ||
} | ||
wasteStack(max - 128); // not sure if this test is even that useful because of this padding | ||
console.log('pass'); | ||
wasteStack(preStack); | ||
} | ||
Fiber(function() { | ||
// Ensure that this doesn't ruin everything while in a fiber | ||
var max = calculateStackSpace(); | ||
for (var stack = max; stack > 0; --stack) { | ||
try { | ||
pathologicRegExp(stack); | ||
break; | ||
} catch (err) {} | ||
} | ||
}).run(); | ||
console.log('pass'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
1870749
56
906
1