Skip to content

Commit

Permalink
updates to basic cookie implementation, JSON is in platform core and …
Browse files Browse the repository at this point in the history
…not included if global JSON is already defined, max-age = 0 is treated as permanent cookie, almost ready to start adding tests and getting feature requests from end user requirements
  • Loading branch information
thatcher committed Apr 28, 2010
1 parent aa60e10 commit 036de7a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions build.xml
Expand Up @@ -127,6 +127,7 @@
<fileset dir="${SRC_DIR}" includes="platform/core/dom.js" />
<fileset dir="${SRC_DIR}" includes="platform/core/event.js" />
<fileset dir="${SRC_DIR}" includes="platform/core/html.js" />
<fileset dir="${SRC_DIR}" includes="platform/core/json.js" />
<fileset dir="${SRC_DIR}" includes="platform/core/timer.js" />
<fileset dir="${SRC_DIR}" includes="platform/core/urlparse.js" />
<fileset dir="${SRC_DIR}" includes="platform/core/xhr.js" />
Expand Down
5 changes: 3 additions & 2 deletions specs/html/boot.js
Expand Up @@ -16,7 +16,7 @@ load('dist/event.js');
load('dist/html.js');

// if the html code has forward references, then
// we have a different problem.
// we have a different problem.

//load('dist/timer.js');
//load('dist/parser.js');
Expand All @@ -25,5 +25,6 @@ load('dist/html.js');

load('specs/html/spec.js');

location = 'specs/html/index.html';
location = 'specs/html/index.html';

start();
1 change: 0 additions & 1 deletion src/console/__global__.js
Expand Up @@ -3,5 +3,4 @@
* @author envjs team
*/
var Console,
JSON,
console;
21 changes: 10 additions & 11 deletions src/html/cookie.js
Expand Up @@ -67,7 +67,7 @@ Cookies.set = function(doc, cookie){
name = __trim__(attrs[i].slice(0,index));
value = __trim__(attrs[i].slice(index+1));
if(name=='max-age'){
//we'll have to set a timer to check these
//we'll have to when to check these
//and garbage collect expired cookies
cookie[name] = parseInt(value, 10);
} else if(name=='domain'){
Expand All @@ -90,11 +90,8 @@ Cookies.set = function(doc, cookie){
}
if(!cookie['max-age']){
//it's a transient cookie so it only lasts as long as
//the window.location remains the same
//the window.location remains the same (ie in-memory cookie)
__mergeCookie__(Cookies.temporary, cookie, properties);
}else if(cookie['max-age']===0){
//delete the cookies
//TODO
}else{
//the cookie is persistent
__mergeCookie__(Cookies.persistent, cookie, properties);
Expand All @@ -118,7 +115,7 @@ Cookies.get = function(doc){
}
//console.log('set cookies for doc %s', doc.baseURI);
}catch(e){
console.log('error loading cookies %s', e)
console.log('cookies not loaded %s', e)
};
}
var temporary = __cookieString__(Cookies.temporary, doc),
Expand Down Expand Up @@ -164,11 +161,13 @@ function __mergeCookie__(target, cookie, properties){
for(name in properties){
now = new Date().getTime();
target[cookie.domain][cookie.path][name] = {
value:properties[name],
"@env:secure":cookie.secure,
"@env:max-age":cookie['max-age'],
"@env:date-created":now,
"@env:expiration":now + cookie['max-age']
"value":properties[name],
"secure":cookie.secure,
"max-age":cookie['max-age'],
"date-created":now,
"expiration":(cookie['max-age']===0) ?
0 :
now + cookie['max-age']
};
//console.log('cookie is %o',target[cookie.domain][cookie.path][name]);
}
Expand Down
3 changes: 3 additions & 0 deletions src/console/json.js → src/platform/core/json.js
Expand Up @@ -15,6 +15,7 @@
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
NOT CONTROL.
*/
try{ JSON; }catch(e){
JSON = function () {

function f(n) {
Expand Down Expand Up @@ -228,3 +229,5 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
}
};
}();

}

0 comments on commit 036de7a

Please sign in to comment.