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

Commit

Permalink
meta: merge node/master into node-chakracore/master
Browse files Browse the repository at this point in the history
Merge d2626ef as of 2017-12-10
This commit was automatically generated. For any problems, please contact jackhorton

Reviewed-By: Taylor Woll <tawoll@ntdev.microsoft.com>
  • Loading branch information
chakrabot committed Jan 17, 2018
2 parents f6a4546 + d2626ef commit d48f231
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 101 deletions.
8 changes: 3 additions & 5 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,13 @@ be written:
import url from 'url';
import path from 'path';
import process from 'process';
import Module from 'module';

const builtins = new Set(
Object.keys(process.binding('natives')).filter((str) =>
/^(?!(?:internal|node|v8)\/)/.test(str))
);
const builtins = Module.builtinModules;
const JS_EXTENSIONS = new Set(['.js', '.mjs']);

export function resolve(specifier, parentModuleURL/*, defaultResolve */) {
if (builtins.has(specifier)) {
if (builtins.includes(specifier)) {
return {
url: specifier,
format: 'builtin'
Expand Down
6 changes: 2 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,8 @@ function formatValue(ctx, value, recurseTimes, ln) {
}

function formatNumber(fn, value) {
// Format -0 as '-0'. A `value === -0` check won't distinguish 0 from -0.
// Using a division check is currently faster than `Object.is(value, -0)`
// as of V8 6.1.
if (1 / value === -Infinity)
// Format -0 as '-0'. Checking `value === -0` won't distinguish 0 from -0.
if (Object.is(value, -0))
return fn('-0', 'number');
return fn(`${value}`, 'number');
}
Expand Down
3 changes: 3 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,9 @@
'defines': [
'HAVE_OPENSSL=1',
],
'defines': [
'HAVE_OPENSSL=1',
],
}],
['v8_enable_inspector==1', {
'sources': [
Expand Down
130 changes: 58 additions & 72 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@
// StartComAndWoSignData.inc
#include "StartComAndWoSignData.inc"

#include <algorithm>
#include <errno.h>
#include <limits.h> // INT_MAX
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

#define THROW_AND_RETURN_IF_NOT_BUFFER(val, prefix) \
do { \
Expand Down Expand Up @@ -421,44 +423,33 @@ void ThrowCryptoError(Environment* env,
Local<Value> exception_v = Exception::Error(message);
CHECK(!exception_v.IsEmpty());
Local<Object> exception = exception_v.As<Object>();
ERR_STATE* es = ERR_get_state();

if (es->bottom != es->top) {
Local<Array> error_stack = Array::New(env->isolate());
int top = es->top;

// Build the error_stack array to be added to opensslErrorStack property.
for (unsigned int i = 0; es->bottom != es->top;) {
unsigned long err_buf = es->err_buffer[es->top]; // NOLINT(runtime/int)
// Only add error string if there is valid err_buffer.
if (err_buf) {
char tmp_str[256];
ERR_error_string_n(err_buf, tmp_str, sizeof(tmp_str));
error_stack->Set(env->context(), i,
String::NewFromUtf8(env->isolate(), tmp_str,
v8::NewStringType::kNormal)
.ToLocalChecked()).FromJust();
// Only increment if we added to error_stack.
i++;
}

// Since the ERR_STATE is a ring buffer, we need to use modular
// arithmetic to loop back around in the case where bottom is after top.
// Using ERR_NUM_ERRORS macro defined in openssl.
es->top = (((es->top - 1) % ERR_NUM_ERRORS) + ERR_NUM_ERRORS) %
ERR_NUM_ERRORS;
std::vector<Local<String>> errors;
for (;;) {
unsigned long err = ERR_get_error(); // NOLINT(runtime/int)
if (err == 0) {
break;
}

// Restore top.
es->top = top;

// Add the opensslErrorStack property to the exception object.
// The new property will look like the following:
// opensslErrorStack: [
// 'error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib',
// 'error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 err'
// ]
exception->Set(env->context(), env->openssl_error_stack(), error_stack)
char tmp_str[256];
ERR_error_string_n(err, tmp_str, sizeof(tmp_str));
errors.push_back(String::NewFromUtf8(env->isolate(), tmp_str,
v8::NewStringType::kNormal)
.ToLocalChecked());
}

// ERR_get_error returns errors in order of most specific to least
// specific. We wish to have the reverse ordering:
// opensslErrorStack: [
// 'error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib',
// 'error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 err'
// ]
if (!errors.empty()) {
std::reverse(errors.begin(), errors.end());
Local<Array> errors_array = Array::New(env->isolate(), errors.size());
for (size_t i = 0; i < errors.size(); i++) {
errors_array->Set(env->context(), i, errors[i]).FromJust();
}
exception->Set(env->context(), env->openssl_error_stack(), errors_array)
.FromJust();
}

Expand Down Expand Up @@ -517,34 +508,29 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext");
t->SetClassName(secureContextString);

env->SetProtoMethod(t, "init", SecureContext::Init);
env->SetProtoMethod(t, "setKey", SecureContext::SetKey);
env->SetProtoMethod(t, "setCert", SecureContext::SetCert);
env->SetProtoMethod(t, "addCACert", SecureContext::AddCACert);
env->SetProtoMethod(t, "addCRL", SecureContext::AddCRL);
env->SetProtoMethod(t, "addRootCerts", SecureContext::AddRootCerts);
env->SetProtoMethod(t, "setCiphers", SecureContext::SetCiphers);
env->SetProtoMethod(t, "setECDHCurve", SecureContext::SetECDHCurve);
env->SetProtoMethod(t, "setDHParam", SecureContext::SetDHParam);
env->SetProtoMethod(t, "setOptions", SecureContext::SetOptions);
env->SetProtoMethod(t, "setSessionIdContext",
SecureContext::SetSessionIdContext);
env->SetProtoMethod(t, "setSessionTimeout",
SecureContext::SetSessionTimeout);
env->SetProtoMethod(t, "close", SecureContext::Close);
env->SetProtoMethod(t, "loadPKCS12", SecureContext::LoadPKCS12);
env->SetProtoMethod(t, "init", Init);
env->SetProtoMethod(t, "setKey", SetKey);
env->SetProtoMethod(t, "setCert", SetCert);
env->SetProtoMethod(t, "addCACert", AddCACert);
env->SetProtoMethod(t, "addCRL", AddCRL);
env->SetProtoMethod(t, "addRootCerts", AddRootCerts);
env->SetProtoMethod(t, "setCiphers", SetCiphers);
env->SetProtoMethod(t, "setECDHCurve", SetECDHCurve);
env->SetProtoMethod(t, "setDHParam", SetDHParam);
env->SetProtoMethod(t, "setOptions", SetOptions);
env->SetProtoMethod(t, "setSessionIdContext", SetSessionIdContext);
env->SetProtoMethod(t, "setSessionTimeout", SetSessionTimeout);
env->SetProtoMethod(t, "close", Close);
env->SetProtoMethod(t, "loadPKCS12", LoadPKCS12);
#ifndef OPENSSL_NO_ENGINE
env->SetProtoMethod(t, "setClientCertEngine",
SecureContext::SetClientCertEngine);
env->SetProtoMethod(t, "setClientCertEngine", SetClientCertEngine);
#endif // !OPENSSL_NO_ENGINE
env->SetProtoMethod(t, "getTicketKeys", SecureContext::GetTicketKeys);
env->SetProtoMethod(t, "setTicketKeys", SecureContext::SetTicketKeys);
env->SetProtoMethod(t, "setFreeListLength", SecureContext::SetFreeListLength);
env->SetProtoMethod(t,
"enableTicketKeyCallback",
SecureContext::EnableTicketKeyCallback);
env->SetProtoMethod(t, "getCertificate", SecureContext::GetCertificate<true>);
env->SetProtoMethod(t, "getIssuer", SecureContext::GetCertificate<false>);
env->SetProtoMethod(t, "getTicketKeys", GetTicketKeys);
env->SetProtoMethod(t, "setTicketKeys", SetTicketKeys);
env->SetProtoMethod(t, "setFreeListLength", SetFreeListLength);
env->SetProtoMethod(t, "enableTicketKeyCallback", EnableTicketKeyCallback);
env->SetProtoMethod(t, "getCertificate", GetCertificate<true>);
env->SetProtoMethod(t, "getIssuer", GetCertificate<false>);

t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kTicketKeyReturnIndex"),
Integer::NewFromUnsigned(env->isolate(), kTicketKeyReturnIndex));
Expand Down Expand Up @@ -3017,21 +3003,21 @@ void Connection::Initialize(Environment* env, Local<Object> target) {
t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Connection"));

AsyncWrap::AddWrapMethods(env, t);
env->SetProtoMethod(t, "encIn", Connection::EncIn);
env->SetProtoMethod(t, "clearOut", Connection::ClearOut);
env->SetProtoMethod(t, "clearIn", Connection::ClearIn);
env->SetProtoMethod(t, "encOut", Connection::EncOut);
env->SetProtoMethod(t, "clearPending", Connection::ClearPending);
env->SetProtoMethod(t, "encPending", Connection::EncPending);
env->SetProtoMethod(t, "start", Connection::Start);
env->SetProtoMethod(t, "close", Connection::Close);
env->SetProtoMethod(t, "encIn", EncIn);
env->SetProtoMethod(t, "clearOut", ClearOut);
env->SetProtoMethod(t, "clearIn", ClearIn);
env->SetProtoMethod(t, "encOut", EncOut);
env->SetProtoMethod(t, "clearPending", ClearPending);
env->SetProtoMethod(t, "encPending", EncPending);
env->SetProtoMethod(t, "start", Start);
env->SetProtoMethod(t, "close", Close);

SSLWrap<Connection>::AddMethods(env, t);


#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
env->SetProtoMethod(t, "getServername", Connection::GetServername);
env->SetProtoMethod(t, "setSNICallback", Connection::SetSNICallback);
env->SetProtoMethod(t, "getServername", GetServername);
env->SetProtoMethod(t, "setSNICallback", SetSNICallback);
#endif

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Connection"),
Expand Down
22 changes: 5 additions & 17 deletions test/parallel/test-http-timeout-overflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const assert = require('assert');

const common = require('../common');
const http = require('http');

let serverRequests = 0;
let clientRequests = 0;

const server = http.createServer(function(req, res) {
serverRequests++;
const server = http.createServer(common.mustCall(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('OK');
});
}));

server.listen(0, function() {
function callback() {}
Expand All @@ -44,10 +38,9 @@ server.listen(0, function() {
}, function(res) {
req.clearTimeout(callback);

res.on('end', function() {
clientRequests++;
res.on('end', common.mustCall(function() {
server.close();
});
}));

res.resume();
});
Expand All @@ -56,8 +49,3 @@ server.listen(0, function() {
req.setTimeout(0xffffffff, callback);
req.end();
});

process.once('exit', function() {
assert.strictEqual(clientRequests, 1);
assert.strictEqual(serverRequests, 1);
});
10 changes: 7 additions & 3 deletions test/parallel/test-repl-reset-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ common.globalCheck = false;

const assert = require('assert');
const repl = require('repl');
const util = require('util');

// Create a dummy stream that does nothing
const dummy = new common.ArrayStream();
Expand All @@ -38,11 +39,13 @@ function testReset(cb) {
r.context.foo = 42;
r.on('reset', common.mustCall(function(context) {
assert(!!context, 'REPL did not emit a context with reset event');
assert.strictEqual(context, r.context, 'REPL emitted incorrect context');
assert.strictEqual(context, r.context, 'REPL emitted incorrect context. ' +
`context is ${util.inspect(context)}, expected ${util.inspect(r.context)}`);
assert.strictEqual(
context.foo,
undefined,
'REPL emitted the previous context, and is not using global as context'
'REPL emitted the previous context and is not using global as context. ' +
`context.foo is ${context.foo}, expected undefined.`
);
context.foo = 42;
cb();
Expand All @@ -61,7 +64,8 @@ function testResetGlobal() {
assert.strictEqual(
context.foo,
42,
'"foo" property is missing from REPL using global as context'
'"foo" property is different from REPL using global as context. ' +
`context.foo is ${context.foo}, expected 42.`
);
}));
r.resetContext();
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ assert.strictEqual(util.inspect(arr3), "[ '-1': -1 ]");
// test positive/negative zero
assert.strictEqual(util.inspect(0), '0');
assert.strictEqual(util.inspect(-0), '-0');
// edge case from check
assert.strictEqual(util.inspect(-5e-324), '-5e-324');

// test for sparse array
{
Expand Down

0 comments on commit d48f231

Please sign in to comment.