diff --git a/deps/v8/src/v8natives.js b/deps/v8/src/v8natives.js index 0afe231c8cd..95ea731c00d 100644 --- a/deps/v8/src/v8natives.js +++ b/deps/v8/src/v8natives.js @@ -157,6 +157,17 @@ function GlobalEval(x) { } +// execScript for IE compatibility. +function GlobalExecScript(expr, lang) { + // NOTE: We don't care about the character casing. + if (!lang || /javascript/i.test(lang)) { + var f = %CompileString(ToString(expr)); + f.call(%GlobalReceiver(global)); + } + return null; +} + + // ---------------------------------------------------------------------------- @@ -176,7 +187,8 @@ function SetupGlobal() { "isFinite", GlobalIsFinite, "parseInt", GlobalParseInt, "parseFloat", GlobalParseFloat, - "eval", GlobalEval + "eval", GlobalEval, + "execScript", GlobalExecScript )); } diff --git a/deps/v8/test/mjsunit/execScript-case-insensitive.js b/deps/v8/test/mjsunit/execScript-case-insensitive.js new file mode 100644 index 00000000000..468d65747ea --- /dev/null +++ b/deps/v8/test/mjsunit/execScript-case-insensitive.js @@ -0,0 +1,34 @@ +// Copyright 2008 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +var x = 0; +execScript('x = 1', 'javascript'); +assertEquals(1, x); + +execScript('x = 2', 'JavaScript'); +assertEquals(2, x); + diff --git a/deps/v8/test/mjsunit/function-names.js b/deps/v8/test/mjsunit/function-names.js index 5ed0b794e8f..c083f18f5d4 100644 --- a/deps/v8/test/mjsunit/function-names.js +++ b/deps/v8/test/mjsunit/function-names.js @@ -128,6 +128,6 @@ var globalFunctions = [ "encodeURI", "encodeURIComponent", "Error", "TypeError", "RangeError", "SyntaxError", "ReferenceError", "EvalError", "URIError", "isNaN", "isFinite", "parseInt", "parseFloat", - "eval"]; + "eval", "execScript"]; TestFunctionNames(this, globalFunctions); diff --git a/deps/v8/test/mjsunit/regress/regress-1341167.js b/deps/v8/test/mjsunit/regress/regress-1341167.js new file mode 100644 index 00000000000..194a7b886a1 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-1341167.js @@ -0,0 +1,33 @@ +// Copyright 2008 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Make sure that 'this' is bound to the global object when using +// execScript. + +var result; +execScript("result = this"); +assertTrue(result === this); diff --git a/doc/api/buffers.markdown b/doc/api/buffers.markdown index 616ccf6fb22..ae24855fb60 100644 --- a/doc/api/buffers.markdown +++ b/doc/api/buffers.markdown @@ -16,6 +16,9 @@ method. Here are the different string encodings; * `'ascii'` - for 7 bit ASCII data only. This encoding method is very fast, and will strip the high bit if set. +Note that this encoding converts a null character (`'\0'` or `'\u0000'`) into +`0x20` (character code of a space). If you want to convert a null character +into `0x00`, you should use `'utf8'`. * `'utf8'` - Multi byte encoded Unicode characters. Many web pages and other document formats use UTF-8. diff --git a/doc/api/fs.markdown b/doc/api/fs.markdown index 7df7ee11583..669b61dc515 100644 --- a/doc/api/fs.markdown +++ b/doc/api/fs.markdown @@ -255,8 +255,27 @@ Synchronous close(2). ### fs.open(path, flags, [mode], [callback]) -Asynchronous file open. See open(2). Flags can be 'r', 'r+', 'w', 'w+', 'a', -or 'a+'. `mode` defaults to 0666. The callback gets two arguments `(err, fd)`. +Asynchronous file open. See open(2). `flags` can be: + +* `'r'` - Open file for reading. +An exception occurs if the file does not exist. + +* `'r+'` - Open file for reading and writing. +An exception occurs if the file does not exist. + +* `'w'` - Open file for writing. +The file is created (if it does not exist) or truncated (if it exists). + +* `'w+'` - Open file for reading and writing. +The file is created (if it does not exist) or truncated (if it exists). + +* `'a'` - Open file for appending. +The file is created if it does not exist. + +* `'a+'` - Open file for reading and appending. +The file is created if it does not exist. + +`mode` defaults to `0666`. The callback gets two arguments `(err, fd)`. ### fs.openSync(path, flags, [mode]) @@ -419,6 +438,12 @@ Objects returned from `fs.stat()` and `fs.lstat()` are of this type. `ReadStream` is a `Readable Stream`. +### Event: 'open' + +`function (fd) { }` + + `fd` is the file descriptor used by the ReadStream. + ### fs.createReadStream(path, [options]) Returns a new ReadStream object (See `Readable Stream`). diff --git a/doc/api/globals.markdown b/doc/api/globals.markdown index d2678fd8c8e..f5c353b2fb4 100644 --- a/doc/api/globals.markdown +++ b/doc/api/globals.markdown @@ -79,6 +79,15 @@ A reference to the current module. In particular for more information. `module` isn't actually a global but rather local to each module. + +### exports + +An object which is shared between all instances of the current module and +made accessible through `require()`. +`exports` is the same as the `module.exports` object. See `src/node.js` +for more information. +`exports` isn't actually a global but rather local to each module. + ### setTimeout(cb, ms) ### clearTimeout(t) ### setInterval(cb, ms) diff --git a/doc/api/http.markdown b/doc/api/http.markdown index cc99da5399a..7af538513c0 100644 --- a/doc/api/http.markdown +++ b/doc/api/http.markdown @@ -52,7 +52,7 @@ per connection (in the case of keep-alive connections). ### Event: 'checkContinue' -`function (request, response) {}` +`function (request, response) { }` Emitted each time a request with an http Expect: 100-continue is received. If this event isn't listened for, the server will automatically respond @@ -68,7 +68,7 @@ not be emitted. ### Event: 'upgrade' -`function (request, socket, head)` +`function (request, socket, head) { }` Emitted each time a client requests a http upgrade. If this event isn't listened for, then clients requesting an upgrade will have their connections @@ -84,7 +84,7 @@ sent to the server on that socket. ### Event: 'clientError' -`function (exception) {}` +`function (exception) { }` If a client connection emits an 'error' event - it will forwarded here. @@ -394,6 +394,10 @@ Options: - `path`: Request path. Should include query string and fragments if any. E.G. `'/index.html?page=12'` - `headers`: An object containing request headers. +- `agent`: Controls `Agent` behavior. Possible values: + - `undefined` (default): use default `Agent` for this host and port. + - `Agent` object: explicitly use the passed in `Agent`. + - `false`: explicitly generate a new `Agent` for this host and port. `Agent` will not be re-used. `http.request()` returns an instance of the `http.ClientRequest` class. The `ClientRequest` instance is a writable stream. If one needs to @@ -483,7 +487,7 @@ Options: ### Event: 'upgrade' -`function (response, socket, head)` +`function (response, socket, head) { }` Emitted each time a server responds to a request with an upgrade. If this event isn't being listened for, clients receiving an upgrade header will have @@ -537,14 +541,6 @@ A client server pair that show you how to listen for the `upgrade` event using ` }); -### Event: 'continue' - -`function ()` - -Emitted when the server sends a '100 Continue' HTTP response, usually because -the request contained 'Expect: 100-continue'. This is an instruction that -the client should send the request body. - ### agent.maxSockets By default set to 5. Determines how many concurrent sockets the agent can have open. @@ -600,6 +596,14 @@ This is a `Writable Stream`. This is an `EventEmitter` with the following events: +### Event: 'continue' + +`function () { }` + +Emitted when the server sends a '100 Continue' HTTP response, usually because +the request contained 'Expect: 100-continue'. This is an instruction that +the client should send the request body. + ### Event 'response' `function (response) { }` @@ -646,18 +650,27 @@ The response implements the `Readable Stream` interface. ### Event: 'data' -`function (chunk) {}` +`function (chunk) { }` Emitted when a piece of the message body is received. ### Event: 'end' -`function () {}` +`function () { }` Emitted exactly once for each message. No arguments. After emitted no other events will be emitted on the response. +### Event: 'close' + +`function (err) { }` + +Indicates that the underlaying connection was terminated before +`end` event was emitted. +See [http.ServerRequest](#http.ServerRequest)'s `'close'` event for more +information. + ### response.statusCode The 3-digit HTTP response status code. E.G. `404`. diff --git a/doc/api/modules.markdown b/doc/api/modules.markdown index 9dfa1c486ab..30e06363f56 100644 --- a/doc/api/modules.markdown +++ b/doc/api/modules.markdown @@ -318,7 +318,6 @@ Because `module` provides a `filename` property (normally equivalent to `__filename`), the entry point of the current application can be obtained by checking `require.main.filename`. - ## AMD Compatibility Node's modules have access to a function named `define`, which may be diff --git a/doc/api/stdio.markdown b/doc/api/stdio.markdown index a24d0572c63..d4153934e45 100644 --- a/doc/api/stdio.markdown +++ b/doc/api/stdio.markdown @@ -35,7 +35,7 @@ Mark a time. Finish timer, record output. Example console.time('100-elements'); - while (var i = 0; i < 100; i++) { + for (var i = 0; i < 100; i++) { ; } console.timeEnd('100-elements'); diff --git a/doc/favicon.ico b/doc/favicon.ico index 6916dbc03e4..49ac26563f6 100644 Binary files a/doc/favicon.ico and b/doc/favicon.ico differ diff --git a/doc/index.html b/doc/index.html index a3e21bcbec6..ba874daf93a 100644 --- a/doc/index.html +++ b/doc/index.html @@ -24,7 +24,7 @@
  1. Download
  2. -
  3. ChangeLog
  4. +
  5. ChangeLog
  6. About
  7. v0.4.9 docs
  8. v0.5.0 docs
  9. @@ -33,6 +33,7 @@
  10. Blog
  11. Community
  12. Demo
  13. +
  14. Logos
  15. Jobs
