Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
refactored cookies.set and cookies.update to use cookies.remove
Browse files Browse the repository at this point in the history
  • Loading branch information
boblail committed Jan 20, 2011
1 parent d74e4af commit d6db19c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/zombie/cookies.coffee
Expand Up @@ -73,22 +73,21 @@ class Cookies
state.expires = browser.clock + maxage if typeof maxage is "number"
state.secure = true if options.secure
if typeof state.expires is "number" && state.expires <= browser.clock
if in_domain = cookies[hostname]
if in_path = in_domain[pathname]
delete in_path[name]
@remove(name)
else
in_domain = cookies[hostname] ||= {}
in_path = in_domain[pathname] ||= {}
in_path[name] = state

#### cookies(host, path).remove(name)
#### cookies(host, path).remove(name, options?)
#
# Deletes a cookie.
#
# * name -- Cookie name
# * options -- Options domain, path
this.remove = (name, options = {})->
if in_domain = cookies[hostname]
if in_path = in_domain[pathname]
if in_domain = cookies[options.domain || hostname]
if in_path = in_domain[options.path || pathname]
delete in_path[name.toLowerCase()]

#### cookies(host, path).clear()
Expand Down Expand Up @@ -125,11 +124,11 @@ class Cookies
when "secure" then options.secure = true
continue if domain && !domainMatch(domain, hostname)
continue if path && pathname.indexOf(path) != 0

# @set(name, value, options)

if options.expires && options.expires <= browser.clock
if in_domain = cookies[domain || hostname]
if in_path = in_domain[path || pathname]
delete in_path[name]
@remove(name, {domain: domain, path: path})
else
in_domain = cookies[domain || hostname] ||= {}
in_path = in_domain[path || pathname] ||= {}
Expand Down

0 comments on commit d6db19c

Please sign in to comment.