Commit Graph

9047 Commits (48976d29f4a2dd72cbef2096dd5e7b822ee19df0)

Author SHA1 Message Date
Ben Noordhuis 48976d29f4 vm: fix Persistent<Context> leak 2013-08-23 02:07:24 +02:00
Ben Noordhuis 2891790dbd vm: remove unnecessary Persistent<FunctionTemplate> 2013-08-23 14:29:58 +02:00
Ben Noordhuis bc28acdd02 buffer: fix regression in Buffer(buf) constructor
Commit 3a2f273b got the source and the target wrong when copying over
the data. Fix that and add a regression test.

Fixes #6111.
2013-08-23 12:01:47 +02:00
Timothy J Fontaine 546ae2eef9 util: pass opts to custom inspect functions
Objects with custom inpsect functions should get the options that were
passed to `util.inspect()`

fixes #5822
fixes #6098
2013-08-22 16:54:17 -07:00
Trevor Norris fa89cf545c buffer: fix inspect throw if slice length too long
All the Buffer#{ascii,hex,etc.}Slice() methods are intentionally strict
to alert if a Buffer instance was attempting to be accessed out of
bounds. Buffer#toString() is the more user friendly way of accessing the
data, and will coerce values to their min/max on overflow.
2013-08-21 22:18:20 -07:00
Timothy J Fontaine 2769d97e67 buffer: adhere to INSPECT_MAX_BYTES 2013-08-21 20:50:28 -07:00
isaacs eef552774e vm: Put back display_errors flag
This is an important part of the repl use-case.

TODO: The arg parsing in vm.runIn*Context() is rather wonky.
It would be good to move more of that into the Script class,
and/or an options object.
2013-08-21 17:58:12 -07:00
Domenic Denicola 7afdba6e0b vm, core, module: re-do vm to fix known issues
As documented in #3042 and in [1], the existing vm implementation has
many problems. All of these are solved by @brianmcd's [contextify][2]
package. This commit uses contextify as a conceptual base and its code
core to overhaul the vm module and fix its many edge cases and caveats.

Functionally, this fixes #3042. In particular:

- A context is now indistinguishable from the object it is based on
  (the "sandbox"). A context is simply a sandbox that has been marked
  by the vm module, via `vm.createContext`, with special internal
  information that allows scripts to be run inside of it.
- Consequently, items added to the context from anywhere are
  immediately visible to all code that can access that context, both
  inside and outside the virtual machine.

This commit also smooths over the API very slightly:

- Parameter defaults are now uniformly triggered via `undefined`, per
  ES6 semantics and previous discussion at [3].
- Several undocumented and problematic features have been removed, e.g.
  the conflation of `vm.Script` with `vm` itself, and the fact that
  `Script` instances also had all static `vm` methods. The API is now
  exactly as documented (although arguably the existence of the
  `vm.Script` export is not yet documented, just the `Script` class
  itself).

In terms of implementation, this replaces node_script.cc with
node_contextify.cc, which is derived originally from [4] (see [5]) but
has since undergone extensive modifications and iterations to expose
the most useful C++ API and use the coding conventions and utilities of
Node core.

The bindings exposed by `process.binding('contextify')`
(node_contextify.cc) replace those formerly exposed by
`process.binding('evals')` (node_script.cc). They are:

- ContextifyScript(code, [filename]), with methods:
  - runInThisContext()
  - runInContext(sandbox, [timeout])
- makeContext(sandbox)

From this, the vm.js file builds the entire documented vm module API.

node.js and module.js were modified to use this new native binding, or
the vm module itself where possible. This introduces an extra line or
two into the stack traces of module compilation (and thus into most
stack traces), explaining the changed tests.

The tests were also updated slightly, with all vm-related simple tests
consolidated as test/simple/test-vm-* (some of them were formerly
test/simple/test-script-*). At the same time they switched from
`common.debug` to `console.error` and were updated to use
`assert.throws` instead of rolling their own error-testing methods.

New tests were also added, of course, demonstrating the new
capabilities and fixes.

[1]: http://nodejs.org/docs/v0.10.16/api/vm.html#vm_caveats
[2]: https://github.com/brianmcd/contextify
[3]: https://github.com/joyent/node/issues/5323#issuecomment-20250726
[4]: bf123f3ef9/src/contextify.cc
[5]: https://gist.github.com/domenic/6068120
2013-08-21 15:52:23 -07:00
Timothy J Fontaine 3602d4c23b Now working on 0.11.7 2013-08-21 14:16:46 -07:00
Timothy J Fontaine 51336a44bb Merge branch 'v0.11.6-release' 2013-08-21 14:16:29 -07:00
Timothy J Fontaine 04018d4b39 2013.08.21, Version 0.11.6 (Unstable)
* uv: Upgrade to v0.11.8

