def test_object_literal(self): result, context = self.eval('object_literal.js') self.assertEqual(result, js.Object({'season': js.Object({'episode': js.Array([js.Object({ 'available': 'true', 'episodenumber': '402', 'description': '...', 'tags': 'Tooth Fairy|Cartman|T**s|Kyle|Stan', 'url': 'http://www.southparkstudios.com/full-episodes/s04e02-the-tooth-fairy-tats', 'title': 'The Tooth Fairy Tats', 'when': '04.05.2000', 'thumbnail_190': 'http://example.com/episode_thumbnails/s04e02_480.jpg?width=190', 'id': '103570', 'airdate': '04.05.2000', 'thumbnail_larger': 'http://example.com/episode_thumbnails/s04e02_480.jpg?width=63', 'thumbnail': 'http://example.com/episode_thumbnails/s04e02_480.jpg?width=55'})])})}))
def test_object_set_new_property(self): context = js.ExecutionContext( {'x': js.Object({ 'cheese': 7, 'ham': 3 })}) self.assertEqual(self.eval('x["spam"] = 2', context), 2) self.assertEqual(context['x']['spam'], 2)
def test_object_set_property(self): context = js.ExecutionContext( {'x': js.Object({ 'cheese': 7, 'ham': 3 })}) self.assertEqual(self.eval('x["cheese"] = 4', context), 4) self.assertEqual(context['x']['cheese'], 4)
def eval(self, context): # TODO return js.Object()
def eval(self, context): items = dict((name, js.get_value(e.eval(context))) for name, e in self.items.items()) return js.Object(items=items)