@@ -1412,6 +1412,8 @@ void Isolate::InvokeApiInterruptCallbacks() {
1412
1412
}
1413
1413
}
1414
1414
1415
+ namespace {
1416
+
1415
1417
void ReportBootstrappingException (Handle <Object> exception ,
1416
1418
MessageLocation* location) {
1417
1419
base::OS::PrintError (" Exception thrown during bootstrapping\n " );
@@ -1467,6 +1469,36 @@ void ReportBootstrappingException(Handle<Object> exception,
1467
1469
#endif
1468
1470
}
1469
1471
1472
+ } // anonymous namespace
1473
+
1474
+ Handle <JSMessageObject> Isolate::CreateMessageOrAbort (
1475
+ Handle <Object> exception , MessageLocation* location) {
1476
+ Handle <JSMessageObject> message_obj = CreateMessage (exception , location);
1477
+
1478
+ // If the abort-on-uncaught-exception flag is specified, and if the
1479
+ // embedder didn't specify a custom uncaught exception callback,
1480
+ // or if the custom callback determined that V8 should abort, then
1481
+ // abort.
1482
+ if (FLAG_abort_on_uncaught_exception) {
1483
+ CatchType prediction = PredictExceptionCatcher ();
1484
+ if ((prediction == NOT_CAUGHT || prediction == CAUGHT_BY_EXTERNAL) &&
1485
+ (!abort_on_uncaught_exception_callback_ ||
1486
+ abort_on_uncaught_exception_callback_ (
1487
+ reinterpret_cast <v8::Isolate*>(this )))) {
1488
+ // Prevent endless recursion.
1489
+ FLAG_abort_on_uncaught_exception = false ;
1490
+ // This flag is intended for use by JavaScript developers, so
1491
+ // print a user-friendly stack trace (not an internal one).
1492
+ PrintF (stderr, " %s\n\n FROM\n " ,
1493
+ MessageHandler::GetLocalizedMessage (this , message_obj).get ());
1494
+ PrintCurrentStackTrace (stderr);
1495
+ base::OS::Abort ();
1496
+ }
1497
+ }
1498
+
1499
+ return message_obj;
1500
+ }
1501
+
1470
1502
Object Isolate::Throw (Object raw_exception, MessageLocation* location) {
1471
1503
DCHECK (!has_pending_exception ());
1472
1504
@@ -1538,38 +1570,14 @@ Object Isolate::Throw(Object raw_exception, MessageLocation* location) {
1538
1570
if (location == nullptr && ComputeLocation (&computed_location)) {
1539
1571
location = &computed_location;
1540
1572
}
1541
-
1542
1573
if (bootstrapper ()->IsActive ()) {
1543
1574
// It's not safe to try to make message objects or collect stack traces
1544
1575
// while the bootstrapper is active since the infrastructure may not have
1545
1576
// been properly initialized.
1546
1577
ReportBootstrappingException (exception , location);
1547
1578
} else {
1548
- Handle <Object> message_obj = CreateMessage (exception , location);
1579
+ Handle <Object> message_obj = CreateMessageOrAbort (exception , location);
1549
1580
thread_local_top ()->pending_message_obj_ = *message_obj;
1550
-
1551
- // For any exception not caught by JavaScript, even when an external
1552
- // handler is present:
1553
- // If the abort-on-uncaught-exception flag is specified, and if the
1554
- // embedder didn't specify a custom uncaught exception callback,
1555
- // or if the custom callback determined that V8 should abort, then
1556
- // abort.
1557
- if (FLAG_abort_on_uncaught_exception) {
1558
- CatchType prediction = PredictExceptionCatcher ();
1559
- if ((prediction == NOT_CAUGHT || prediction == CAUGHT_BY_EXTERNAL) &&
1560
- (!abort_on_uncaught_exception_callback_ ||
1561
- abort_on_uncaught_exception_callback_ (
1562
- reinterpret_cast <v8::Isolate*>(this )))) {
1563
- // Prevent endless recursion.
1564
- FLAG_abort_on_uncaught_exception = false ;
1565
- // This flag is intended for use by JavaScript developers, so
1566
- // print a user-friendly stack trace (not an internal one).
1567
- PrintF (stderr, " %s\n\n FROM\n " ,
1568
- MessageHandler::GetLocalizedMessage (this , message_obj).get ());
1569
- PrintCurrentStackTrace (stderr);
1570
- base::OS::Abort ();
1571
- }
1572
- }
1573
1581
}
1574
1582
}
1575
1583
@@ -2106,7 +2114,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
2106
2114
bool is_at_number_conversion =
2107
2115
elements->IsAsmJsWasmFrame (i) &&
2108
2116
elements->Flags (i).value () & FrameArray::kAsmJsAtNumberConversion ;
2109
- if (elements->IsWasmCompiledFrame (i)) {
2117
+ if (elements->IsWasmCompiledFrame (i) || elements-> IsAsmJsWasmFrame (i) ) {
2110
2118
// WasmCode* held alive by the {GlobalWasmCodeRef}.
2111
2119
wasm::WasmCode* code =
2112
2120
Managed<wasm::GlobalWasmCodeRef>::cast (elements->WasmCodeObject (i))
@@ -2230,9 +2238,28 @@ bool Isolate::IsExternalHandlerOnTop(Object exception) {
2230
2238
return (entry_handler > external_handler);
2231
2239
}
2232
2240
2233
- void Isolate::ReportPendingMessagesImpl (bool report_externally) {
2241
+ std::vector<MemoryRange>* Isolate::GetCodePages () const {
2242
+ return code_pages_.load (std::memory_order_acquire);
2243
+ }
2244
+
2245
+ void Isolate::SetCodePages (std::vector<MemoryRange>* new_code_pages) {
2246
+ code_pages_.store (new_code_pages, std::memory_order_release);
2247
+ }
2248
+
2249
+ void Isolate::ReportPendingMessages () {
2250
+ DCHECK (AllowExceptions::IsAllowed (this ));
2251
+
2252
+ // The embedder might run script in response to an exception.
2253
+ AllowJavascriptExecutionDebugOnly allow_script (this );
2254
+
2234
2255
Object exception_obj = pending_exception ();
2235
2256
2257
+ // Try to propagate the exception to an external v8::TryCatch handler. If
2258
+ // propagation was unsuccessful, then we will get another chance at reporting
2259
+ // the pending message if the exception is re-thrown.
2260
+ bool has_been_propagated = PropagatePendingExceptionToExternalTryCatch ();
2261
+ if (!has_been_propagated) return ;
2262
+
2236
2263
// Clear the pending message object early to avoid endless recursion.
2237
2264
Object message_obj = thread_local_top ()->pending_message_obj_ ;
2238
2265
clear_pending_message ();
@@ -2245,7 +2272,7 @@ void Isolate::ReportPendingMessagesImpl(bool report_externally) {
2245
2272
// depending on whether and external v8::TryCatch or an internal JavaScript
2246
2273
// handler is on top.
2247
2274
bool should_report_exception;
2248
- if (report_externally ) {
2275
+ if (IsExternalHandlerOnTop (exception_obj) ) {
2249
2276
// Only report the exception if the external handler is verbose.
2250
2277
should_report_exception = try_catch_handler ()->is_verbose_ ;
2251
2278
} else {
@@ -2271,93 +2298,6 @@ void Isolate::ReportPendingMessagesImpl(bool report_externally) {
2271
2298
}
2272
2299
}
2273
2300
2274
- std::vector<MemoryRange>* Isolate::GetCodePages () const {
2275
- return code_pages_.load (std::memory_order_acquire);
2276
- }
2277
-
2278
- void Isolate::SetCodePages (std::vector<MemoryRange>* new_code_pages) {
2279
- code_pages_.store (new_code_pages, std::memory_order_release);
2280
- }
2281
-
2282
- void Isolate::ReportPendingMessages () {
2283
- DCHECK (AllowExceptions::IsAllowed (this ));
2284
-
2285
- // The embedder might run script in response to an exception.
2286
- AllowJavascriptExecutionDebugOnly allow_script (this );
2287
-
2288
- Object exception = pending_exception ();
2289
-
2290
- // Try to propagate the exception to an external v8::TryCatch handler. If
2291
- // propagation was unsuccessful, then we will get another chance at reporting
2292
- // the pending message if the exception is re-thrown.
2293
- bool has_been_propagated = PropagatePendingExceptionToExternalTryCatch ();
2294
- if (!has_been_propagated) return ;
2295
-
2296
- ReportPendingMessagesImpl (IsExternalHandlerOnTop (exception ));
2297
- }
2298
-
2299
- void Isolate::ReportPendingMessagesFromJavaScript () {
2300
- DCHECK (AllowExceptions::IsAllowed (this ));
2301
-
2302
- auto IsHandledByJavaScript = [=]() {
2303
- // In this situation, the exception is always a non-terminating exception.
2304
-
2305
- // Get the top-most JS_ENTRY handler, cannot be on top if it doesn't exist.
2306
- Address entry_handler = Isolate::handler (thread_local_top ());
2307
- DCHECK_NE (entry_handler, kNullAddress );
2308
- entry_handler = StackHandler::FromAddress (entry_handler)->next_address ();
2309
-
2310
- // Get the address of the external handler so we can compare the address to
2311
- // determine which one is closer to the top of the stack.
2312
- Address external_handler = thread_local_top ()->try_catch_handler_address ();
2313
- if (external_handler == kNullAddress ) return true ;
2314
-
2315
- return (entry_handler < external_handler);
2316
- };
2317
-
2318
- auto IsHandledExternally = [=]() {
2319
- Address external_handler = thread_local_top ()->try_catch_handler_address ();
2320
- if (external_handler == kNullAddress ) return false ;
2321
-
2322
- // Get the top-most JS_ENTRY handler, cannot be on top if it doesn't exist.
2323
- Address entry_handler = Isolate::handler (thread_local_top ());
2324
- DCHECK_NE (entry_handler, kNullAddress );
2325
- entry_handler = StackHandler::FromAddress (entry_handler)->next_address ();
2326
- return (entry_handler > external_handler);
2327
- };
2328
-
2329
- auto PropagateToExternalHandler = [=]() {
2330
- if (IsHandledByJavaScript ()) {
2331
- thread_local_top ()->external_caught_exception_ = false ;
2332
- return false ;
2333
- }
2334
-
2335
- if (!IsHandledExternally ()) {
2336
- thread_local_top ()->external_caught_exception_ = false ;
2337
- return true ;
2338
- }
2339
-
2340
- thread_local_top ()->external_caught_exception_ = true ;
2341
- v8::TryCatch* handler = try_catch_handler ();
2342
- DCHECK (thread_local_top ()->pending_message_obj_ .IsJSMessageObject () ||
2343
- thread_local_top ()->pending_message_obj_ .IsTheHole (this ));
2344
- handler->can_continue_ = true ;
2345
- handler->has_terminated_ = false ;
2346
- handler->exception_ = reinterpret_cast <void *>(pending_exception ().ptr ());
2347
- // Propagate to the external try-catch only if we got an actual message.
2348
- if (thread_local_top ()->pending_message_obj_ .IsTheHole (this )) return true ;
2349
-
2350
- handler->message_obj_ =
2351
- reinterpret_cast <void *>(thread_local_top ()->pending_message_obj_ .ptr ());
2352
- return true ;
2353
- };
2354
-
2355
- // Try to propagate to an external v8::TryCatch handler.
2356
- if (!PropagateToExternalHandler ()) return ;
2357
-
2358
- ReportPendingMessagesImpl (true );
2359
- }
2360
-
2361
2301
bool Isolate::OptionalRescheduleException (bool clear_exception) {
2362
2302
DCHECK (has_pending_exception ());
2363
2303
PropagatePendingExceptionToExternalTryCatch ();
0 commit comments