<< Back to previous view

[CLJS-478] ClojureScript js->clj not converting Created: 26/Feb/13  Updated: 29/Jul/13

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

Type: Defect Priority: Minor
Reporter: Mike Longworth Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Environment:

ClojureScript 0.0-1586 build #22, Chrome, OSX



 Description   

I've updated to 0.0-1586 build #22 from a much older release: 0.0-1450

I'm now geting a problem with (js->clj token) not converting token to a map; this worked before I upgraded.

token is generated by the google OAuth 2 process: "gapi.auth.authorize"

I don't think the problem is with js->clj rather something about token so it isn't recognised as a js/Object.

(println (expose token true)) gives:

access_token = ya29.AHES6ZSgnk3Ws5bB-2aDx41Bbr335hKugjZJfcNAs83d121S306fxy64
token_type = Bearer
expires_in = 3600
client_id = 52351124085.apps.googleusercontent.com
scope = https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/drive.metadata.readonly,https://www.googleapis.com/auth/drive.readonly
g_user_cookie_policy = undefined
cookie_policy = undefined
issued_at = 1361807171
expires_at = 1361810771

This looks ok.

however
> token

gives:

"Error evaluating:" token :as "esef.client.evidence.token"
#<TypeError: Object [object Object] has no method 'toString'>
TypeError: Object [object Object] has no method 'toString'

> (type token)

gives a blank line. I think this is why js->clj isn't converting.

> (alength token)

gives a blank line.

(.-token_type token)

Correctly gives ya29.AHES6ZSgnk3Ws5bB-2aDx41Bbr335hKugjZJfcNAs83d121S306fxy64

I haven't managed to recreate 'token' with a minimal test case but I'm fairly new to javascript. It's impractical to to include my OAuth 2 code because its tied into all my google security.
If you can suggest anything that will provide you with more info on 'token' I'll try and help.

As a work-around I manually create the MAP by explicitly reading each property, I couldn't get a list of properties.



 Comments   
Comment by David Nolen [ 26/Feb/13 11:00 AM ]

type just returns the constructor property of an Object. For some reason this is returning undefined instead of value. It's likely that this has nothing to do with ClojureScript and more to do with Google Closure. Have you investigated whether the OAuth token constructor has changed in Closure itself?

Comment by Mike Longworth [ 26/Feb/13 11:21 AM ]

I don't think the token object or the apis have any significant relationship with closure, they are loaded dynamically from google (gapi.client.load):
https://code.google.com/p/google-api-javascript-client/wiki/ReferenceDocs#OAuth_2.0_Token_Object
https://code.google.com/p/google-api-javascript-client/wiki/GettingStarted

Comment by David Nolen [ 26/Feb/13 11:25 AM ]

Did type return something for you instead of undefined in 1450?

Comment by Mike Longworth [ 26/Feb/13 11:40 AM ]

Sorry I can't answer that; js->clj just worked so I didn't probe too deeply but looking at the code in js->clj It looks like it must have. I tried the original implementation of js->clj before the recent changes but confirmed this still suffers from the same problem (type x) js/Object):

(defn js->clj
"Recursively transforms JavaScript arrays into ClojureScript
vectors, and JavaScript objects into ClojureScript maps. With
option ':keywordize-keys true' will convert object fields from
strings to keywords."
[x & options]
(let [{:keys [keywordize-keys]} options
keyfn (if keywordize-keys keyword str)
f (fn thisfn [x]
(cond
(seq? x) (doall (map thisfn x))
(coll? x) (into (empty x) (map thisfn x))
(goog.isArray x) (vec (map thisfn x))
(identical? (type x) js/Object) (into {} (for [k (js-keys x)]
[(keyfn k)
(thisfn (aget x k))]))
:else x))]
(f x)))

Comment by David Nolen [ 29/Jul/13 10:39 PM ]

There's currently not enough information on this ticket.

Generated at Sun Nov 23 10:19:19 CST 2014 using JIRA 4.4#649-r158309.