Skip to content

Commit

Permalink
cookies are now honored for any use of XHR, which should internally i…
Browse files Browse the repository at this point in the history
…nclude html docs, css, javascript, images(if enabled), and other links. coookies are set with set-cookie response header and sent for every request to matching domain with 'cookie' response header. moved Envjs.uri tests to new specs/platform/core.js and added a couple basic cookie tests
  • Loading branch information
thatcher committed Apr 29, 2010
2 parents d927f19 + 3290883 commit 91cf5f5
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 48 deletions.
5 changes: 2 additions & 3 deletions build.xml
Expand Up @@ -99,10 +99,9 @@
</target>


<target name='local-settings' unless='${HAS_LOCAL}'>
<target name='local-settings' unless='HAS_LOCAL'>
<copy file="${BASEDIR}/settings.js"
tofile="${BASEDIR}/local_settings.js"
overwrite='false'/>
tofile="${BASEDIR}/local_settings.js" />
</target>

<!-- BUILD ENV PLATFORM BINDINGS -->
Expand Down
3 changes: 2 additions & 1 deletion specs/parser/spec.js
Expand Up @@ -367,7 +367,7 @@ test('Link Loading', function(){
});

test('Form Named Element Lookup', function(){
expect(10);
expect(11);
if ((typeof Envjs == 'undefined') || !Envjs) {
Envjs = {};
}
Expand All @@ -387,6 +387,7 @@ test('Form Named Element Lookup', function(){
var str = '<form name="bar"><input name="input1"/></form>';
doc.body.innerHTML = str;
form = doc.bar;
ok(form instanceof HTMLFormElement, "form is an HTMLFormElement");
elements = doc.bar.elements;
equals(elements.length, 1, 'elements length is 1');
equals(form.length, 1, 'form length is 1');
Expand Down
62 changes: 43 additions & 19 deletions specs/timer/spec.js
@@ -1,60 +1,84 @@
QUnit.module('timer');
test('Timer Interfaces Available', function(){

expect(4);
ok(setTimeout, 'setTimeout');
ok(setInterval, 'setInterval');
ok(clearTimeout, 'clearTimeout');
ok(clearInterval, 'clearInterval');


});

/**
* When passing a string to the set-timeout, it is evaluated in global scope
*
*/
test('setTimeoutScopeString', function() {
expect(1);
var BOGON = 1;
setTimeout("equals(typeof BOGON, 'undefined'); start();", 10);
stop();
});


/**
* This case works, since the function is under a closure
*
*/
test('setTimeoutScopeFunction', function() {
expect(1);
var BOGON = 1;
setTimeout(function() {equals(typeof BOGON, 'number'); start();}, 10);
stop();
});

test('setTimeout', function(){

expect(2);
var order = 1,
id;
id;

id = setTimeout(function(){
equals(order, 2, 'callback');
start()
}, 10);

equals(order++, 1, 'callstack');
stop();

});


test('clearTimeout', function(){

expect(2);
var order = 1,
id1, id2;
id1, id2;

id1 = setTimeout(function(){
ok(false, 'should have cancelled');
start()
}, 10);


id2 = setTimeout(function(){
equals(order, 2, 'callback');
start()
}, 10);

equals(order++, 1, 'callstack');
clearTimeout(id1);
stop();

});


test('setInterval / clearInterval', function(){

expect(10);
var order = 1,
id;
id;

id = setInterval(function(){
if(order < 10){
ok(order++, 'interval callback');
Expand All @@ -64,9 +88,9 @@ test('setInterval / clearInterval', function(){
start();
}
}, 50);

equals(order++, 1, 'callstack');
stop();

});

2 changes: 1 addition & 1 deletion src/html/element.js
Expand Up @@ -269,7 +269,7 @@ __extend__(HTMLElement.prototype, {
var newnode = __DOMElement__.prototype.replaceNode.apply(this, arguments);
__removeNamedMap__(this.ownerDocument, oldchild);
__addNamedMap__(this.ownerDocument, newnode);
return newnode;
return newnode;
}
});

Expand Down
49 changes: 25 additions & 24 deletions src/timer/timer.js
@@ -1,12 +1,12 @@
/*
* timer.js
* timer.js
* implementation provided by Steven Parkes
*/

//private
var $timers = [],
EVENT_LOOP_RUNNING = false;

$timers.lock = function(fn){
Envjs.sync(fn)();
};
Expand All @@ -17,9 +17,9 @@ var Timer = function(fn, interval){
this.interval = interval;
this.at = Date.now() + interval;
// allows for calling wait() from callbacks
this.running = false;
this.running = false;
};

Timer.prototype.start = function(){};
Timer.prototype.stop = function(){};

Expand All @@ -29,15 +29,15 @@ Timer.normalize = function(time) {
if ( isNaN(time) || time < 0 ) {
time = 0;
}

if ( EVENT_LOOP_RUNNING && time < Timer.MIN_TIME ) {
time = Timer.MIN_TIME;
}
return time;
};
// html5 says this should be at least 4, but the parser is using
// html5 says this should be at least 4, but the parser is using
// a setTimeout for the SAX stuff which messes up the world
Timer.MIN_TIME = /* 4 */ 0;
Timer.MIN_TIME = /* 4 */ 0;

/**
* @function setTimeout
Expand All @@ -53,7 +53,8 @@ setTimeout = function(fn, time){
if (typeof fn == 'string') {
tfn = function() {
try {
eval(fn);
// eval in global scope
eval(fn, null);
} catch (e) {
console.log('timer error %s %s', fn, e);
} finally {
Expand Down Expand Up @@ -90,10 +91,10 @@ setInterval = function(fn, time){
time = 10;
}
if (typeof fn == 'string') {
var fnstr = fn;
fn = function() {
var fnstr = fn;
fn = function() {
eval(fnstr);
};
};
}
var num;
$timers.lock(function(){
Expand All @@ -117,15 +118,15 @@ clearInterval = clearTimeout = function(num){
delete $timers[num];
}
});
};
};

// wait === null/undefined: execute any timers as they fire,
// wait === null/undefined: execute any timers as they fire,
// waiting until there are none left
// wait(n) (n > 0): execute any timers as they fire until there
// are none left waiting at least n ms but no more, even if there
// wait(n) (n > 0): execute any timers as they fire until there
// are none left waiting at least n ms but no more, even if there
// are future events/current threads
// wait(0): execute any immediately runnable timers and return
// wait(-n): keep sleeping until the next event is more than n ms
// wait(-n): keep sleeping until the next event is more than n ms
// in the future
//
// TODO: make a priority queue ...
Expand All @@ -135,24 +136,24 @@ Envjs.wait = function(wait) {
var delta_wait,
start = Date.now(),
was_running = EVENT_LOOP_RUNNING;

if (wait < 0) {
delta_wait = -wait;
wait = 0;
}
EVENT_LOOP_RUNNING = true;
EVENT_LOOP_RUNNING = true;
if (wait !== 0 && wait !== null && wait !== undefined){
wait += Date.now();
}

var earliest,
timer,
sleep,
index,
goal,
now,
nextfn;

for (;;) {
//console.log('timer loop');
earliest = sleep = goal = now = nextfn = null;
Expand Down Expand Up @@ -196,19 +197,19 @@ Envjs.wait = function(wait) {
if ( !earliest ) {
// no events in the queue (but maybe XHR will bring in events, so ...
if ( !wait || wait < Date.now() ) {
// Loop ends if there are no events and a wait hasn't been
// Loop ends if there are no events and a wait hasn't been
// requested or has expired
break;
}
// no events, but a wait requested: fall through to sleep
} else {
// there are events in the queue, but they aren't firable now
/*if ( delta_wait && sleep <= delta_wait ) {
//TODO: why waste a check on a tight
//TODO: why waste a check on a tight
// loop if it just falls through?
// if they will happen within the next delta, fall through to sleep
} else */if ( wait === 0 || ( wait > 0 && wait < Date.now () ) ) {
// loop ends even if there are events but the user
// loop ends even if there are events but the user
// specifcally asked not to wait too long
break;
}
Expand All @@ -222,7 +223,7 @@ Envjs.wait = function(wait) {
}
//console.log('sleeping %s', sleep);
Envjs.sleep(sleep);

}
EVENT_LOOP_RUNNING = was_running;
};
Expand Down

0 comments on commit 91cf5f5

Please sign in to comment.