@@ -40,6 +41,7 @@
+

diff --git a/doc/logo.png b/doc/logo.png index fabb0e37b61..4ca766d4864 100644 Binary files a/doc/logo.png and b/doc/logo.png differ diff --git a/doc/logos/index.html b/doc/logos/index.html new file mode 100644 index 00000000000..6d8e662e8b9 --- /dev/null +++ b/doc/logos/index.html @@ -0,0 +1,98 @@ + + + + + + + + + + + + Node.js Logos + + +

+
    +
  1. Download
  2. +
  3. ChangeLog
  4. +
  5. About
  6. +
  7. v0.4.9 docs
  8. +
  9. v0.5.0 docs
  10. +
    +
  11. Wiki
  12. +
  13. Blog
  14. +
  15. Community
  16. +
  17. Demo
  18. +
  19. Logos
  20. +
  21. Jobs
  22. +
+
+
+ + +
+
+ +

To echo the evolutionary nature of Node, we've added some punch and playfulness to its identity. All it needs now is a good home with you, download and have fun!

+

Logo Downloads

+ + + + + + + + + + + + + + + + + +
Node.js darkNode.js dark
Node.js standard EPSNode.js reversed EPS
Node.js darkNode.js dark
Node.js bright EPSNode.js 1 color EPS
+

