Skip to content

Commit

Permalink
Merge branch 'timer-fix' into multi-window
Browse files Browse the repository at this point in the history
  • Loading branch information
gleneivey committed Aug 10, 2009
2 parents 04074a3 + a97e3d4 commit 878bffc
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 83 deletions.
79 changes: 41 additions & 38 deletions dist/env.js
Expand Up @@ -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);}
Expand Down Expand Up @@ -5001,27 +5001,27 @@ __extend__(HTMLDocument.prototype, {
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(){
Expand Down Expand Up @@ -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){
Expand All @@ -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;

}
});

Expand Down Expand Up @@ -9078,11 +9078,14 @@ window.setTimeout = function(fn, time){
tfn = function() {
fn();
window.clearInterval(num);
};
};
}

if (time === 0){
tfn();
if (typeof fn == 'string')
eval(fn);
else
fn();
}
else {
$debug("Creating timer number "+num);
Expand Down
79 changes: 41 additions & 38 deletions dist/env.rhino.js
Expand Up @@ -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);}
Expand Down Expand Up @@ -5440,27 +5440,27 @@ __extend__(HTMLDocument.prototype, {
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(){
Expand Down Expand Up @@ -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){
Expand All @@ -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;

}
});

Expand Down Expand Up @@ -9517,11 +9517,14 @@ window.setTimeout = function(fn, time){
tfn = function() {
fn();
window.clearInterval(num);
};
};
}

if (time === 0){
tfn();
if (typeof fn == 'string')
eval(fn);
else
fn();
}
else {
$debug("Creating timer number "+num);
Expand Down
Binary file modified rhino/mainForEnvjs.jar
Binary file not shown.
19 changes: 14 additions & 5 deletions src/window/timer.js
Expand Up @@ -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){
Expand Down
12 changes: 10 additions & 2 deletions 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" );
});
Expand Down Expand Up @@ -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;
Expand All @@ -51,3 +58,4 @@ test("cleared callbacks don't get executed", function() {
$wait();
ok( occurred === 0, "Timeout should not have executed" );
});
*/

0 comments on commit 878bffc

Please sign in to comment.