@@ -102,6 +102,8 @@ using v8::Promise;
102
102
using v8::PromiseRejectMessage;
103
103
using v8::PropertyCallbackInfo;
104
104
using v8::SealHandleScope;
105
+ using v8::StackFrame;
106
+ using v8::StackTrace;
105
107
using v8::String;
106
108
using v8::TryCatch;
107
109
using v8::Uint32;
@@ -113,6 +115,7 @@ static bool print_eval = false;
113
115
static bool force_repl = false ;
114
116
static bool trace_deprecation = false ;
115
117
static bool throw_deprecation = false ;
118
+ static bool warn_on_sync = false ;
116
119
static bool abort_on_uncaught_exception = false ;
117
120
static const char * eval_string = nullptr ;
118
121
static unsigned int preload_module_count = 0 ;
@@ -1492,6 +1495,27 @@ static void ReportException(Environment* env, const TryCatch& try_catch) {
1492
1495
}
1493
1496
1494
1497
1498
+ void PrintSyncWarning (Environment* env) {
1499
+ if (!warn_on_sync)
1500
+ return ;
1501
+
1502
+ Isolate* isolate = env->isolate ();
1503
+ HandleScope handle_scope (isolate);
1504
+ Local<StackTrace> stack = StackTrace::CurrentStackTrace (
1505
+ isolate, 10 , StackTrace::kDetailed );
1506
+
1507
+ fprintf (stderr, " WARNING: Detected use of sync API\n " );
1508
+ for (int i = 0 ; i < stack->GetFrameCount () - 1 ; i++) {
1509
+ Local<StackFrame> sf = stack->GetFrame (i);
1510
+ node::Utf8Value n (isolate, sf->GetFunctionName ());
1511
+ node::Utf8Value m (isolate, sf->GetScriptName ());
1512
+ int ln = sf->GetLineNumber ();
1513
+ int cl = sf->GetColumn ();
1514
+ fprintf (stderr, " at %s (%s:%i:%i)\n " , *n, *m, ln, cl);
1515
+ }
1516
+ }
1517
+
1518
+
1495
1519
// Executes a str within the current v8 context.
1496
1520
static Local<Value> ExecuteString (Environment* env,
1497
1521
Handle <String> source,
@@ -2834,6 +2858,11 @@ void SetupProcessObject(Environment* env,
2834
2858
READONLY_PROPERTY (process, " traceDeprecation" , True (env->isolate ()));
2835
2859
}
2836
2860
2861
+ // --warn-on-sync
2862
+ if (warn_on_sync) {
2863
+ READONLY_PROPERTY (process, " printOnSync" , True (env->isolate ()));
2864
+ }
2865
+
2837
2866
size_t exec_path_len = 2 * PATH_MAX;
2838
2867
char * exec_path = new char [exec_path_len];
2839
2868
Local<String> exec_path_value;
@@ -3180,6 +3209,8 @@ static void ParseArgs(int* argc,
3180
3209
no_deprecation = true ;
3181
3210
} else if (strcmp (arg, " --trace-deprecation" ) == 0 ) {
3182
3211
trace_deprecation = true ;
3212
+ } else if (strcmp (arg, " --warn-on-sync" ) == 0 ) {
3213
+ warn_on_sync = true ;
3183
3214
} else if (strcmp (arg, " --throw-deprecation" ) == 0 ) {
3184
3215
throw_deprecation = true ;
3185
3216
} else if (strcmp (arg, " --abort-on-uncaught-exception" ) == 0 ||
0 commit comments