* v8: upgrade v8 to 3.20.14.1

* build: disable SSLv2 by default (Ben Noordhuis)

* build: don't auto-destroy existing configuration (Ben Noordhuis)

* crypto: add TLS 1.1 and 1.2 to secureProtocol list (Matthias Bartelmeß)

* crypto: fix memory leak in randomBytes() error path (Ben Noordhuis)

* dgram: don't call into js when send cb is omitted (Ben Noordhuis)

* dgram: fix regression in string argument handling (Ben Noordhuis)

* domains: performance improvements (Trevor Norris)

* events: EventEmitter = require('events') (Jake Verbaten)

* http: Add write()/end() callbacks (isaacs)

* http: Consistent 'finish' event semantics (isaacs)

* http: Prefer 'binary' over 'ascii' (isaacs)

* http: Support legacy agent.addRequest API (isaacs)

* http: Write hex/base64 chunks properly (isaacs)

* http: add agent.maxFreeSockets option (isaacs)

* http: provide access to raw headers/trailers (isaacs)

* http: removed headers stay removed (James Halliday)

* http,timers: improve callback performance (Ben Noordhuis)

* net: family option in net.connect (Vsevolod Strukchinsky)

* readline: pause stdin before turning off terminal raw mode (Daniel Chatfield)

* smalloc: allow different external array types (Trevor Norris)

* smalloc: expose ExternalArraySize (Trevor Norris)

* stream: Short-circuit buffer pushes when flowing (isaacs)

* tls: handle errors on socket before releasing it (Fedor Indutny)

* util: fix isPrimitive check (Trevor Norris)

* util: isObject should always return boolean (Trevor Norris)
2013-08-21 13:20:50 -07:00
Timothy J Fontaine a784abaff6 uv: Upgrade to v0.11.8 2013-08-21 11:15:21 -07:00
Timothy J Fontaine 41f55dc59b test: net-GH-5504 child env needs NODE_COMMON_PORT 2013-08-21 10:51:42 -07:00
isaacs cdf2a661f2 Merge remote-tracking branch 'ry/v0.10'
Conflicts:
	lib/tls.js
2013-08-21 09:40:10 -07:00
Fedor Indutny a1b3273a9d test: fix test failure on linux after edd2fcc 2013-08-21 12:33:09 +04:00
Ben Noordhuis 8d42c6344b deps: upgrade http_parser to 303c4e4
Upgrade to joyent/http-parser@303c4e4. Changes:

  * Do not accept PUN/GEM methods as PUT/GET.
  * Further request method check strengthening.
2013-08-21 03:40:43 +02:00
Fedor Indutny af6a2339c5 tls: fix assertion when ssl is destroyed at read
`maybeInitFinished()` can emit the 'secure' event which
in turn destroys the connection in case of authentication
failure and sets `this.pair.ssl` to `null`.

If such condition appeared after non-empty read - loop will continue
and `clearOut` will be called on `null` object instead of
`crypto::Connection` instance. Resulting in the following assertion:

    ERROR: Error: Hostname/IP doesn't match certificate's altnames
    Assertion failed: handle->InternalFieldCount() > 0

fix #5756
2013-08-21 16:15:08 +04:00
Trevor Norris 849cf1aa92 smalloc: consistent-ify syntax
Small syntax fixes of variable renaming and argument alignment.
2013-08-20 13:33:50 -07:00
Trevor Norris 6b5c43ed18 smalloc: length is byte size, not array length
The C++ API has been changed so the passed length is the byte size of
the data, not the length of the array.

This was done so users need to explicitly define how much memory they
want allocated.
2013-08-20 13:33:35 -07:00
Trevor Norris ed0677f427 smalloc: expose ExternalArraySize
Useful to correctly determine the byte size of the external memory that
needs to be allocated for an external array.
2013-08-20 11:07:37 -07:00
Trevor Norris 50cee6ecab util: isObject should always return boolean
Fix small bug where isObject would return the original object instead of
true.
2013-08-20 11:05:36 -07:00
Vsevolod Strukchinsky edd2fcccf0 net: family option in net.connect
`dns.lookup` defaults to selecting IPv4 record even if IPv6 is available
for the desired zone. Generally, this approach works, but if IPv4
address is unavailable - there'll be no other way to opt-out and connect using
IPv6 address than calling `dns.lookup` and passing it to `.connect()`
directly.

