ClojureScript

ClojureScript js->clj not converting

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Not Reproducible
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • 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.

Activity

Hide
David Nolen added a comment -

There's currently not enough information on this ticket.

Show
David Nolen added a comment - There's currently not enough information on this ticket.
Hide
Mike Longworth added a comment - - edited

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)))

Show
Mike Longworth added a comment - - edited 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)))
Hide
David Nolen added a comment -

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

Show
David Nolen added a comment - Did type return something for you instead of undefined in 1450?
Hide
Mike Longworth added a comment -

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

Show
Mike Longworth added a comment - 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
Hide
David Nolen added a comment -

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?

Show
David Nolen added a comment - 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?

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: