From 04074a307e0467ebc15ac75570ba8bffca2acf16 Mon Sep 17 00:00:00 2001 From: "Glen E. Ivey" Date: Mon, 10 Aug 2009 13:53:30 -0700 Subject: [PATCH 1/6] Cleaning up type-o's involving HTMLElement child class naming. --- dist/env.js | 95 ++++++++++++++++++++++------------------- dist/env.rhino.js | 95 ++++++++++++++++++++++------------------- rhino/mainForEnvjs.jar | Bin 4608 -> 4714 bytes src/html/div.js | 4 +- src/html/document.js | 2 +- 5 files changed, 105 insertions(+), 91 deletions(-) diff --git a/dist/env.js b/dist/env.js index e3dbcca8..aad38466 100644 --- a/dist/env.js +++ b/dist/env.js @@ -4945,13 +4945,13 @@ HTMLDocument.prototype = new DOMDocument; __extend__(HTMLDocument.prototype, { createElement: function(tagName){ // throw Exception if the tagName string contains an illegal character - if (__ownerDocument__(this).implementation.errorChecking && + if (__ownerDocument__(this).implementation.errorChecking && (!__isValidName__(tagName))) { throw(new DOMException(DOMException.INVALID_CHARACTER_ERR)); } tagName = tagName.toUpperCase(); // create DOMElement specifying 'this' as ownerDocument - //This is an html document so we need to use explicit interfaces per the + //This is an html document so we need to use explicit interfaces per the if( tagName.match(/^A$/)) {node = new HTMLAnchorElement(this);} else if(tagName.match(/AREA/)) {node = new HTMLAreaElement(this);} else if(tagName.match(/BASE/)) {node = new HTMLBaseElement(this);} @@ -4994,34 +4994,34 @@ __extend__(HTMLDocument.prototype, { else if(tagName.match(/TABLE/)) {node = new HTMLTableElement(this);} else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLSectionElement(this);} else if(tagName.match(/TD|TH/)) {node = new HTMLTableCellElement(this);} - else if(tagName.match(/TEXTAREA/)) {node = new HTMLElement(this);} + else if(tagName.match(/TEXTAREA/)) {node = new HTMLTextAreaElement(this);} else if(tagName.match(/TITLE/)) {node = new HTMLTitleElement(this);} else if(tagName.match(/TR/)) {node = new HTMLTableRowElement(this);} else if(tagName.match(/UL/)) {node = new HTMLElement(this);} else{ node = new HTMLElement(this); } - + // assign values to properties (and aliases) node.tagName = tagName; return node; }, get anchors(){ return new HTMLCollection(this.getElementsByTagName('a'), 'Anchor'); - + }, get applets(){ return new HTMLCollection(this.getElementsByTagName('applet'), 'Applet'); - + }, - get body(){ + get body(){ var nodelist = this.getElementsByTagName('body'); return nodelist.item(0); - + }, set body(html){ return this.replaceNode(this.body,html); - + }, get title(){ @@ -5049,44 +5049,44 @@ __extend__(HTMLDocument.prototype, { //set/get cookie see cookie.js get domain(){ return this._domain||window.location.domain; - + }, set domain(){ - /* TODO - requires a bit of thought to enforce domain restrictions */ - return; - + /* TODO - requires a bit of thought to enforce domain restrictions */ + return; + }, get forms(){ return new HTMLCollection(this.getElementsByTagName('form'), 'Form'); }, get images(){ return new HTMLCollection(this.getElementsByTagName('img'), 'Image'); - + }, - get lastModified(){ + get lastModified(){ /* TODO */ - return this._lastModified; - + return this._lastModified; + }, get links(){ return new HTMLCollection(this.getElementsByTagName('a'), 'Link'); - + }, get location(){ return $w.location }, get referrer(){ /* TODO */ - return this._refferer; - + return this._refferer; + }, get URL(){ /* TODO*/ - return this._url; - + return this._url; + }, - close : function(){ - /* TODO */ + close : function(){ + /* TODO */ this._open = false; }, getElementsByName : function(name){ @@ -5103,28 +5103,28 @@ __extend__(HTMLDocument.prototype, { } return retNodes; }, - open : function(){ + open : function(){ /* TODO */ - this._open = true; + this._open = true; }, - write: function(htmlstring){ + write: function(htmlstring){ /* TODO */ - return; - + return; + }, - writeln: function(htmlstring){ - this.write(htmlstring+'\n'); + writeln: function(htmlstring){ + this.write(htmlstring+'\n'); }, - toString: function(){ - return "Document" + (typeof this._url == "string" ? ": " + this._url : ""); + toString: function(){ + return "Document" + (typeof this._url == "string" ? ": " + this._url : ""); }, - get innerHTML(){ - return this.documentElement.outerHTML; - + get innerHTML(){ + return this.documentElement.outerHTML; + }, get __html__(){ return true; - + } }); @@ -5893,7 +5893,7 @@ $w.HTMLModElement = HTMLModElement; /* */ -$debug("Defining HTMLTextAreaElement"); +$debug("Defining HTMLDivElement"); /* * HTMLDivElement - DOM Level 2 */ @@ -5911,7 +5911,8 @@ __extend__(HTMLDivElement.prototype, { } }); -$w.HTMLDivElement = HTMLDivElement;$debug("Defining HTMLFieldSetElement"); +$w.HTMLDivElement = HTMLDivElement; +$debug("Defining HTMLFieldSetElement"); /* * HTMLFieldSetElement - DOM Level 2 */ @@ -9077,12 +9078,18 @@ window.setTimeout = function(fn, time){ tfn = function() { fn(); window.clearInterval(num); - } + }; } - $debug("Creating timer number "+num); - $timers[num] = new $env.timer(tfn, time); - $timers[num].start(); - return num; + + if (time === 0){ + tfn(); + } + else { + $debug("Creating timer number "+num); + $timers[num] = new $env.timer(tfn, time); + $timers[num].start(); + return num; + } }; window.setInterval = function(fn, time){ diff --git a/dist/env.rhino.js b/dist/env.rhino.js index 5b7d36da..8ed4d6bc 100644 --- a/dist/env.rhino.js +++ b/dist/env.rhino.js @@ -5384,13 +5384,13 @@ HTMLDocument.prototype = new DOMDocument; __extend__(HTMLDocument.prototype, { createElement: function(tagName){ // throw Exception if the tagName string contains an illegal character - if (__ownerDocument__(this).implementation.errorChecking && + if (__ownerDocument__(this).implementation.errorChecking && (!__isValidName__(tagName))) { throw(new DOMException(DOMException.INVALID_CHARACTER_ERR)); } tagName = tagName.toUpperCase(); // create DOMElement specifying 'this' as ownerDocument - //This is an html document so we need to use explicit interfaces per the + //This is an html document so we need to use explicit interfaces per the if( tagName.match(/^A$/)) {node = new HTMLAnchorElement(this);} else if(tagName.match(/AREA/)) {node = new HTMLAreaElement(this);} else if(tagName.match(/BASE/)) {node = new HTMLBaseElement(this);} @@ -5433,34 +5433,34 @@ __extend__(HTMLDocument.prototype, { else if(tagName.match(/TABLE/)) {node = new HTMLTableElement(this);} else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLSectionElement(this);} else if(tagName.match(/TD|TH/)) {node = new HTMLTableCellElement(this);} - else if(tagName.match(/TEXTAREA/)) {node = new HTMLElement(this);} + else if(tagName.match(/TEXTAREA/)) {node = new HTMLTextAreaElement(this);} else if(tagName.match(/TITLE/)) {node = new HTMLTitleElement(this);} else if(tagName.match(/TR/)) {node = new HTMLTableRowElement(this);} else if(tagName.match(/UL/)) {node = new HTMLElement(this);} else{ node = new HTMLElement(this); } - + // assign values to properties (and aliases) node.tagName = tagName; return node; }, get anchors(){ return new HTMLCollection(this.getElementsByTagName('a'), 'Anchor'); - + }, get applets(){ return new HTMLCollection(this.getElementsByTagName('applet'), 'Applet'); - + }, - get body(){ + get body(){ var nodelist = this.getElementsByTagName('body'); return nodelist.item(0); - + }, set body(html){ return this.replaceNode(this.body,html); - + }, get title(){ @@ -5488,44 +5488,44 @@ __extend__(HTMLDocument.prototype, { //set/get cookie see cookie.js get domain(){ return this._domain||window.location.domain; - + }, set domain(){ - /* TODO - requires a bit of thought to enforce domain restrictions */ - return; - + /* TODO - requires a bit of thought to enforce domain restrictions */ + return; + }, get forms(){ return new HTMLCollection(this.getElementsByTagName('form'), 'Form'); }, get images(){ return new HTMLCollection(this.getElementsByTagName('img'), 'Image'); - + }, - get lastModified(){ + get lastModified(){ /* TODO */ - return this._lastModified; - + return this._lastModified; + }, get links(){ return new HTMLCollection(this.getElementsByTagName('a'), 'Link'); - + }, get location(){ return $w.location }, get referrer(){ /* TODO */ - return this._refferer; - + return this._refferer; + }, get URL(){ /* TODO*/ - return this._url; - + return this._url; + }, - close : function(){ - /* TODO */ + close : function(){ + /* TODO */ this._open = false; }, getElementsByName : function(name){ @@ -5542,28 +5542,28 @@ __extend__(HTMLDocument.prototype, { } return retNodes; }, - open : function(){ + open : function(){ /* TODO */ - this._open = true; + this._open = true; }, - write: function(htmlstring){ + write: function(htmlstring){ /* TODO */ - return; - + return; + }, - writeln: function(htmlstring){ - this.write(htmlstring+'\n'); + writeln: function(htmlstring){ + this.write(htmlstring+'\n'); }, - toString: function(){ - return "Document" + (typeof this._url == "string" ? ": " + this._url : ""); + toString: function(){ + return "Document" + (typeof this._url == "string" ? ": " + this._url : ""); }, - get innerHTML(){ - return this.documentElement.outerHTML; - + get innerHTML(){ + return this.documentElement.outerHTML; + }, get __html__(){ return true; - + } }); @@ -6332,7 +6332,7 @@ $w.HTMLModElement = HTMLModElement; /* */ -$debug("Defining HTMLTextAreaElement"); +$debug("Defining HTMLDivElement"); /* * HTMLDivElement - DOM Level 2 */ @@ -6350,7 +6350,8 @@ __extend__(HTMLDivElement.prototype, { } }); -$w.HTMLDivElement = HTMLDivElement;$debug("Defining HTMLFieldSetElement"); +$w.HTMLDivElement = HTMLDivElement; +$debug("Defining HTMLFieldSetElement"); /* * HTMLFieldSetElement - DOM Level 2 */ @@ -9516,12 +9517,18 @@ window.setTimeout = function(fn, time){ tfn = function() { fn(); window.clearInterval(num); - } + }; } - $debug("Creating timer number "+num); - $timers[num] = new $env.timer(tfn, time); - $timers[num].start(); - return num; + + if (time === 0){ + tfn(); + } + else { + $debug("Creating timer number "+num); + $timers[num] = new $env.timer(tfn, time); + $timers[num].start(); + return num; + } }; window.setInterval = function(fn, time){ diff --git a/rhino/mainForEnvjs.jar b/rhino/mainForEnvjs.jar index 0edbd5f44f9a0dbe6b54ee819f476b3fc9325281..948e1a9926ae323571d342af73d8176f501b1ac9 100644 GIT binary patch delta 2456 zcmV;J31{|zB@3IG5A004Y@0XvZnCj@(Y0Xwld#RU?3djUK3=v-742><}` z6aWA_0FzM=9Fr^tBY#_W6W0~~#?olU@?aYi12UAD07kwc;wF%aOX3 z26-&Y8PAx}$XuF2D9{#4(uUIX1|=jRE^XQd+S)Oc%kl$VtN)-+ee6SD`&{~+ku>Ha z$6k3!y{t25&e>=0Z-0BAea`&-zc+3Jcp7)YSd0UraTH`#ynm!(uZmYxyryDMMYoD! z1#TD>$cbiDGzS$Nsz4PEt2k1QZ{tnz@*M?7E3g8`gs!*3IF9csI1xq^C&kDq1>aNg z{VdX6dhQ5X$4py0=0yo+-c_zBJ{_-Po;cuzDx z6C*!Y@C%{*mw#cz@GA+SjTtNBZk7;;HtvxS?6CU{2~|BA%jnGw?>C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qhqTdAx%aA5(N)j&+H&iO!&-0nhj@#uADi(v`sGYuH?MSXZv0 zb6YsDRc%$zu73ze%<~s;NLO0bicq4lqP|h6Z=6TH*bscax<%6)buRt%j_6@MQYKF(dAH^=a-(0}FA~8e@^%^b^OGP-k00Ti{%%~M zkC%B&r%Gy7Gs-q&61z%?R?cka{@wh~aU^m(S>q>J<0o0;Ct2Y~rH7-`5@i3`Isw>2BDo T2mk=16O#oJUk3ON00000SKM`v diff --git a/src/html/div.js b/src/html/div.js index a17c5e85..997c51e8 100644 --- a/src/html/div.js +++ b/src/html/div.js @@ -7,7 +7,7 @@ */ -$debug("Defining HTMLTextAreaElement"); +$debug("Defining HTMLDivElement"); /* * HTMLDivElement - DOM Level 2 */ @@ -25,4 +25,4 @@ __extend__(HTMLDivElement.prototype, { } }); -$w.HTMLDivElement = HTMLDivElement; \ No newline at end of file +$w.HTMLDivElement = HTMLDivElement; diff --git a/src/html/document.js b/src/html/document.js index eed7320e..50e18093 100644 --- a/src/html/document.js +++ b/src/html/document.js @@ -69,7 +69,7 @@ __extend__(HTMLDocument.prototype, { else if(tagName.match(/TABLE/)) {node = new HTMLTableElement(this);} else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLSectionElement(this);} else if(tagName.match(/TD|TH/)) {node = new HTMLTableCellElement(this);} - else if(tagName.match(/TEXTAREA/)) {node = new HTMLElement(this);} + else if(tagName.match(/TEXTAREA/)) {node = new HTMLTextAreaElement(this);} else if(tagName.match(/TITLE/)) {node = new HTMLTitleElement(this);} else if(tagName.match(/TR/)) {node = new HTMLTableRowElement(this);} else if(tagName.match(/UL/)) {node = new HTMLElement(this);} From a97e3d4547455131f78fd83a4abc91e647db8c44 Mon Sep 17 00:00:00 2001 From: "Glen E. Ivey" Date: Mon, 10 Aug 2009 16:54:09 -0700 Subject: [PATCH 2/6] Changed behavior to match earlier version of env.js, so that if setTimer is called with time=0, the function passed to setTimer is executed immediately and not deferred. --- dist/env.js | 19 ++++++++++++++----- dist/env.rhino.js | 27 +++++++++++++++++++-------- src/window/timer.js | 19 ++++++++++++++----- test/unit/timer.js | 12 ++++++++++-- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/dist/env.js b/dist/env.js index ff35638a..f00e0361 100644 --- a/dist/env.js +++ b/dist/env.js @@ -8784,12 +8784,21 @@ window.setTimeout = function(fn, time){ tfn = function() { fn(); window.clearInterval(num); - } + }; } - $debug("Creating timer number "+num); - $timers[num] = new $env.timer(tfn, time); - $timers[num].start(); - return num; + + if (time === 0){ + if (typeof fn == 'string') + eval(fn); + else + fn(); + } + else { + $debug("Creating timer number "+num); + $timers[num] = new $env.timer(tfn, time); + $timers[num].start(); + return num; + } }; window.setInterval = function(fn, time){ diff --git a/dist/env.rhino.js b/dist/env.rhino.js index 752fc41c..a5990b99 100644 --- a/dist/env.rhino.js +++ b/dist/env.rhino.js @@ -231,20 +231,22 @@ var Envjs = function(){ if (timer.at <= now){ f = timer.fn; f(); - timer.at = Date.now() + timer.interval; + timer.at += timer.interval; } } empty = true; sleep = null; now = Date.now(); for (i in timers){ - empty = false; + empty = false; timer = timers[i]; after = timer.at - now sleep = (sleep === null || after < sleep) ? after : sleep; } sleep = sleep < 0 ? 0 : sleep; - if (empty || ( wait !== 0 ) && ( ( sleep > 0 && !wait ) || ( Date.now() + sleep > wait ) ) ) { + if (empty || + ( wait !== 0 ) && + ( ( sleep > 0 && !wait ) || ( Date.now() + sleep > wait ) ) ) { break; } if (sleep) { @@ -9221,12 +9223,21 @@ window.setTimeout = function(fn, time){ tfn = function() { fn(); window.clearInterval(num); - } + }; } - $debug("Creating timer number "+num); - $timers[num] = new $env.timer(tfn, time); - $timers[num].start(); - return num; + + if (time === 0){ + if (typeof fn == 'string') + eval(fn); + else + fn(); + } + else { + $debug("Creating timer number "+num); + $timers[num] = new $env.timer(tfn, time); + $timers[num].start(); + return num; + } }; window.setInterval = function(fn, time){ diff --git a/src/window/timer.js b/src/window/timer.js index 380e6051..31234cee 100644 --- a/src/window/timer.js +++ b/src/window/timer.js @@ -21,12 +21,21 @@ window.setTimeout = function(fn, time){ tfn = function() { fn(); window.clearInterval(num); - } + }; } - $debug("Creating timer number "+num); - $timers[num] = new $env.timer(tfn, time); - $timers[num].start(); - return num; + + if (time === 0){ + if (typeof fn == 'string') + eval(fn); + else + fn(); + } + else { + $debug("Creating timer number "+num); + $timers[num] = new $env.timer(tfn, time); + $timers[num].start(); + return num; + } }; window.setInterval = function(fn, time){ diff --git a/test/unit/timer.js b/test/unit/timer.js index 2a7c28dc..452dc952 100644 --- a/test/unit/timer.js +++ b/test/unit/timer.js @@ -1,10 +1,13 @@ module("timer"); test("runnable callbacks are run until wait", function() { - expect(2); + expect(1); var occurred = 0; setTimeout(function(){ occurred = Date.now(); }, 0); - ok( occurred === 0, "Timeout should not have been executed" ); +// don't execute the following any more--have reverted window/timer.js changes +// so that setTimeout/Interval functions with time=0 *are* executed prior +// within the call to setTimeout/Interval +// ok( occurred === 0, "Timeout should not have been executed" ); $wait(); ok( occurred !== 0, "Timeout was not executed" ); }); @@ -43,6 +46,10 @@ test("wait(n) does not execute nonrunnable callbacks", function() { ok( occurred !== 0, "Timeout should have been executed" ); }); +// don't execute the following any more--have reverted window/timer.js changes +// so that setTimeout/Interval functions with time=0 *are* executed prior +// within the call to setTimeout/Interval +/* test("cleared callbacks don't get executed", function() { expect(1); var occurred = 0; @@ -51,3 +58,4 @@ test("cleared callbacks don't get executed", function() { $wait(); ok( occurred === 0, "Timeout should not have executed" ); }); +*/ From b3310588d4ac28088559c419d13bfbf310ccdc5d Mon Sep 17 00:00:00 2001 From: "Glen E. Ivey" Date: Tue, 11 Aug 2009 20:21:54 -0700 Subject: [PATCH 3/6] Implementing the