This commit adds `family` option to `net.connect` method to figure out
this issue.
2013-08-20 21:03:52 +04:00
Gil Pedersen e04c8a8ee4 fs: use correct self reference for autoClose test 2013-08-20 17:10:18 +02:00
isaacs 26a8c0c6b8 doc: Minor typos in dgram doc
a/an usage.  Thanks @KenanSulayman
2013-08-19 17:55:58 -07:00
isaacs 85d6b78343 test: Remove unnecessary assertion
It only fails once in about 1000 times, but that's too many.
It's timing dependent, and the main behavior is covered by the other
assertions in the test anyway.
2013-08-19 17:43:38 -07:00
Raynos 6ed861dd7f events: have events module exports EventEmitter
This change is 100% backwards compatible.

This change will make using `EventEmitter` slightly simpler / nicer and
adheres to the best practice set forth by substack.

```js
var EventEmitter = require("events")

var emitter = new EventEmitter()
```

The only difference is that we now have to set `EventEmitter` as a
property of `EventEmitter` for backwards compatibility like we do with
[`Stream`][1]

We have also set the `usingDomains` property on the `EventEmitter`
constructor itself because that aligns with it's current usage of
`require("events").usingDomains = true`

There are other internals that would benefit from this change as well
like `StringDecoder`
2013-08-19 17:27:08 -07:00
Matthew Aynalem c171c490f2 fixes #6031 spelling errors
explictly => explicitly
accesss => access
througput => throughput
epxression => expression
communiction => communication
becuase => because
repersent => represent
condonitions => conditions
decompresion => decompression
intentially => intentionally
eventes => events
listning => listening
resicved => received
becuase => because
fundimental => fundamental
colapse => collapse
privlages => privileges
sufficently => sufficiently
hapepns => happens
expliclitly => explicitly
thier => their
shold => should
2013-08-19 16:42:16 -07:00
Duan Yao 9456cf8fe2 doc: Add callback parameter to dgram socket.bind()
Also, describe more details of bind().
2013-08-19 16:33:38 -07:00
ChrisWren 2385fbbc3a doc: fixed syntax error in stream.Transform 2013-08-19 16:10:05 -07:00
James Halliday 5555318bf3 http: removed headers stay removed
This allows automatically-inserted headers to be removed permanently by
calling OutgoingMessage.removeHeader() on them, as if they were normal
headers.
2013-08-19 16:05:44 -07:00
Edward Hutchins 31a27ca72d Added documentation for process.execArgv 2013-08-19 15:53:09 -07:00
Eivind Uggedal 732f8b9641 doc: add missing word in Transform stream intro 2013-08-19 15:45:35 -07:00
isaacs fe0f12b100 Merge remote-tracking branch 'ry/v0.10' 2013-08-19 14:15:03 -07:00
Trevor Norris f97a1267e2 buffer: lint
This and b80d11d are my fault. An unrelated test was failing, which
prevents {js,cpp}lint from running automatically.
2013-08-19 11:15:16 -07:00
Fedor Indutny b80d11d46b buffer: lint 2013-08-19 20:41:24 +04:00
Fedor Indutny 306f863438 crypto: don't touch ssl_ in Connection
`ssl_` is a property of SSLWrap class, don't touch it, and definitely
don't zero it in constructor.
2013-08-19 20:34:34 +04:00
isaacs 545807918e stream: Throw on 'error' if listeners removed
In this situation:

    writable.on('error', handler);
    readable.pipe(writable);
    writable.removeListener('error', handler);
    writable.emit('error', new Error('boom'));

there is actually no error handler, but it doesn't throw, because of the
fix for stream.once('error', handler), in 23d92ec.

Note that simply reverting that change is not valid either, because
otherwise this will emit twice, being handled the first time, and then
throwing the second:

    writable.once('error', handler);
    readable.pipe(writable);
    writable.emit('error', new Error('boom'));

Fix this with a horrible hack to make the stream pipe onerror handler
added before any other userland handlers, so that our handler is not
affected by adding or removing any userland handlers.

Closes #6007.
2013-08-19 09:26:49 -07:00
Fedor Indutny b9a0eb0688 tls, crypto: deduplicate code
Commit 03e008d introduced src/tls_wrap.cc and src/tls_wrap.h but
said files copied on the order of 1 kLoC from src/node_crypto.cc
and src/node_crypto.h.  This commit undoes some of the duplication.

