Skip to content

Commit

Permalink
Support for object property modification
Browse files Browse the repository at this point in the history
  • Loading branch information
jdudek committed Mar 21, 2012
1 parent 984e16d commit e02bde4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/c_backend.js
Expand Up @@ -29,7 +29,16 @@ exports.compile = function (ast) {
case AST.AssignStatement:
if (node.leftExpr() instanceof AST.Variable) {
return "js_assign_variable(binding, " +
quotes(node.leftExpr().identifier()) + ", " + expression(node.rightExpr()) + ");";
quotes(node.leftExpr().identifier()) + ", " +
expression(node.rightExpr()) +
");";
} else if (node.leftExpr() instanceof AST.Refinement) {
return "{ "+
"JSValue* object = " + expression(node.leftExpr().expression()) + "; " +
"object->object_value = dict_insert(object->object_value, " +
"js_to_string(" + expression(node.leftExpr().key()) + ")->string_value, " +
expression(node.rightExpr()) + "); " +
"}";
} else {
throw "Invalid left-hand side in assignment";
}
Expand Down
1 change: 1 addition & 0 deletions test/c_backend_test.js
Expand Up @@ -55,6 +55,7 @@ tests.push(testProgram("return 2 > 3;", "false"));
tests.push(testProgram("var x; return 2;", "2"));
tests.push(testProgram("var x = 2; return x;", "2"));
tests.push(testProgram("var x = 5; x = 2; return x;", "2"));
tests.push(testProgram("var x = {}; x.y = 2; return x.y;", "2"));

// Test: expression statement
tests.push(testProgram("var x = 2; 5; return x;", "2"));
Expand Down

0 comments on commit e02bde4

Please sign in to comment.