This project is archived and is in readonly mode.

#1204 ✓resolved
Moo24

Object.prototype.toString method should be W3C compatible

Reported by Moo24 | March 21st, 2011 @ 11:15 PM | in 2.0 (closed)

Since Mootools version 1.3 the result of the Object.prototype.toString method is not conform with the W3C standard.

Object.prototype.toString.call(new Window()) should return "[object Window]"

Object.prototype.toString.call(new Document()) should return "[object HTMLDocument]"

Object.prototype.toString.call(new Element()) should return "[object HTMLDivElement]"

Currently the first two methods return [object Object] while the third method call returns an error.

I managed to get Mootools 1.3 W3C compatible by changing three lines of code:

1) Replace

this.Window = this.$constructor = new Type('Window', function(){});

with

this.Window = this.$constructor = new Type('Window', function(){

return window;

});

2) Replace

this.Document = document.$constructor = new Type('Document', function(){});

with

this.Document = document.$constructor = new Type('Document', function(){

return document;

});

3) Add the following line to Element

var Element = function(tag, props){
/*

patch for w3c compatiblity to support

Object.prototype.toString.call(new Element()) = "[object HTMLDivElement]";

*/

if (typeof tag === undefined || 'undefined') tag = 'div';

/ end patch for w3c compatiblity /

I attached a fixed version.

Comments and changes to this ticket

  • Arian

    Arian March 22nd, 2011 @ 03:42 PM

    • Milestone set to 1.4.0
    • Assigned user set to “Christoph Pojer”
    • Milestone order changed from “902” to “0”
  • Moo24

    Moo24 March 23rd, 2011 @ 01:29 PM

    Using my suggested change for Element seems to cause other issues. (Sorry I was very tired when creating this ticket)

    We should use
    if (arguments.length==0) tag = 'div';

    instead of
    if (typeof tag === undefined || 'undefined') tag = 'div';

    than it works fine :-)

  • Christoph Pojer

    Christoph Pojer April 14th, 2011 @ 11:23 AM

    • State changed from “new” to “resolved”
    • Milestone changed from 1.4.0 to 2.0
    • Milestone order changed from “8” to “0”

    This will not be fixed in 1.3. We have fixed this for 2.0.

  • Christoph Pojer

    Christoph Pojer April 14th, 2011 @ 11:25 AM

    Alternatively in 1.3 you can use the Core function instanceOf(new Window(), Window) or instanceOf(window, Window).

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Attachments

Pages