type checks

This commit is contained in:
Danny Yoo 2011-12-01 17:22:41 -05:00
parent 1b2680b03a
commit b45b986caa

View File

@ -20,20 +20,30 @@
(inexact->exact (js-number->number (get-attr localStorage "length"))))
(define (storage-key i)
(unless (exact-nonnegative-integer? i)
(raise-type-error 'storage-key "natural" i))
(js-string->string (call-method localStorage "key" (number->js-number i))))
(define (storage-ref name)
(unless (string? name)
(raise-type-error 'storage-ref "string" name))
(define val (call-method localStorage "getItem" (string->js-string name)))
(if (js-null? val)
#f
(js-string->string val)))
(define (storage-set! name value)
(unless (string? name)
(raise-type-error 'storage-set! "string" name 0))
(unless (string? value)
(raise-type-error 'storage-set! "string" value 1))
(void (call-method localStorage "setItem"
(string->js-string name)
(string->js-string value))))
(define (storage-remove! name)
(unless (string? name)
(raise-type-error 'storage-remove! "string" name))
(void (call-method localStorage "removeItem"
(string->js-string name))))