-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iojs: introduce internal modules #848
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,3 @@ | ||
'use strict'; | ||
|
||
// This is a free list to avoid creating so many of the same object. | ||
exports.FreeList = function(name, max, constructor) { | ||
this.name = name; | ||
this.constructor = constructor; | ||
this.max = max; | ||
this.list = []; | ||
}; | ||
|
||
|
||
exports.FreeList.prototype.alloc = function() { | ||
//debug("alloc " + this.name + " " + this.list.length); | ||
return this.list.length ? this.list.shift() : | ||
this.constructor.apply(this, arguments); | ||
}; | ||
|
||
|
||
exports.FreeList.prototype.free = function(obj) { | ||
//debug("free " + this.name + " " + this.list.length); | ||
if (this.list.length < this.max) { | ||
this.list.push(obj); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
module.exports = require('internal/freelist'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
// This is a free list to avoid creating so many of the same object. | ||
exports.FreeList = function(name, max, constructor) { | ||
this.name = name; | ||
this.constructor = constructor; | ||
this.max = max; | ||
this.list = []; | ||
}; | ||
|
||
|
||
exports.FreeList.prototype.alloc = function() { | ||
return this.list.length ? this.list.shift() : | ||
this.constructor.apply(this, arguments); | ||
}; | ||
|
||
|
||
exports.FreeList.prototype.free = function(obj) { | ||
if (this.list.length < this.max) { | ||
this.list.push(obj); | ||
return true; | ||
} | ||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,8 @@ | |
'lib/v8.js', | ||
'lib/vm.js', | ||
'lib/zlib.js', | ||
|
||
'lib/internal/freelist.js', | ||
], | ||
}, | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('internal/freelist'); | ||
1 change: 1 addition & 0 deletions
1
test/fixtures/internal-modules/node_modules/internal/freelist.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Flags: --expose_internals | ||
|
||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
assert.equal(typeof require('internal/freelist').FreeList, 'function'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
assert.throws(function() { | ||
require('internal/freelist'); | ||
}); | ||
|
||
assert(require('../fixtures/internal-modules') === 42); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this file be called freelist.js or something? Avoids unnecessary churn when another module is added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what do you mean.
js2c
drops extensions so this is how we require internal modules. This particular test checks that if we try it in userland module and there isnode_modules/internal/freelist.js
everything works as before.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The directory is called test/fixtures/internal-modules but it's really only about the freelist module. Maybe move index.js to test/fixtures/internal-modules/freelist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't change a lot. we only need to test this once with any module. it could be anything other than
freelist