diff --git a/build.xml b/build.xml index e5e208e6..d8b18eef 100644 --- a/build.xml +++ b/build.xml @@ -99,10 +99,9 @@ - + + tofile="${BASEDIR}/local_settings.js" /> diff --git a/specs/parser/spec.js b/specs/parser/spec.js index 96e8e018..8a0dc40b 100644 --- a/specs/parser/spec.js +++ b/specs/parser/spec.js @@ -367,7 +367,7 @@ test('Link Loading', function(){ }); test('Form Named Element Lookup', function(){ - expect(10); + expect(11); if ((typeof Envjs == 'undefined') || !Envjs) { Envjs = {}; } @@ -387,6 +387,7 @@ test('Form Named Element Lookup', function(){ var str = '
'; 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'); diff --git a/specs/timer/spec.js b/specs/timer/spec.js index fadeeb79..dab4e352 100644 --- a/specs/timer/spec.js +++ b/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'); @@ -64,9 +88,9 @@ test('setInterval / clearInterval', function(){ start(); } }, 50); - + equals(order++, 1, 'callstack'); stop(); - + }); diff --git a/src/html/element.js b/src/html/element.js index 7b36457a..7d70a9a9 100644 --- a/src/html/element.js +++ b/src/html/element.js @@ -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; } }); diff --git a/src/timer/timer.js b/src/timer/timer.js index 5b12326e..b2a03f60 100644 --- a/src/timer/timer.js +++ b/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)(); }; @@ -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(){}; @@ -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 @@ -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 { @@ -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(){ @@ -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 ... @@ -135,16 +136,16 @@ 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, @@ -152,7 +153,7 @@ Envjs.wait = function(wait) { goal, now, nextfn; - + for (;;) { //console.log('timer loop'); earliest = sleep = goal = now = nextfn = null; @@ -196,7 +197,7 @@ 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; } @@ -204,11 +205,11 @@ Envjs.wait = function(wait) { } 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; } @@ -222,7 +223,7 @@ Envjs.wait = function(wait) { } //console.log('sleeping %s', sleep); Envjs.sleep(sleep); - + } EVENT_LOOP_RUNNING = was_running; };