[Webkit-unassigned] [Bug 12405] New: DOM nodes should be true Javascript objects

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Jan 25 09:46:47 PST 2007


http://bugs.webkit.org/show_bug.cgi?id=12405

           Summary: DOM nodes should be true Javascript objects
           Product: WebKit
           Version: 420+ (nightly)
          Platform: Macintosh
        OS/Version: Mac OS X 10.4
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: HTML DOM
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: ggaren at apple.com


This bug is also in Radar as <rdar://4799485>

Hi

I've been doing a lot of Javascript OOP programming lately and ran up against a
problem in Safari that works fine in Firefox. In Firefox, it's possible to use
a DOM node as a "superclass" of a custom object type, for example:

JSDiv.prototype                 = document.createElement('div');
JSTextInput.prototype   = document.createElement('input');
JSImg.prototype                 = document.createElement('img');
etc...

Which allows the creation of subclasses like this

function JSDiv(inContainer, inID, inStyle) {
        this.setAttribute('id', inID);
        this.setAttribute('class', inStyle);
        inContainer.appendChild(this);
}

function JSTextInput(inContainer, inID, inStyle) {
        this.setAttribute('id', inID);
        this.setAttribute('class', inStyle);
        this.setAttribute('type', 'text');
        inContainer.appendChild(this);
}

function JSTextInput(inContainer, inID, inStyle, inURL) {
        this.setAttribute('id', inID);
        this.setAttribute('class', inStyle);
        this.setAttribute('src', inURL);
        inContainer.appendChild(this);
}

Further allowing the use of the powerful Object.watch method like so

x = new JSDiv(document.body, 1, 'div_style');
y = new JSTextInput(document.body, 1, 'text_style');
z = new JSImg(document.body, 1, 'text_style', '../png/some_image.png');

x.watch(style.color, y.displayColorValue);
y.watch(style.width, z.growImage);
z.watch(url, x.doSomething);

Firefox already allows this type of stuff and it would be great if Safari did
as well. It becomes so much easier to create slick Web 2.0 stuff if the DOM
nodes are Javascript objects (or can at least pose as them)

Thanks

<GMT28-Oct-2006 02:49:20GMT> Ken Tozier:
Safari fails in two important ways:

Test 1: Defining object prototype as a 'div', 'img', 'input' etc produces an
object, not a div

Test 2: Defining a 'watch' handler on a manually created div never fires

Attached is the simplest test case I could come up with. Just drop it in the
"WebServer->documents folder" and open in both Safari and Firefox.

Firefox displays the desired behavior for both "Test 1" and 'Test 2" above

Because Safari won't even run test 1 succeessfully, you'll need comment out the
indicated line to see the "Object.watch" failure.


'safari_bug_test.html' was successfully uploaded

-------------------------------------------

<GMT27-Oct-2006 18:09:28GMT> Geoff Garen:
This bug suggests that there's an architectural flaw in WebKit, where DOM nodes
do not correspond to true JavaScript objects. That's incorrect. They do. So we
need more information about exactly what JavaScript technique doesn't work. A
reduced testcase demonstrating expected and actual results would be best.

<GMT28-Oct-2006 02:49:20GMT> Ken Tozier:
New information added to Description via RadarWeb


-- 
Configure bugmail: http://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list