Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
iojs: introduce internal modules#848
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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'); |
| 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; | ||
| }; |
| 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', | ||
| ], | ||
| }, | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| module.exports = require('internal/freelist'); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| 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'); |
| 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); |
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.
js2cdrops 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.jseverything 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