-
Notifications
You must be signed in to change notification settings - Fork 31k
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
core: implement runtime flag to print warn on sync #1707
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,58 @@ | ||
#include "env.h" | ||
#include "env-inl.h" | ||
#include "v8.h" | ||
#include <stdio.h> | ||
|
||
namespace node { | ||
|
||
using v8::HandleScope; | ||
using v8::Local; | ||
using v8::Message; | ||
using v8::StackFrame; | ||
using v8::StackTrace; | ||
|
||
void Environment::PrintSyncTrace() const { | ||
if (!trace_sync_io_) | ||
return; | ||
|
||
HandleScope handle_scope(isolate()); | ||
Local<v8::StackTrace> stack = | ||
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed); | ||
|
||
fprintf(stderr, "WARNING: Detected use of sync API\n"); | ||
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. Probably should have the word «late» or words «after the first tick». 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 think that's pretty explicit in the fact that the flag now has the word "late". |
||
|
||
for (int i = 0; i < stack->GetFrameCount() - 1; i++) { | ||
Local<StackFrame> stack_frame = stack->GetFrame(i); | ||
node::Utf8Value fn_name_s(isolate(), stack_frame->GetFunctionName()); | ||
node::Utf8Value script_name(isolate(), stack_frame->GetScriptName()); | ||
const int line_number = stack_frame->GetLineNumber(); | ||
const int column = stack_frame->GetColumn(); | ||
|
||
if (stack_frame->IsEval()) { | ||
if (stack_frame->GetScriptId() == Message::kNoScriptIdInfo) { | ||
fprintf(stderr, " at [eval]:%i:%i\n", line_number, column); | ||
} else { | ||
fprintf(stderr, | ||
" at [eval] (%s:%i:%i)\n", | ||
*script_name, | ||
line_number, | ||
column); | ||
} | ||
break; | ||
} | ||
|
||
if (fn_name_s.length() == 0) { | ||
fprintf(stderr, " at %s:%i:%i\n", *script_name, line_number, column); | ||
} else { | ||
fprintf(stderr, | ||
" at %s (%s:%i:%i)\n", | ||
*fn_name_s, | ||
*script_name, | ||
line_number, | ||
column); | ||
} | ||
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.
|
||
} | ||
fflush(stderr); | ||
} | ||
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. What do you think about putting it here instead? |
||
|
||
} // namespace node |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const spawn = require('child_process').spawn; | ||
|
||
|
||
if (process.argv[2] === 'child') { | ||
setImmediate(function() { | ||
require('fs').readFileSync(__filename); | ||
process.exit(); | ||
}); | ||
|
||
} else { | ||
(function runTest(flags) { | ||
var execArgv = [flags.pop()]; | ||
var args = [__filename, 'child']; | ||
var child = spawn(process.execPath, execArgv.concat(args)); | ||
var cntr = 0; | ||
|
||
child.stdout.on('data', function(chunk) { | ||
throw new Error('UNREACHABLE'); | ||
}); | ||
|
||
child.stderr.on('data', function(chunk) { | ||
// Prints twice for --trace-sync-io. First for the require() and second | ||
// for the fs operation. | ||
if (/^WARNING[\s\S]*fs\.readFileSync/.test(chunk.toString())) | ||
cntr++; | ||
}); | ||
|
||
child.on('exit', function() { | ||
if (execArgv[0] === '--trace-sync-io') | ||
assert.equal(cntr, 2); | ||
else if (execArgv[0] === ' ') | ||
assert.equal(cntr, 0); | ||
else | ||
throw new Error('UNREACHABLE'); | ||
|
||
if (flags.length > 0) | ||
setImmediate(runTest, flags); | ||
}); | ||
}(['--trace-sync-io', ' '])); | ||
} | ||
|
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.
Three teeny tiny nits:
#include "foo.h"
for project-local includes?#include <stdio.h>
explicitly?using
directives inside the namespace for consistency?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.
done, done and done. thanks.