Desktop Background

+

Screensavers

+

Select your screen resolution:
+ 1024 x 768
| 1280 x 1024 | 1440 x 900 | 1920 x 1200 | 2560 x 1440

+ +

 

+

+ + +
+ +
+ + + +
+ Copyright 2010 Joyent, Inc +
+ Node.js is a trademark of Joyent, Inc. + See the trademark policy + for more information. +
+ + + + + + + diff --git a/doc/logos/monitor.png b/doc/logos/monitor.png new file mode 100644 index 00000000000..18c804e2df9 Binary files /dev/null and b/doc/logos/monitor.png differ diff --git a/doc/logos/node-favicon.png b/doc/logos/node-favicon.png new file mode 100644 index 00000000000..8d52a3be44f Binary files /dev/null and b/doc/logos/node-favicon.png differ diff --git a/doc/logos/nodejs-1024x768.png b/doc/logos/nodejs-1024x768.png new file mode 100644 index 00000000000..e571c091d24 Binary files /dev/null and b/doc/logos/nodejs-1024x768.png differ diff --git a/doc/logos/nodejs-1280x1024.png b/doc/logos/nodejs-1280x1024.png new file mode 100644 index 00000000000..00f65d0de53 Binary files /dev/null and b/doc/logos/nodejs-1280x1024.png differ diff --git a/doc/logos/nodejs-1440x900.png b/doc/logos/nodejs-1440x900.png new file mode 100644 index 00000000000..4b818cc682f Binary files /dev/null and b/doc/logos/nodejs-1440x900.png differ diff --git a/doc/logos/nodejs-1920x1200.png b/doc/logos/nodejs-1920x1200.png new file mode 100644 index 00000000000..6b31fecf490 Binary files /dev/null and b/doc/logos/nodejs-1920x1200.png differ diff --git a/doc/logos/nodejs-2560x1440.png b/doc/logos/nodejs-2560x1440.png new file mode 100644 index 00000000000..ba46b7704ec Binary files /dev/null and b/doc/logos/nodejs-2560x1440.png differ diff --git a/doc/logos/nodejs-black.eps b/doc/logos/nodejs-black.eps new file mode 100644 index 00000000000..e3186994f52 Binary files /dev/null and b/doc/logos/nodejs-black.eps differ diff --git a/doc/logos/nodejs-black.png b/doc/logos/nodejs-black.png new file mode 100644 index 00000000000..a7c6d63db4e Binary files /dev/null and b/doc/logos/nodejs-black.png differ diff --git a/doc/logos/nodejs-dark.eps b/doc/logos/nodejs-dark.eps new file mode 100644 index 00000000000..11c230db150 Binary files /dev/null and b/doc/logos/nodejs-dark.eps differ diff --git a/doc/logos/nodejs-dark.png b/doc/logos/nodejs-dark.png new file mode 100644 index 00000000000..56094a9b41a Binary files /dev/null and b/doc/logos/nodejs-dark.png differ diff --git a/doc/logos/nodejs-green.eps b/doc/logos/nodejs-green.eps new file mode 100644 index 00000000000..362ac37d894 Binary files /dev/null and b/doc/logos/nodejs-green.eps differ diff --git a/doc/logos/nodejs-green.png b/doc/logos/nodejs-green.png new file mode 100644 index 00000000000..ee8a2fb550f Binary files /dev/null and b/doc/logos/nodejs-green.png differ diff --git a/doc/logos/nodejs-light.eps b/doc/logos/nodejs-light.eps new file mode 100644 index 00000000000..2317313e4f5 Binary files /dev/null and b/doc/logos/nodejs-light.eps differ diff --git a/doc/logos/nodejs.png b/doc/logos/nodejs.png new file mode 100644 index 00000000000..df49579bb5b Binary files /dev/null and b/doc/logos/nodejs.png differ diff --git a/doc/pipe.css b/doc/pipe.css index 5d9edfea4ba..3cc2b88c353 100644 --- a/doc/pipe.css +++ b/doc/pipe.css @@ -1,21 +1,25 @@ +html { + -webkit-font-smoothing: antialiased; +} + body { - background: #22252a; - color: #eee; - font-size: 14pt; - line-height: 150%; - font-family: times, Times New Roman, times-roman, georgia, serif; - max-width: 30em; - margin: 0 0 5em 9em; + background: #353129; + color: #eee; + font-size: 14pt; + line-height: 150%; + font-family: Georgia, "Times New Roman", Times, serif; + max-width: 30em; + margin: 0 0 5em 9em; } img { - padding: 5em 0; - border: 0; + border: 0; } #toc { position: absolute; top: 2em; left: 0; width: 10em; + font-family: Helvetica, Arial, sans-serif; font-size: 12pt; line-height: 150%; } @@ -35,11 +39,17 @@ img { margin: 0; padding: 0; } -#toc a { color: #aaa; } +#toc a { + color: #8BC84B; +} h1, h2, h3, h4 { - color: #B0C4DE; - margin: 2em 0; + color: #CCD2BC; + font-family: Helvetica, Arial, sans-serif; + margin-top: 2em; + margin-right: 0; + margin-bottom: 10px; + margin-left: 0; } #toc ol ol { @@ -56,14 +66,17 @@ h1 a, h2 a, h3 a, h4 a } pre, code { - font-family: monospace; - font-size: 13pt; - color: #eee0e0; + font-family: Monaco, 'Andale Mono', 'Lucida Console', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; + ; + font-size: 11pt; + color: #C3CC88; } pre { - padding-left: 1em; - border-left: 1px solid #444; + padding-left: 1em; + border-left-width: 1px; + border-left-style: solid; + border-left-color: #8BC84B; } dd { @@ -71,11 +84,16 @@ dd { margin-left: 1em; } -a { color: #cd5; text-decoration: none; } +a { + color: #8BC84B; + text-decoration: none; +} a:hover { text-decoration: underline; } .highlight { background: #733; padding: 0.2em 0; } - +.desktops { + font-size: 14px; +} diff --git a/doc/sh_vim-dark.css b/doc/sh_vim-dark.css index 3b6b3992f55..34a526c533f 100644 --- a/doc/sh_vim-dark.css +++ b/doc/sh_vim-dark.css @@ -1,24 +1,23 @@ -.sh_sourceCode { - - font-weight: normal; - font-style: normal; -} - -.sh_sourceCode .sh_symbol , .sh_sourceCode .sh_cbracket { - color: #fff; -} - -.sh_sourceCode .sh_keyword { - font-style: italic; -} - -.sh_sourceCode .sh_string, .sh_sourceCode .sh_regexp, .sh_sourceCode .sh_number, -.sh_sourceCode .sh_specialchar -{ - color: #B0C4DE; -} - -.sh_sourceCode .sh_comment { - color: #777; -} - +.sh_sourceCode { + + font-weight: normal; + font-style: normal; +} + +.sh_sourceCode .sh_symbol , .sh_sourceCode .sh_cbracket { + color: #fff; +} + +.sh_sourceCode .sh_keyword { + font-style: italic; +} + +.sh_sourceCode .sh_string, .sh_sourceCode .sh_regexp, .sh_sourceCode .sh_number, +.sh_sourceCode .sh_specialchar +{ + color: #B9CCC5; +} + +.sh_sourceCode .sh_comment { + color: #777; +} diff --git a/doc/sponsored.png b/doc/sponsored.png index 7031a935df7..e7564e169d5 100644 Binary files a/doc/sponsored.png and b/doc/sponsored.png differ diff --git a/doc/trademark-policy.pdf b/doc/trademark-policy.pdf index 59a04b2915c..0fc73e73e74 100644 Binary files a/doc/trademark-policy.pdf and b/doc/trademark-policy.pdf differ diff --git a/lib/_debugger.js b/lib/_debugger.js index 2714fc52dc8..4ae19d542e7 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -998,7 +998,7 @@ Interface.prototype.yesNoQuestion = function(prompt, cb) { cb(false); } else { console.log('Please answer y or n.'); - self.restartQuestion(cb); + self.yesNoQuestion(prompt, cb); } }); }; diff --git a/lib/assert.js b/lib/assert.js index 57a798ad72a..9ca871da3d2 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -56,9 +56,21 @@ assert.AssertionError.prototype.toString = function() { return [this.name + ':', this.message].join(' '); } else { return [this.name + ':', - JSON.stringify(this.expected), + JSON.stringify(this.expected, replacer), this.operator, - JSON.stringify(this.actual)].join(' '); + JSON.stringify(this.actual, replacer)].join(' '); + } + function replacer(key, value) { + if (value === undefined) { + return '' + value; + } + if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) { + return value.toString(); + } + if (typeof value === 'function' || value instanceof RegExp) { + return value.toString(); + } + return value; } }; diff --git a/lib/http.js b/lib/http.js index af36d5f01fc..b61be65386d 100644 --- a/lib/http.js +++ b/lib/http.js @@ -1325,7 +1325,10 @@ Agent.prototype._establishNewConnection = function() { debug('AGENT socket keep-alive'); } - req.detachSocket(socket); + // The socket may already be detached and destroyed by an abort call + if (socket._httpMessage) { + req.detachSocket(socket); + } assert(!socket._httpMessage); diff --git a/lib/tls.js b/lib/tls.js index 49c1ce84f8e..e83ae4ef936 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -530,7 +530,10 @@ function SecurePair(credentials, isServer, requestCert, rejectUnauthorized, this.encrypted = new EncryptedStream(this); process.nextTick(function() { - self.ssl.start(); + /* The Connection may be destroyed by an abort call */ + if (self.ssl) { + self.ssl.start(); + } self.cycle(); }); } diff --git a/src/node_buffer.cc b/src/node_buffer.cc index c9fdd0c2846..def06f03db3 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -470,7 +470,15 @@ Handle Buffer::Utf8Write(const Arguments &args) { size_t offset = args[1]->Uint32Value(); - if (s->Length() > 0 && offset >= buffer->length_) { + int length = s->Length(); + + if (length == 0) { + constructor_template->GetFunction()->Set(chars_written_sym, + Integer::New(0)); + return scope.Close(Integer::New(0)); + } + + if (length > 0 && offset >= buffer->length_) { return ThrowException(Exception::TypeError(String::New( "Offset is out of bounds"))); } @@ -491,7 +499,13 @@ Handle Buffer::Utf8Write(const Arguments &args) { constructor_template->GetFunction()->Set(chars_written_sym, Integer::New(char_written)); - if (written > 0 && p[written-1] == '\0') written--; + if (written > 0 && p[written-1] == '\0' && char_written == length) { + uint16_t last_char; + s->Write(&last_char, length - 1, 1, String::NO_HINTS); + if (last_char != 0 || written > s->Utf8Length()) { + written--; + } + } return scope.Close(Integer::New(written)); } diff --git a/test/simple/test-assert.js b/test/simple/test-assert.js index f15072f9d16..b47f0454549 100644 --- a/test/simple/test-assert.js +++ b/test/simple/test-assert.js @@ -229,3 +229,34 @@ try { console.log('All OK'); assert.ok(gotError); + +// #217 +function testAssertionMessage(actual, expected) { + try { + assert.equal(actual, ''); + } catch (e) { + assert.equal(e.toString(), + ['AssertionError:', '""', '==', expected].join(' ')); + } +} +testAssertionMessage(undefined, '"undefined"'); +testAssertionMessage(null, 'null'); +testAssertionMessage(true, 'true'); +testAssertionMessage(false, 'false'); +testAssertionMessage(0, '0'); +testAssertionMessage(100, '100'); +testAssertionMessage(NaN, '"NaN"'); +testAssertionMessage(Infinity, '"Infinity"'); +testAssertionMessage(-Infinity, '"-Infinity"'); +testAssertionMessage('', '""'); +testAssertionMessage('foo', '"foo"'); +testAssertionMessage([], '[]'); +testAssertionMessage([1,2,3], '[1,2,3]'); +testAssertionMessage(/a/, '"/a/"'); +testAssertionMessage(/abc/gim, '"/abc/gim"'); +testAssertionMessage(function f() {}, '"function f() {}"'); +testAssertionMessage({}, '{}'); +testAssertionMessage({a:undefined, b:null}, '{"a":"undefined","b":null}'); +testAssertionMessage({a:NaN, b:Infinity, c:-Infinity}, + '{"a":"NaN","b":"Infinity","c":"-Infinity"}'); + diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js index 9fd0a28de16..9cd4959aa2c 100644 --- a/test/simple/test-buffer.js +++ b/test/simple/test-buffer.js @@ -594,3 +594,30 @@ assert.equal(0xef, b[3]); assert.throws(function() { new Buffer('"pong"', 0, 6, 8031, '127.0.0.1') }); + +// #1210 Test UTF-8 string includes null character +var buf = new Buffer('\0'); +assert.equal(buf.length, 1); +buf = new Buffer('\0\0'); +assert.equal(buf.length, 2); + +buf = new Buffer(2); +var written = buf.write(''); // 0byte +assert.equal(written, 0); +written = buf.write('\0'); // 1byte (v8 adds null terminator) +assert.equal(written, 1); +written = buf.write('a\0'); // 1byte * 2 +assert.equal(written, 2); +written = buf.write('あ'); // 3bytes +assert.equal(written, 0); +written = buf.write('\0あ'); // 1byte + 3bytes +assert.equal(written, 1); +written = buf.write('\0\0あ'); // 1byte * 2 + 3bytes +assert.equal(written, 2); + +buf = new Buffer(10); +written = buf.write('あいう'); // 3bytes * 3 (v8 adds null terminator) +assert.equal(written, 9); +written = buf.write('あいう\0'); // 3bytes * 3 + 1byte +assert.equal(written, 10); + diff --git a/test/simple/test-http-client-abort2.js b/test/simple/test-http-client-abort2.js new file mode 100644 index 00000000000..c0c995b91d4 --- /dev/null +++ b/test/simple/test-http-client-abort2.js @@ -0,0 +1,38 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); + +var server = http.createServer(function(req, res) { + res.end('Hello'); +}); + +server.listen(common.PORT, function() { + var req = http.get({port: common.PORT}, function(res) { + res.on('data', function(data) { + req.abort(); + server.close(); + }); + }); +}); + diff --git a/test/simple/test-tls-client-abort.js b/test/simple/test-tls-client-abort.js new file mode 100644 index 00000000000..8f10f0ff0ad --- /dev/null +++ b/test/simple/test-tls-client-abort.js @@ -0,0 +1,52 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +if (!process.versions.openssl) { + console.error("Skipping because node compiled without OpenSSL."); + process.exit(0); +} + +var common = require('../common'); +var assert = require('assert'); +var fs = require('fs'); +var tls = require('tls'); +var path = require('path'); + +(function() { + var cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); + var key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); + + var errorEmitted = false; + + process.on('exit', function() { + assert.ok(!errorEmitted); + }); + + var conn = tls.connect(common.PORT, {cert:cert, key:key}, function() { + assert.ok(false); // callback should never be executed + }); + conn.destroy(); + + conn.on('error', function() { + errorEmitted = true; + }); +})(); +