Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Merge nodejs/master
Browse files Browse the repository at this point in the history
Merge fca31be as of 2017-10-09.
This is an automatically created merge. For any problems please
contact @kunalspathak.
  • Loading branch information
chakrabot authored and jackhorton committed Oct 11, 2017
2 parents 6616b34 + fca31be commit 12cb6ee
Show file tree
Hide file tree
Showing 68 changed files with 443 additions and 330 deletions.
7 changes: 5 additions & 2 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ On macOS you will need to install the `Xcode Command Line Tools` by running
installed, you can find them under the menu `Xcode -> Open Developer Tool ->
More Developer Tools...`. This step will install `clang`, `clang++`, and
`make`.
* You may want to setup [firewall rules](tools/macosx-firewall.sh)
* After building, you may want to setup [firewall rules](tools/macosx-firewall.sh)
to avoid popups asking to accept incoming network connections when running tests:

If the path to your build directory contains a space, the build will likely fail.
Expand Down Expand Up @@ -126,6 +126,9 @@ To run the tests:
$ make test
```

At this point you are ready to make code changes and re-run the tests!
Optionally, continue below.

To run the tests and generate code coverage reports:

```console
Expand All @@ -142,7 +145,7 @@ and overwrites the `lib/` directory. To clean up after generating the coverage
reports:

```console
make coverage-clean
$ make coverage-clean
```