Fixes #6024.
2013-08-19 17:52:44 +02:00
Ben Noordhuis 3e25ed905c src: move includes inside include guard
Having the includes in src/node_buffer.h outside of the include guard
is not really harmful but it's inconsistent with other header files.
2013-08-19 16:42:12 +02:00
isaacs 3b923a7ace Merge remote-tracking branch 'ry/v0.10'
Conflicts:
	AUTHORS
	ChangeLog
	lib/dgram.js
	lib/http.js
	src/node_crypto.cc
	src/node_version.h
2013-08-17 13:57:41 -07:00
Ben Noordhuis 0c2960ef4a dgram: fix assertion on bad send() arguments
Add range checks for the offset, length and port arguments to
dgram.Socket#send().  Fixes the following assertion:

    node: ../../src/udp_wrap.cc:264: static v8::Handle<v8::Value>
    node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion
    `offset < Buffer::Length(buffer_obj)' failed.

And:

    node: ../../src/udp_wrap.cc:265: static v8::Handle<v8::Value>
    node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion
    `length <= Buffer::Length(buffer_obj) - offset' failed.

Interestingly enough, a negative port number was accepted until now but
silently ignored.  (In other words, it would send the datagram to a
random port.)

This commit exposed a bug in the simple/test-dgram-close test which
has also been fixed.

This is a back-port of commit 41ec6d0 from the master branch.

Fixes #6025.
2013-08-17 17:11:02 +02:00
Daniel Chatfield 5453619eb2 readline: pause stdin before turning off terminal raw mode
On windows, libuv will immediately make a `ReadConsole` call (in the
thread pool) when a 'flowing' `uv_tty_t` handle is switched to
line-buffered mode. That causes an immediate issue for some users,
since libuv can't cancel the `ReadConsole` operation on Windows 8 /
Server 2012 and up if the program switches back to raw mode later.

But even if this will be fixed in libuv at some point, it's better to
avoid the overhead of starting work in the thread pool and immediately
cancelling it afther that.

See also f34f1e3, where the same change is made for the opposite
flow, e.g. move `resume()` after `_setRawMode(true)`.

Fixes #5927

This is a backport of dfb0461 (see #5930) to the v0.10 branch.
2013-08-17 15:35:09 +02:00
Daniel Chatfield dfb0461c4c readline: pause stdin before turning off terminal raw mode
On windows, libuv will immediately make a `ReadConsole` call (in the
thread pool) when a 'flowing' `uv_tty_t` handle is switched to
line-buffered mode. That causes an immediate issue for some users,
since libuv can't cancel the `ReadConsole` operation on Windows 8 /
Server 2012 and up if the program switches back to raw mode later.

But even if this will be fixed in libuv at some point, it's better to
avoid the overhead of starting work in the thread pool and immediately
cancelling it afther that.

See also f34f1e3, where the same change is made for the opposite
flow, e.g. move `resume()` after `_setRawMode(true)`.

Fixes #5927
Closes #5930
2013-08-17 15:22:50 +02:00
isaacs a66d2400a0 blog: v0.10.16 2013-08-16 12:47:54 -07:00
isaacs 0e043528a1 Now working on v0.10.17 2013-08-16 12:47:29 -07:00
isaacs e679739b63 Merge branch 'v0.10.16-release' into v0.10 2013-08-16 12:46:56 -07:00
Trevor Norris 2dd4a745b0 buffer: don't call ByteLength for simple encodings
For several encodings the byte length is simple arithmetic. Don't call
into C++ in those cases.
2013-08-16 12:42:33 -07:00
isaacs 50b4c905a4 2013.08.16, Version 0.10.16 (Stable)
* v8: back-port fix for CVE-2013-2882

* npm: Upgrade to 1.3.8

* crypto: fix assert() on malformed hex input (Ben Noordhuis)

* crypto: fix memory leak in randomBytes() error path (Ben Noordhuis)

* events: fix memory leak, don't leak event names (Ben Noordhuis)

* http: Handle hex/base64 encodings properly (isaacs)

* http: improve chunked res.write(buf) performance (Ben Noordhuis)

* stream: Fix double pipe error emit (Eran Hammer)
2013-08-16 08:32:38 -07:00
isaacs 5abdef790c npm: Upgrade to 1.3.8 2013-08-16 08:19:31 -07:00
Ben Noordhuis f55aca6515 crypto: fix memory leak in randomBytes() error path
This is the conceptual back-port of commit ec54873 from the master
branch.
2013-08-16 16:50:01 +02:00