@@ -102,6 +102,8 @@ using v8::Promise;
102102using v8::PromiseRejectMessage;
103103using v8::PropertyCallbackInfo;
104104using v8::SealHandleScope;
105+ using v8::StackFrame;
106+ using v8::StackTrace;
105107using v8::String;
106108using v8::TryCatch;
107109using v8::Uint32;
@@ -113,6 +115,7 @@ static bool print_eval = false;
113115static bool force_repl = false ;
114116static bool trace_deprecation = false ;
115117static bool throw_deprecation = false ;
118+ static bool warn_on_sync = false ;
116119static bool abort_on_uncaught_exception = false ;
117120static const char * eval_string = nullptr ;
118121static unsigned int preload_module_count = 0 ;
@@ -1492,6 +1495,27 @@ static void ReportException(Environment* env, const TryCatch& try_catch) {
14921495}
14931496
14941497
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+
14951519// Executes a str within the current v8 context.
14961520static Local<Value> ExecuteString (Environment* env,
14971521 Handle<String> source,
@@ -2834,6 +2858,11 @@ void SetupProcessObject(Environment* env,
28342858 READONLY_PROPERTY (process, " traceDeprecation" , True (env->isolate ()));
28352859 }
28362860
2861+ // --warn-on-sync
2862+ if (warn_on_sync) {
2863+ READONLY_PROPERTY (process, " printOnSync" , True (env->isolate ()));
2864+ }
2865+
28372866 size_t exec_path_len = 2 * PATH_MAX;
28382867 char * exec_path = new char [exec_path_len];
28392868 Local<String> exec_path_value;
@@ -3180,6 +3209,8 @@ static void ParseArgs(int* argc,
31803209 no_deprecation = true ;
31813210 } else if (strcmp (arg, " --trace-deprecation" ) == 0 ) {
31823211 trace_deprecation = true ;
3212+ } else if (strcmp (arg, " --warn-on-sync" ) == 0 ) {
3213+ warn_on_sync = true ;
31833214 } else if (strcmp (arg, " --throw-deprecation" ) == 0 ) {
31843215 throw_deprecation = true ;
31853216 } else if (strcmp (arg, " --abort-on-uncaught-exception" ) == 0 ||
0 commit comments