Skip to content

Commit

Permalink
http2: move process.binding('http2') to internalBinding
Browse files Browse the repository at this point in the history
Refs: #22160

PR-URL: #22328
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
  • Loading branch information
jasnell committed Aug 18, 2018
1 parent c7788fb commit 4fa5448
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 17 deletions.
3 changes: 2 additions & 1 deletion lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

const { internalBinding } = require('internal/bootstrap/loaders');
const Stream = require('stream');
const Readable = Stream.Readable;
const binding = process.binding('http2');
const binding = internalBinding('http2');
const constants = binding.constants;
const {
ERR_HTTP2_HEADERS_SENT,
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {

assertCrypto();

const { internalBinding } = require('internal/bootstrap/loaders');
const assert = require('assert');
const EventEmitter = require('events');
const fs = require('fs');
Expand All @@ -31,7 +32,6 @@ const {
owner_symbol,
},
} = require('internal/async_hooks');
const { internalBinding } = require('internal/bootstrap/loaders');
const {
codes: {
ERR_HTTP2_ALTSVC_INVALID_ORIGIN,
Expand Down Expand Up @@ -114,7 +114,7 @@ const {
const { isArrayBufferView } = require('internal/util/types');

const { FileHandle } = process.binding('fs');
const binding = process.binding('http2');
const binding = internalBinding('http2');
const { ShutdownWrap } = process.binding('stream_wrap');
const { UV_EOF } = internalBinding('uv');

Expand Down
3 changes: 2 additions & 1 deletion lib/internal/http2/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const binding = process.binding('http2');
const { internalBinding } = require('internal/bootstrap/loaders');
const binding = internalBinding('http2');
const {
ERR_HTTP2_HEADER_SINGLE_VALUE,
ERR_HTTP2_INVALID_CONNECTION_HEADERS,
Expand Down
5 changes: 3 additions & 2 deletions lib/perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ let sessionStats;
let streamStats;

function collectHttp2Stats(entry) {
const http2 = internalBinding('http2');
switch (entry.name) {
case 'Http2Stream':
if (streamStats === undefined)
streamStats = process.binding('http2').streamStats;
streamStats = http2.streamStats;
entry.id =
streamStats[IDX_STREAM_STATS_ID] >>> 0;
entry.timeToFirstByte =
Expand All @@ -99,7 +100,7 @@ function collectHttp2Stats(entry) {
break;
case 'Http2Session':
if (sessionStats === undefined)
sessionStats = process.binding('http2').sessionStats;
sessionStats = http2.sessionStats;
entry.type =
sessionStats[IDX_SESSION_STATS_TYPE] >>> 0 === 0 ? 'server' : 'client';
entry.pingRTT =
Expand Down
2 changes: 1 addition & 1 deletion src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2999,4 +2999,4 @@ HTTP_STATUS_CODES(V)
} // namespace http2
} // namespace node

NODE_BUILTIN_MODULE_CONTEXT_AWARE(http2, node::http2::Initialize)
NODE_MODULE_CONTEXT_AWARE_INTERNAL(http2, node::http2::Initialize)
4 changes: 3 additions & 1 deletion test/parallel/test-http2-binding.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const { internalBinding } = require('internal/test/binding');

const binding = process.binding('http2');
const binding = internalBinding('http2');
const http2 = require('http2');

assert(binding.Http2Session);
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http2-client-onconnect-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const { internalBinding } = require('internal/test/binding');
const {
constants,
Http2Session,
nghttp2ErrorString
} = process.binding('http2');
} = internalBinding('http2');
const http2 = require('http2');
const { NghttpError } = require('internal/http2/util');

Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http2-info-headers-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const { internalBinding } = require('internal/test/binding');
const {
constants,
Http2Stream,
nghttp2ErrorString
} = process.binding('http2');
} = internalBinding('http2');
const { NghttpError } = require('internal/http2/util');

// tests error handling within additionalHeaders
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http2-respond-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const { Http2Stream } = process.binding('http2');
const { internalBinding } = require('internal/test/binding');
const { Http2Stream } = internalBinding('http2');

const server = http2.createServer();

Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http2-respond-nghttperrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const { internalBinding } = require('internal/test/binding');
const {
constants,
Http2Stream,
nghttp2ErrorString
} = process.binding('http2');
} = internalBinding('http2');
const { NghttpError } = require('internal/http2/util');

// tests error handling within respond
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http2-respond-with-fd-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ const fixtures = require('../common/fixtures');

const http2 = require('http2');

const { internalBinding } = require('internal/test/binding');
const {
constants,
Http2Stream,
nghttp2ErrorString
} = process.binding('http2');
} = internalBinding('http2');
const { NghttpError } = require('internal/http2/util');

// tests error handling within processRespondWithFD
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http2-server-push-stream-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const { internalBinding } = require('internal/test/binding');
const {
constants,
Http2Stream,
nghttp2ErrorString
} = process.binding('http2');
} = internalBinding('http2');
const { NghttpError } = require('internal/http2/util');

// tests error handling within pushStream
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http2-util-headers-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const { mapToHeaders, toHeaderObject } = require('internal/http2/util');

const { internalBinding } = require('internal/test/binding');
const {
HTTP2_HEADER_STATUS,
HTTP2_HEADER_METHOD,
Expand Down Expand Up @@ -88,7 +88,7 @@ const {
HTTP2_HEADER_HOST,
HTTP2_HEADER_KEEP_ALIVE,
HTTP2_HEADER_PROXY_CONNECTION
} = process.binding('http2').constants;
} = internalBinding('http2').constants;

{
const headers = {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http2-util-update-options-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ if (!common.hasCrypto)
// by the http2 implementation.

const { updateOptionsBuffer } = require('internal/http2/util');
const { optionsBuffer } = process.binding('http2');
const { internalBinding } = require('internal/test/binding');
const { optionsBuffer } = internalBinding('http2');
const { ok, strictEqual } = require('assert');

const IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE = 0;
Expand Down

0 comments on commit 4fa5448

Please sign in to comment.