To build the documentation:
Expand Down
7 changes: 7 additions & 0 deletions doc/guides/writing-and-running-benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [Running all benchmarks](#running-all-benchmarks)
* [Comparing Node.js versions](#comparing-nodejs-versions)
* [Comparing parameters](#comparing-parameters)
* [Running Benchmarks on the CI](#running-benchmarks-on-the-ci)
* [Creating a benchmark](#creating-a-benchmark)
* [Basics of a benchmark](#basics-of-a-benchmark)
* [Creating an HTTP benchmark](#creating-an-http-benchmark)
Expand Down Expand Up @@ -298,6 +299,11 @@ chunk encoding mean confidence.interval

![compare tool boxplot](doc_img/scatter-plot.png)

### Running Benchmarks on the CI

To see the performance impact of a Pull Request by running benchmarks on
the CI, check out [How to: Running core benchmarks on Node.js CI][benchmark-ci].

## Creating a benchmark

### Basics of a benchmark
Expand Down Expand Up @@ -432,3 +438,4 @@ Supported options keys are:
[t-test]: https://en.wikipedia.org/wiki/Student%27s_t-test#Equal_or_unequal_sample_sizes.2C_unequal_variances
[git-for-windows]: http://git-scm.com/download/win
[nghttp2.org]: http://nghttp2.org
[benchmark-ci]: https://github.com/nodejs/benchmarking/blob/master/docs/core_benchmarks.md
5 changes: 5 additions & 0 deletions doc/onboarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ onboarding session.
* [https://github.com/nodejs/readable-stream](https://github.com/nodejs/readable-stream)
* [https://github.com/nodejs/LTS](https://github.com/nodejs/LTS)
* [https://github.com/nodejs/citgm](https://github.com/nodejs/citgm)
* The Node.js Foundation hosts regular summits for active contributors to the Node.js
project, where we have face-to-face discussion about our work on the project.
The foundation has travel funds to cover participants' expenses including
accommodation, transportation, visa fees etc. if needed. Check out the
[summit](https://github.com/nodejs/summit) repository for details.

[Code of Conduct]: https://github.com/nodejs/TSC/blob/master/CODE_OF_CONDUCT.md
[`core-validate-commit`]: https://github.com/evanlucas/core-validate-commit
Expand Down
70 changes: 58 additions & 12 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,69 @@ const {
} = require('internal/crypto/util');
const Certificate = require('internal/crypto/certificate');

// These helper functions are needed because the constructors can
// use new, in which case V8 cannot inline the recursive constructor call
function createHash(algorithm, options) {
return new Hash(algorithm, options);
}

function createCipher(cipher, password, options) {
return new Cipher(cipher, password, options);
}

function createCipheriv(cipher, key, iv, options) {
return new Cipheriv(cipher, key, iv, options);
}

function createDecipher(cipher, password, options) {
return new Decipher(cipher, password, options);
}

function createDecipheriv(cipher, key, iv, options) {
return new Decipheriv(cipher, key, iv, options);
}

function createDiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) {
return new DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding);
}

function createDiffieHellmanGroup(name) {
return new DiffieHellmanGroup(name);
}

function createECDH(curve) {
return new ECDH(curve);
}

function createHmac(hmac, key, options) {
return new Hmac(hmac, key, options);
}

function createSign(algorithm, options) {
return new Sign(algorithm, options);
}

function createVerify(algorithm, options) {
return new Verify(algorithm, options);
}

module.exports = exports = {
// Methods
_toBuf: toBuf,
createCipher: Cipher,
createCipheriv: Cipheriv,
createDecipher: Decipher,
createDecipheriv: Decipheriv,
createDiffieHellman: DiffieHellman,
createDiffieHellmanGroup: DiffieHellmanGroup,
createECDH: ECDH,
createHash: Hash,
createHmac: Hmac,
createSign: Sign,
createVerify: Verify,
createCipher,
createCipheriv,
createDecipher,
createDecipheriv,
createDiffieHellman,
createDiffieHellmanGroup,
createECDH,
createHash,
createHmac,
createSign,
createVerify,
getCiphers,
getCurves,
getDiffieHellman: DiffieHellmanGroup,
getDiffieHellman: createDiffieHellmanGroup,
getHashes,
pbkdf2,
pbkdf2Sync,
Expand Down
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,

HandleScope handle_scope(env->isolate());
// If you hit this assertion, you forgot to enter the v8::Context first.
CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());
CHECK_EQ(Environment::GetCurrent(env->isolate()), env);

if (env->using_domains() && !object_.IsEmpty()) {
DomainEnter(env, object_);
Expand Down
31 changes: 9 additions & 22 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ TLSWrap::TLSWrap(Environment* env,
started_(false),
established_(false),
shutdown_(false),
error_(nullptr),
cycle_depth_(0),
eof_(false) {
node::Wrap(object(), this);
Expand Down Expand Up @@ -103,8 +102,6 @@ TLSWrap::~TLSWrap() {
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
sni_context_.Reset();
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB

ClearError();
}


Expand Down Expand Up @@ -367,7 +364,7 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) {
}


Local<Value> TLSWrap::GetSSLError(int status, int* err, const char** msg) {
Local<Value> TLSWrap::GetSSLError(int status, int* err, std::string* msg) {
EscapableHandleScope scope(env()->isolate());

// ssl_ is already destroyed in reading EOF by close notify alert.
Expand Down Expand Up @@ -398,13 +395,9 @@ Local<Value> TLSWrap::GetSSLError(int status, int* err, const char** msg) {
OneByteString(env()->isolate(), mem->data, mem->length);
Local<Value> exception = Exception::Error(message);

if (msg != nullptr) {
CHECK_EQ(*msg, nullptr);
char* const buf = new char[mem->length + 1];
memcpy(buf, mem->data, mem->length);
buf[mem->length] = '\0';
*msg = buf;
}
if (msg != nullptr)
msg->assign(mem->data, mem->data + mem->length);

BIO_free_all(bio);

return scope.Escape(exception);
Expand Down Expand Up @@ -516,12 +509,11 @@ bool TLSWrap::ClearIn() {

// Error or partial write
int err;
const char* error_str = nullptr;
std::string error_str;
Local<Value> arg = GetSSLError(written, &err, &error_str);
if (!arg.IsEmpty()) {
MakePending();
InvokeQueued(UV_EPROTO, error_str);
delete[] error_str;
InvokeQueued(UV_EPROTO, error_str.c_str());
clear_in_->Reset();
}

Expand Down Expand Up @@ -570,13 +562,12 @@ int TLSWrap::ReadStop() {


const char* TLSWrap::Error() const {
return error_;
return error_.empty() ? nullptr : error_.c_str();
}


void TLSWrap::ClearError() {
delete[] error_;
error_ = nullptr;
error_.clear();
}


Expand Down Expand Up @@ -624,11 +615,7 @@ int TLSWrap::DoWrite(WriteWrap* w,

if (ssl_ == nullptr) {
ClearError();

static char msg[] = "Write after DestroySSL";
char* tmp = new char[sizeof(msg)];
memcpy(tmp, msg, sizeof(msg));
error_ = tmp;
error_ = "Write after DestroySSL";
return UV_EPROTO;
}

Expand Down
7 changes: 4 additions & 3 deletions src/tls_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

#include <openssl/ssl.h>

#include <string>

namespace node {

// Forward-declarations
Expand Down Expand Up @@ -148,8 +150,7 @@ class TLSWrap : public AsyncWrap,

void DoRead(ssize_t nread, const uv_buf_t* buf, uv_handle_type pending);

// If |msg| is not nullptr, caller is responsible for calling `delete[] *msg`.
v8::Local<v8::Value> GetSSLError(int status, int* err, const char** msg);
v8::Local<v8::Value> GetSSLError(int status, int* err, std::string* msg);

static void OnClientHelloParseEnd(void* arg);
static void Wrap(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down Expand Up @@ -180,7 +181,7 @@ class TLSWrap : public AsyncWrap,
bool started_;
bool established_;
bool shutdown_;
const char* error_;
std::string error_;
int cycle_depth_;

// If true - delivered EOF to the js-land, either after `close_notify`, or
Expand Down
32 changes: 10 additions & 22 deletions test/addons-napi/test_error/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,34 @@ class MyError extends Error { }
const myError = new MyError('Some MyError');

// Test that native error object is correctly classed
assert.strictEqual(test_error.checkError(theError), true,
'Error object correctly classed by napi_is_error');
assert.strictEqual(test_error.checkError(theError), true);

// Test that native type error object is correctly classed
assert.strictEqual(test_error.checkError(theTypeError), true,
'Type error object correctly classed by napi_is_error');
assert.strictEqual(test_error.checkError(theTypeError), true);

// Test that native syntax error object is correctly classed
assert.strictEqual(test_error.checkError(theSyntaxError), true,
'Syntax error object correctly classed by napi_is_error');
assert.strictEqual(test_error.checkError(theSyntaxError), true);

// Test that native range error object is correctly classed
assert.strictEqual(test_error.checkError(theRangeError), true,
'Range error object correctly classed by napi_is_error');
assert.strictEqual(test_error.checkError(theRangeError), true);

// Test that native reference error object is correctly classed
assert.strictEqual(test_error.checkError(theReferenceError), true,
'Reference error object correctly classed by' +
' napi_is_error');
assert.strictEqual(test_error.checkError(theReferenceError), true);

// Test that native URI error object is correctly classed
assert.strictEqual(test_error.checkError(theURIError), true,
'URI error object correctly classed by napi_is_error');
assert.strictEqual(test_error.checkError(theURIError), true);

// Test that native eval error object is correctly classed
assert.strictEqual(test_error.checkError(theEvalError), true,
'Eval error object correctly classed by napi_is_error');
assert.strictEqual(test_error.checkError(theEvalError), true);

// Test that class derived from native error is correctly classed
assert.strictEqual(test_error.checkError(myError), true,
'Class derived from native error correctly classed by' +
' napi_is_error');
assert.strictEqual(test_error.checkError(myError), true);

// Test that non-error object is correctly classed
assert.strictEqual(test_error.checkError({}), false,
'Non-error object correctly classed by napi_is_error');
assert.strictEqual(test_error.checkError({}), false);

// Test that non-error primitive is correctly classed
assert.strictEqual(test_error.checkError('non-object'), false,
'Non-error primitive correctly classed by napi_is_error');
assert.strictEqual(test_error.checkError('non-object'), false);

assert.throws(() => {
test_error.throwExistingError();
Expand Down
Loading

0 comments on commit 12cb6ee

Please sign in to comment.