diff options
author | David Barksdale <amatus@amatus.name> | 2014-12-07 17:30:08 -0600 |
---|---|---|
committer | David Barksdale <amatus@amatus.name> | 2014-12-07 17:30:08 -0600 |
commit | a871571b75d3be47132ef10bf65edc4158ff418f (patch) | |
tree | 239716db0e9d935988defdc00df6d3879b9ff6c5 /src/cljs/gnunet_web/filesharing.cljs | |
parent | e5aaf1a88fa05a25bdc46c9a6b1c590c3a039ccc (diff) |
Avoid dynamic use of Runtime.addFunction
Diffstat (limited to 'src/cljs/gnunet_web/filesharing.cljs')
-rw-r--r-- | src/cljs/gnunet_web/filesharing.cljs | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/cljs/gnunet_web/filesharing.cljs b/src/cljs/gnunet_web/filesharing.cljs index ad3d8e5..7be5617 100644 --- a/src/cljs/gnunet_web/filesharing.cljs +++ b/src/cljs/gnunet_web/filesharing.cljs @@ -56,16 +56,19 @@ keywords)) (defn metadata-iterator - [metadata cls plugin-name type format mime-type data data-size] - (swap! metadata conj - {:plugin-name (js/Pointer_stringify plugin-name) - :type type - :format format - :mime-type (js/Pointer_stringify mime-type) - :data (if (or (= format e/format-utf8) - (= format e/format-string)) - (js/Pointer_stringify data) - (read-memory data data-size))})) + [cls plugin-name type format mime-type data data-size] + (let [metadata (get-object cls)] + (swap! metadata conj + {:plugin-name (js/Pointer_stringify plugin-name) + :type type + :format format + :mime-type (js/Pointer_stringify mime-type) + :data (if (or (= format e/format-utf8) + (= format e/format-string)) + (js/Pointer_stringify data) + (read-memory data data-size))}))) + +(def metadata-iterator-pointer (js/Runtime.addFunction metadata-iterator)) (defn parse-progress-publish [status info-pointer] @@ -113,13 +116,13 @@ :cctx (js/_GNUNET_FS_ProgressInfo_get_search_cctx info-pointer)} (condp = status :search-result (let [metadata (atom []) - callback (partial metadata-iterator metadata) - callback-pointer (js/Runtime.addFunction callback)] + metadata-key (register-object metadata)] (js/_GNUNET_CONTAINER_meta_data_iterate (js/_GNUNET_FS_ProgressInfo_get_search_result_meta info-pointer) - callback-pointer) - (js/Runtime.removeFunction callback-pointer) + metadata-iterator-pointer + metadata-key) + (unregister-object metadata-key) {:uri (uri-pointer-to-string (js/_GNUNET_FS_ProgressInfo_get_search_result_uri info-pointer)) |