Commits

masklinn committed f735d3a

Automatically convert raw js Object values to py.object values (with all attributes correctly set)

Comments (0)

Files changed (2)

             return new py.def(val);
         }
 
+        switch(val.constructor) {
+        case Object:
+            var o = new py.object();
+            for (var prop in val) {
+                if (val.hasOwnProperty(prop)) {
+                    o[prop] = val[prop];
+                }
+            }
+            return o;
+        }
+
         throw new Error("Could not convert " + val + " to a pyval");
     }
     // Builtins
         __getattribute__: function (name) {
             if (name in this) {
                 var val = this[name];
-                if ('__get__' in val) {
+                if (typeof val === 'object' && '__get__' in val) {
                     // TODO: second argument should be class
                     return val.__get__(this);
                 }
             });
         });
     });
-});
+});
+describe('Type converter', function () {
+    it('should convert bare objects to objects', function () {
+        expect(py.eval('foo.bar', {foo: {bar: 3}})).to.be(3);
+    });
+});