From 28d33ca3b57017d5879e01105a1ddfeab5ee8911 Mon Sep 17 00:00:00 2001 From: Nick Galbreath Date: Thu, 29 Apr 2010 01:50:34 +0000 Subject: [PATCH 1/7] untabify only. Will make next commit nicer --- src/timer/timer.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/timer/timer.js b/src/timer/timer.js index 5b12326e..83b8405d 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 @@ -90,10 +90,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 +117,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 +135,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 +152,7 @@ Envjs.wait = function(wait) { goal, now, nextfn; - + for (;;) { //console.log('timer loop'); earliest = sleep = goal = now = nextfn = null; @@ -196,7 +196,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 +204,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 +222,7 @@ Envjs.wait = function(wait) { } //console.log('sleeping %s', sleep); Envjs.sleep(sleep); - + } EVENT_LOOP_RUNNING = was_running; }; From 2b340d5c67880a996d3c40fac34756f7029e5835 Mon Sep 17 00:00:00 2001 From: Nick Galbreath Date: Thu, 29 Apr 2010 01:52:13 +0000 Subject: [PATCH 2/7] timers get evalled in global scope, not local --- specs/timer/spec.js | 62 +++++++++++++++++++++++++++++++-------------- src/timer/timer.js | 3 ++- 2 files changed, 45 insertions(+), 20 deletions(-) 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/timer/timer.js b/src/timer/timer.js index 83b8405d..b2a03f60 100644 --- a/src/timer/timer.js +++ b/src/timer/timer.js @@ -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 { From b586b1348a06fc9084c7bfd170f675a4f19cb9cc Mon Sep 17 00:00:00 2001 From: Nick Galbreath Date: Thu, 29 Apr 2010 02:31:57 +0000 Subject: [PATCH 3/7] make test more clear on source of failure --- specs/parser/spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/parser/spec.js b/specs/parser/spec.js index 96e8e018..ec33ea6a 100644 --- a/specs/parser/spec.js +++ b/specs/parser/spec.js @@ -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'); From 5e029822837c5fcce754c7da25995fb14346abaa Mon Sep 17 00:00:00 2001 From: Nick Galbreath Date: Thu, 29 Apr 2010 02:45:50 +0000 Subject: [PATCH 4/7] whitespace only. will make next commit nicer --- src/html/element.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/html/element.js b/src/html/element.js index 81453e05..36782f1b 100644 --- a/src/html/element.js +++ b/src/html/element.js @@ -204,9 +204,9 @@ __extend__(HTMLElement.prototype, { */ setAttribute: function(name, value) { - var result = __DOMElement__.prototype.setAttribute.apply(this, arguments); + var result = __DOMElement__.prototype.setAttribute.apply(this, arguments); __addNamedMap__(this.ownerDocument, this); - var tagname = this.tagName; + var tagname = this.tagName; var callback = HTMLElement.getAttributeCallback('set', tagname, name); if (callback) { callback(this, value); @@ -215,7 +215,7 @@ __extend__(HTMLElement.prototype, { setAttributeNS: function(namespaceURI, name, value) { var result = __DOMElement__.prototype.setAttributeNS.apply(this, arguments); __addNamedMap__(this.ownerDocument, this); - var tagname = this.tagName; + var tagname = this.tagName; var callback = HTMLElement.getAttributeCallback('set', tagname, name); if (callback) { callback(this, value); @@ -225,7 +225,7 @@ __extend__(HTMLElement.prototype, { }, setAttributeNode: function(newnode) {var result = __DOMElement__.prototype.setAttributeNode.apply(this, arguments); __addNamedMap__(this.ownerDocument, this); - var tagname = this.tagName; + var tagname = this.tagName; var callback = HTMLElement.getAttributeCallback('set', tagname, newnode.name); if (callback) { callback(this, node.value); @@ -235,7 +235,7 @@ __extend__(HTMLElement.prototype, { setAttributeNodeNS: function(newnode) { var result = __DOMElement__.prototype.setAttributeNodeNS.apply(this, arguments); __addNamedMap__(this.ownerDocument, this); - var tagname = this.tagName; + var tagname = this.tagName; var callback = HTMLElement.getAttributeCallback('set', tagname, newnode.name); if (callback) { callback(this, node.value); @@ -255,13 +255,13 @@ __extend__(HTMLElement.prototype, { return __DOMElement__.prototype.removeAttribute.apply(this, arguments); }, removeChild: function(oldChild) { - __removeNamedMap__(this.ownerDocument, oldChild); + __removeNamedMap__(this.ownerDocument, oldChild); return __DOMElement__.prototype.removeChild.apply(this, arguments); }, importNode: function(othernode, deep) { var newnode = __DOMElement__.prototype.importNode.apply(this, arguments); __removeNamedMap__(this.ownerDocument, newnode); - return newnode; + return newnode; }, // not actually sure if this is needed or not @@ -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; } }); From fee359e0d655d8304c0e48f2276726a050768e2d Mon Sep 17 00:00:00 2001 From: Nick Galbreath Date: Thu, 29 Apr 2010 02:48:32 +0000 Subject: [PATCH 5/7] fix named elements on innerHTML --- src/html/element.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/html/element.js b/src/html/element.js index 36782f1b..c7f6a6a0 100644 --- a/src/html/element.js +++ b/src/html/element.js @@ -260,8 +260,8 @@ __extend__(HTMLElement.prototype, { }, importNode: function(othernode, deep) { var newnode = __DOMElement__.prototype.importNode.apply(this, arguments); - __removeNamedMap__(this.ownerDocument, newnode); - return newnode; + __addNamedMap__(this.ownerDocument, newnode); + return newnode; }, // not actually sure if this is needed or not From 63dea28f82e45581d7c749cb0606c3af27c032cb Mon Sep 17 00:00:00 2001 From: Nick Galbreath Date: Thu, 29 Apr 2010 02:51:02 +0000 Subject: [PATCH 6/7] order is restored --- specs/parser/spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/parser/spec.js b/specs/parser/spec.js index ec33ea6a..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 = {}; } From 329088313f580e1141d0ac9c096c6c88f7d49a8c Mon Sep 17 00:00:00 2001 From: "Glen E. Ivey" Date: Wed, 28 Apr 2010 21:19:00 -0700 Subject: [PATCH 7/7] Fixed use of "unless" attribute to target for local_settings.js. --- build.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build.xml b/build.xml index d206d58a..bb435248 100644 --- a/build.xml +++ b/build.xml @@ -99,10 +99,9 @@ - + + tofile="${BASEDIR}/local_settings.js" />