Merge pull request #5560 from kumpera/wasm-work-p3
[mono.git] / mono / metadata / object.c
index 2ea88c75f8cfde20ecb362453f027e16dbe1225a..457c50e02cc115b4deeeaa547ff0453ef9df24c5 100644 (file)
@@ -4587,7 +4587,14 @@ mono_unhandled_exception_checked (MonoObjectHandle exc, MonoError *error)
        MonoObjectHandle current_appdomain_delegate = MONO_HANDLE_NEW (MonoObject, NULL);
 
        MonoClass *klass = mono_handle_class (exc);
-       if (mono_class_has_parent (klass, mono_defaults.threadabortexception_class))
+       /*
+        * AppDomainUnloadedException don't behave like unhandled exceptions unless thrown from 
+        * a thread started in unmanaged world.
+        * https://msdn.microsoft.com/en-us/library/system.appdomainunloadedexception(v=vs.110).aspx#Anchor_6
+        */
+       if (klass == mono_defaults.threadabortexception_class ||
+                       (klass == mono_class_get_appdomain_unloaded_exception_class () &&
+                       mono_thread_info_current ()->runtime_thread))
                return;
 
        field = mono_class_get_field_from_name (mono_defaults.appdomain_class, "UnhandledException");
@@ -7403,6 +7410,9 @@ mono_wait_handle_get_handle (MonoWaitHandle *handle)
 static MonoObject*
 mono_runtime_capture_context (MonoDomain *domain, MonoError *error)
 {
+#ifdef HOST_WASM
+       return mono_runtime_invoke_checked (mono_get_context_capture_method (), NULL, NULL, error);
+#else
        MONO_REQ_GC_UNSAFE_MODE;
 
        RuntimeInvokeFunction runtime_invoke;
@@ -7424,6 +7434,7 @@ mono_runtime_capture_context (MonoDomain *domain, MonoError *error)
        runtime_invoke = (RuntimeInvokeFunction)domain->capture_context_runtime_invoke;
 
        return runtime_invoke (NULL, NULL, NULL, domain->capture_context_method);
+#endif
 }
 /**
  * mono_async_result_new: