<< Back to previous view

[CLJS-647] js-obj emits invalid js when keys are expressions Created: 29/Oct/13  Updated: 10/Nov/13  Resolved: 10/Nov/13

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: George Fraser Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: None
Environment:

CLJS 1934


Attachments: File cljs-647-20131108.diff     File cljs-647-20131110.diff    

 Description   

ClojureScript REPL:

> (js-obj (identity "a") 1)
"Error evaluating:" (js-obj (identity "a") 1) :as "{cljs.core.identity.call(null,\"a\"):1}"

But this is ok:

> (def object js-obj)
> (object (identity "a") 1)
#<[object Object]>
> (js->clj *1)
{"a" 1}


 Comments   
Comment by Travis Thieman [ 06/Nov/13 10:38 AM ]

Patch: 20131106

JS objects are now created in two stages. First, an object is instantiated with all key-value pairs having a string or symbol as the key. Then, all other keys are evaluated, and the evaluated key is set to the value on the new object.

Comment by David Nolen [ 06/Nov/13 10:45 AM ]

I messed up the patch, we should only check for strings not symbols.

Comment by Travis Thieman [ 06/Nov/13 11:22 AM ]

Revised: 20131106

Only key-value pairs with string literals as the keys are used for the original creation of the JS object. All other pairs, including those with symbols are keys, have their keys evaluated before updating the object.

Comment by Travis Thieman [ 06/Nov/13 6:05 PM ]

Revised: 20131106

JS objects are now constructed in three parts. Key-value pairs with string literals are used to construct the object. Pairs with symbol keys are set directly using the implicit evaluation of the symbol. Remaining pairs have their keys let-bound to gensyms, then the pair is set on the object using the evaluation of the gensym for the key.

Comment by David Nolen [ 07/Nov/13 6:07 PM ]

path needs to be rebased on master thanks.

Comment by Travis Thieman [ 08/Nov/13 9:15 AM ]

Patch: 20131108

Rebased to 8d1d315.

Comment by David Nolen [ 08/Nov/13 5:05 PM ]

Need another rebase sorry.

Comment by Travis Thieman [ 10/Nov/13 1:04 PM ]

Patch: 20131110

Rebased to 0e427a0.

Comment by David Nolen [ 10/Nov/13 1:54 PM ]

fixed, https://github.com/clojure/clojurescript/commit/7a912f32c7d26eb171862db03acd7184074c620b

Generated at Mon Sep 01 20:56:22 CDT 2014 using JIRA 4.4#649-r158309.