-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
src: add /json/protocol endpoint to inspector #7491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Flags: --inspect={PORT} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had not seen this syntax before... specifically not with the Is this documented anywhere? Should it be I'm assuming I am wrong here, just curious There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nvm... I am seeing that it is included below. sorry for noise |
||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const options = { | ||
path: '/json/protocol', | ||
port: common.PORT, | ||
host: common.localhostIPv4, | ||
}; | ||
|
||
http.get(options, common.mustCall((res) => { | ||
let body = ''; | ||
res.setEncoding('utf8'); | ||
res.on('data', (data) => body += data); | ||
res.on('end', common.mustCall(() => { | ||
assert(body.length > 0); | ||
assert.deepStrictEqual(JSON.stringify(JSON.parse(body)), body); | ||
})); | ||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,10 @@ def GetCommand(self): | |
source = open(self.file).read() | ||
flags_match = FLAGS_PATTERN.search(source) | ||
if flags_match: | ||
result += flags_match.group(1).strip().split() | ||
# PORT should match the definition in test/common.js. | ||
env = { 'PORT': int(os.getenv('NODE_COMMON_PORT', '12346')) } | ||
env['PORT'] += self.thread_id * 100 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't make it up, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, sorry, didn’t see that value is changed later in test/common.js. |
||
result += flags_match.group(1).strip().format(**env).split() | ||
files_match = FILES_PATTERN.search(source); | ||
additional_files = [] | ||
if files_match: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python | ||
|
||
import json | ||
import struct | ||
import sys | ||
import zlib | ||
|
||
if __name__ == '__main__': | ||
fp = open(sys.argv[1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if important for this kind of script, but fp is not explicitly closed. Since we depend on 2.6-2.7, maybe use a with statement instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script is short-lived so I went for simplicity. |
||
obj = json.load(fp) | ||
text = json.dumps(obj, separators=(',', ':')) | ||
data = zlib.compress(text, zlib.Z_BEST_COMPRESSION) | ||
|
||
# To make decompression a little easier, we prepend the compressed data | ||
# with the size of the uncompressed data as a 24 bits BE unsigned integer. | ||
assert len(text) < 1 << 24, 'Uncompressed JSON must be < 16 MB.' | ||
data = struct.pack('>I', len(text))[1:4] + data | ||
|
||
step = 20 | ||
slices = (data[i:i+step] for i in xrange(0, len(data), step)) | ||
slices = map(lambda s: ','.join(str(ord(c)) for c in s), slices) | ||
text = ',\n'.join(slices) | ||
|
||
fp = open(sys.argv[2], 'w') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
fp.write(text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: is there a reason for the inconsistent indent between this and the two lines above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous line is a continuation of the one before it. Note how the first line doesn't have a comma at the end.