diff options
author | Chouser <chouser@n01se.net> | 2008-10-21 04:44:44 +0000 |
---|---|---|
committer | Chouser <chouser@n01se.net> | 2008-10-21 04:44:44 +0000 |
commit | 99000024fbb67ecdf9b45991840e0cd25a63d8f7 (patch) | |
tree | 1cb70422d2b387145812d1d8a5ae5e629fa1d223 | |
parent | 94ca536b4e901c9ee0bc7bcc2662e86a7803fbbf (diff) |
ClojureScript: remove set-prop in favor of (set! prop val), plus some bug fixes.
-rw-r--r-- | clojurescript/clj.js | 15 | ||||
-rw-r--r-- | clojurescript/repl.html (renamed from clojurescript/test.html) | 2 | ||||
-rw-r--r-- | clojurescript/tojs.clj | 8 |
3 files changed, 18 insertions, 7 deletions
diff --git a/clojurescript/clj.js b/clojurescript/clj.js index 305ae203..b14179ac 100644 --- a/clojurescript/clj.js +++ b/clojurescript/clj.js @@ -109,12 +109,14 @@ clojure = new clojure.lang.Namespace("clojure",{ } }, first: function(x) { + if( x === null ) return null; if( x.first ) return x.first(); var seq = clojure.seq( x ); if( seq === null ) return null; return seq.first(); }, rest: function(x) { + if( x === null ) return null; if( x.rest ) return x.rest(); var seq = clojure.seq( x ); if( seq === null ) return null; @@ -236,8 +238,6 @@ clojure = new clojure.lang.Namespace("clojure",{ vals: function(coll) { return clojure.lang.APersistentMap.ValSeq.create(clojure.seq(coll)); }, - get_prop: function(coll,key) { return coll[ key ]; }, - set_prop: function(coll,key,val) { return coll[ key ] = val; }, JS: { merge: clojure.JS.merge, global: clojure.JS.global, @@ -271,8 +271,11 @@ clojure = new clojure.lang.Namespace("clojure",{ }, getOrRun: function( obj, prop ) { var val = obj[ prop ]; - if( val !== undefined && "apply" in val ) + if( typeof val === clojure.JS.functionType + || (typeof val === clojure.JS.objectType && "apply" in val) ) + { return val.apply( obj, [] ); + } return val; }, lit_list: function( a ) { @@ -401,7 +404,9 @@ clojure = new clojure.lang.Namespace("clojure",{ } return ret; } - return o.hashCode(); + if( o.hashCode ) + return o.hashCode(); + return 0x11111111; }, hashCombine: function(seed, hash){ return seed ^ (hash + 0x9e3779b9 + (seed << 6) + (seed >> 2)); @@ -1001,6 +1006,8 @@ clojure.JS.defclass( clojure.lang, "APersistentVector", { }); clojure.JS.defclass( clojure.lang.APersistentVector, "Seq", { + extend: clojure.lang.ASeq, + implement: [clojure.lang.IndexedSeq, clojure.lang.IReduce], init: function( _meta, v, i){ this._meta = _meta; this.v = v; diff --git a/clojurescript/test.html b/clojurescript/repl.html index 17d23003..2c179501 100644 --- a/clojurescript/test.html +++ b/clojurescript/repl.html @@ -52,7 +52,7 @@ e = e || event; if( e.keyCode == 13 ) { var s = document.createElement('script'); - s.src = "http://mycroft:8080/" + + s.src = "http://localhost:8081/" + escape(jsrepl.text.value).replace(/\+/,'%2b'); document.body.appendChild( s ); } diff --git a/clojurescript/tojs.clj b/clojurescript/tojs.clj index a46b0e28..9769951a 100644 --- a/clojurescript/tojs.clj +++ b/clojurescript/tojs.clj @@ -166,8 +166,12 @@ (str vns "._var_" vname))) (defmethod tojs clojure.lang.Compiler$AssignExpr [e ctx] - (let [[vns vname] (var-parts (.target e))] - (str vns "._var_" vname ".set(" (tojs (.val e) ctx) ")"))) + (let [target (.target e)] + (if (instance? clojure.lang.Compiler$InstanceFieldExpr target) + (vstr ["(" (tojs (.target target) ctx) "." + (var-munge (.fieldName target)) "=" (tojs (.val e) ctx) ")"]) + (let [[vns vname] (var-parts target)] + (str vns "._var_" vname ".set(" (tojs (.val e) ctx) ")"))))) (defmethod tojs clojure.lang.Compiler$DefExpr [e ctx] (let [[vns vname] (var-parts e)] |