From c612b99a3da06a5cb133d55c955aeab02306c7b3 Mon Sep 17 00:00:00 2001
From: bl0ckeduser <bl0ckedusersoft@gmail.com>
Date: Thu, 17 Jan 2013 19:10:39 -0500
Subject: [PATCH] Ugly but working fix for bug #38084

---
 libcore/vm/ASHandlers.cpp |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/libcore/vm/ASHandlers.cpp b/libcore/vm/ASHandlers.cpp
index 92f9cd9..db6b23c 100644
--- a/libcore/vm/ASHandlers.cpp
+++ b/libcore/vm/ASHandlers.cpp
@@ -2794,10 +2794,15 @@ ActionCallMethod(ActionExec& thread)
 
     as_object* super;
     as_function* func = method_obj->to_function();
+    as_object *alternate_this(0);
     if (func && func->isBuiltin()) {
         // Do not construct super if method is a builtin
         // TODO: check if this is correct!!
         super = 0;
+
+        // Check for superclass prototype. Used below.
+        if (obj->get_super(methURI)->get_prototype())
+            alternate_this = obj->get_super(methURI)->get_prototype();
     }
     else {
         super = obj->get_super(methURI);
@@ -2814,6 +2819,22 @@ ActionCallMethod(ActionExec& thread)
         IF_VERBOSE_ASCODING_ERRORS(
             log_aserror("ActionCallMethod: %s", e.what());
         );
+
+        // Try again with superclass prototype if the call
+        // failed. This is a quite ugly (but working) fix for
+        // a rare corner-case described in bug report #38084.
+        if (alternate_this) {
+            log_error("Trying superclass prototype call hack");
+            call.this_ptr = alternate_this;
+            try {
+                result = method_obj->call(call);
+            }
+            catch (const ActionTypeError& e) {
+                IF_VERBOSE_ASCODING_ERRORS(
+                    log_aserror("ActionCallMethod: %s", e.what());
+                );
+            }
+        }
     }
 
     env.push(result);
-- 
1.7.9.5

