Browse Source

Added support for non-Atomic namespace JSBind generated classes

(cherry picked from commit 6c4497cc1bda45a7d25be3cb1a2381e34b3b8c1f)
Matt Benic 10 years ago
parent
commit
71c464e776
1 changed files with 8 additions and 4 deletions
  1. 8 4
      Source/AtomicJS/Javascript/JSAPI.cpp

+ 8 - 4
Source/AtomicJS/Javascript/JSAPI.cpp

@@ -69,13 +69,17 @@ void js_class_declare_internal(JSVM* vm, void* uniqueClassID, const char* packag
         duk_put_prop(ctx, -3);
         duk_pop(ctx);
     }
-    else
+    
+    if (!duk_get_global_string(ctx, package))
     {
-        // RefCounted only supported in Atomic package
-        assert(String("Atomic") == package );
+        // Failure leaves undefined on the stack
+        duk_pop(ctx);
+        // Create a new namespace object for the package
+        duk_push_object(ctx);
+        duk_put_global_string(ctx, package);
+        duk_get_global_string(ctx, package);
     }
 
-    duk_get_global_string(ctx, package);
     duk_push_c_function(ctx, constructor, DUK_VARARGS);
     duk_put_prop_string(ctx, -2, classname);
     duk_pop(ctx);