-
-
Notifications
You must be signed in to change notification settings - Fork 35.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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Internal modules can be used to share private code between public modules without risk to expose private APIs to the user.
- Loading branch information
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,26 @@ | ||
| '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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
| 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' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Femto-nit: can you append a comma? That makes the diff less noisy when new entries are added. |
||
| ], | ||
| }, | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| module.exports = require('internal/freelist'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what do you mean.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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') === true); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,11 +238,11 @@ def ReadMacros(lines): | |
|
|
||
|
|
||
| NATIVE_DECLARATION = """\ | ||
| { "%(id)s", %(id)s_native, sizeof(%(id)s_native)-1 }, | ||
| { "%(id)s", %(escaped_id)s_native, sizeof(%(escaped_id)s_native)-1 }, | ||
| """ | ||
|
|
||
| SOURCE_DECLARATION = """\ | ||
| const char %(id)s_native[] = { %(data)s }; | ||
| const char %(escaped_id)s_native[] = { %(data)s }; | ||
| """ | ||
|
|
||
|
|
||
|
|
@@ -293,16 +293,18 @@ def JS2C(source, target): | |
| lines = ExpandMacros(lines, macros) | ||
| lines = CompressScript(lines, do_jsmin) | ||
| data = ToCArray(s, lines) | ||
| id = os.path.basename(str(s)).split('.')[0] | ||
| id = '/'.join((str(s).split(os.sep)[1:])).split('.')[0] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not 100% sure if you should be using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch. someone needs to check this on windows |
||
| if delay: id = id[:-6] | ||
| if delay: | ||
| delay_ids.append((id, len(lines))) | ||
| else: | ||
| ids.append((id, len(lines))) | ||
| source_lines.append(SOURCE_DECLARATION % { 'id': id, 'data': data }) | ||
| source_lines_empty.append(SOURCE_DECLARATION % { 'id': id, 'data': 0 }) | ||
| native_lines.append(NATIVE_DECLARATION % { 'id': id }) | ||
|
|
||
|
|
||
| escaped_id = id.replace('/', '$') | ||
| source_lines.append(SOURCE_DECLARATION % { 'id': id, 'escaped_id': escaped_id, 'data': data }) | ||
| source_lines_empty.append(SOURCE_DECLARATION % { 'id': id, 'escaped_id': escaped_id, 'data': 0 }) | ||
| native_lines.append(NATIVE_DECLARATION % { 'id': id, 'escaped_id': escaped_id }) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please wrap at 80 columns here. |
||
|
|
||
| # Build delay support functions | ||
| get_index_cases = [ ] | ||
| get_script_source_cases = [ ] | ||
|
|
||
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.
You might as well remove this commented out code while you're here.