Commit 27b705a1 authored by ggaren's avatar ggaren

LayoutTests:

        - Merged test-prototypes.html into global-constructors.html
        - Added prototypes.html, which tests for some missing prototypes in DOM objects
        
        * fast/dom/global-constructors-expected.txt:
        * fast/dom/global-constructors.html:
        * fast/dom/prototypes-expected.txt: Added.
        * fast/dom/prototypes.html: Added.
        * fast/dom/test-prototypes-expected.txt: Removed.
        * fast/dom/test-prototypes.html: Removed.
        * fast/dom/undetectable-document-all-expected.txt: Updated to reflect
        change from "HTMLCollection" to "Collection"

WebCore:

        Reviewed by Darin.

        - http://bugzilla.opendarwin.org/show_bug.cgi?id=9310
        Add missing DOM prototypes and other DOM cleanup

        - Added the built-in object prototype to DOM objects that were missing it
        so that primitive operations like == work on them.
        
        - Removed dead EventConstructor class (it's autogenerated now)
        
        - Changed HTML collections to describe themselves as "[object Collection]",
        to match IE.
        
        - Made DOMCSSRule constructor private because JSCSSRule is the class
        to use.
        
        * bindings/js/JSHTMLOptionElementConstructor.cpp:
        (WebCore::JSHTMLOptionElementConstructor::JSHTMLOptionElementConstructor):
        * bindings/js/kjs_css.cpp:
        (KJS::DOMStyleSheet::DOMStyleSheet):
        (KJS::DOMStyleSheetList::DOMStyleSheetList):
        (KJS::DOMCSSRule::DOMCSSRule):
        (KJS::DOMCSSValue::DOMCSSValue):
        (KJS::toJS):
        (KJS::DOMRGBColor::DOMRGBColor):
        (KJS::getDOMRGBColor):
        (KJS::DOMRect::DOMRect):
        * bindings/js/kjs_css.h:
        * bindings/js/kjs_dom.cpp:
        (KJS::DOMNodeList::DOMNodeList):
        (KJS::DOMExceptionConstructor::DOMExceptionConstructor):
        (KJS::DOMExceptionConstructor::getOwnPropertySlot):
        (KJS::):
        (KJS::DOMNamedNodesCollection::DOMNamedNodesCollection):
        * bindings/js/kjs_dom.h:
        (KJS::DOMNamedNodesCollection::classInfo):
        * bindings/js/kjs_events.h:
        * bindings/js/kjs_html.cpp:
        (KJS::):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@14735 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent df6e53c9
2006-06-04 Geoffrey Garen <ggaren@apple.com>
- Merged test-prototypes.html into global-constructors.html
- Added prototypes.html, which tests for some missing prototypes in DOM objects
* fast/dom/global-constructors-expected.txt:
* fast/dom/global-constructors.html:
* fast/dom/prototypes-expected.txt: Added.
* fast/dom/prototypes.html: Added.
* fast/dom/test-prototypes-expected.txt: Removed.
* fast/dom/test-prototypes.html: Removed.
* fast/dom/undetectable-document-all-expected.txt: Updated to reflect
change from "HTMLCollection" to "Collection"
2006-06-04 Darin Adler <darin@apple.com>
- test for http://bugzilla.opendarwin.org/show_bug.cgi?id=9176
This page tests global constructor objects like window.HTMLDocument. If it passes, you'll see a series of 'PASS' messages below.
This page tests constructors and prototypes that WebKit has gotten wrong in the past. If it passes, you'll see a series of 'PASS' messages below.
PASS: DOMParser.prototype.isPrototypeOf(domParser) should be true and is.
PASS: XMLHttpRequest.prototype.isPrototypeOf(xmlHttpRequest) should be true and is.
PASS: XMLSerializer.prototype.isPrototypeOf(xmlSerializer) should be true and is.
PASS: XSLTProcessor.prototype.isPrototypeOf(xsltProcessor) should be true and is.
PASS: window.Document.prototype.isPrototypeOf(document) should be true and is.
PASS: window.HTMLDocument.prototype.isPrototypeOf(document) should be true and is.
PASS: window.Node.prototype.isPrototypeOf(element) should be true and is.
......
......@@ -16,9 +16,6 @@ function print(message, color)
document.getElementById("console").appendChild(paragraph);
}
var element, range, nodeFilter, cssRule, cssPrimitiveValue, cssStyleDeclaration, event;
var originalNodeConstructor;
function shouldBe(a, b)
{
var evalA;
......@@ -37,7 +34,19 @@ function test()
{
if (window.layoutTestController)
layoutTestController.dumpAsText();
domParser = new DOMParser();
shouldBe("DOMParser.prototype.isPrototypeOf(domParser)", true);
xmlHttpRequest = new XMLHttpRequest();
shouldBe("XMLHttpRequest.prototype.isPrototypeOf(xmlHttpRequest)", true);
xmlSerializer = new XMLSerializer();
shouldBe("XMLSerializer.prototype.isPrototypeOf(xmlSerializer)", true);
xsltProcessor = new XSLTProcessor();
shouldBe("XSLTProcessor.prototype.isPrototypeOf(xsltProcessor)", true);
shouldBe("window.Document.prototype.isPrototypeOf(document)", true);
shouldBe("window.HTMLDocument.prototype.isPrototypeOf(document)", true);
......
This test checks some DOM object prototypes that WebKit has gotten wrong in the past. If the test passes, you'll see a series of 'PASS' messages below.
PASS: Object.prototype.isPrototypeOf(window.DOMException) should be true and is.
PASS: Object.prototype.isPrototypeOf(window.Option) should be true and is.
PASS: Object.prototype.isPrototypeOf(cssValue) should be true and is.
PASS: Object.prototype.isPrototypeOf(rgbColor) should be true and is.
PASS: Object.prototype.isPrototypeOf(rect) should be true and is.
PASS: Object.prototype.isPrototypeOf(styleSheetList) should be true and is.
PASS: Object.prototype.isPrototypeOf(styleSheet) should be true and is.
PASS: Object.prototype.isPrototypeOf(cssRule) should be true and is.
PASS: Object.prototype.isPrototypeOf(nodeList) should be true and is.
PASS: Object.prototype.isPrototypeOf(namedNodesCollection) should be true and is.
<html>
<head>
<script>
function print(message, color)
{
var paragraph = document.createElement("div");
paragraph.appendChild(document.createTextNode(message));
paragraph.style.fontFamily = "monospace";
if (color)
paragraph.style.color = color;
document.getElementById("console").appendChild(paragraph);
}
function shouldBe(a, b)
{
var evalA;
try {
evalA = eval(a);
} catch(e) {
evalA = e;
}
if (evalA == b)
print("PASS: " + a + " should be " + b + " and is.", "green");
else
print("FAIL: " + a + " should be " + b + " but instead is " + evalA + ".", "red");
}
function test()
{
if (window.layoutTestController)
layoutTestController.dumpAsText();
shouldBe("Object.prototype.isPrototypeOf(window.DOMException)", true);
shouldBe("Object.prototype.isPrototypeOf(window.Option)", true);
div = document.createElement('div');
div.style.color = "black";
cssValue = div.style.getPropertyCSSValue('color'); // actually a CSSPrimitiveValue
shouldBe("Object.prototype.isPrototypeOf(cssValue)", true);
rgbColor = div.style.getPropertyCSSValue('color').getRGBColorValue();
shouldBe("Object.prototype.isPrototypeOf(rgbColor)", true);
div.style.clip = "rect(0, 0, 0, 0)";
rect = div.style.getPropertyCSSValue('clip').getRectValue();
shouldBe("Object.prototype.isPrototypeOf(rect)", true);
styleElement = document.createElement('style');
styleElement.appendChild(document.createTextNode("* {}"));
headElement = document.getElementsByTagName('head')[0];
headElement.appendChild(styleElement);
styleSheetList = document.styleSheets;
shouldBe("Object.prototype.isPrototypeOf(styleSheetList)", true);
styleSheet = styleSheetList[0];
shouldBe("Object.prototype.isPrototypeOf(styleSheet)", true);
cssRule = styleSheet.cssRules[0];
shouldBe("Object.prototype.isPrototypeOf(cssRule)", true);
nodeList = document.getElementsByTagName('html');
shouldBe("Object.prototype.isPrototypeOf(nodeList)", true);
var form = document.createElement('form');
form.name = 'myForm';
document.body.appendChild(form);
document.body.appendChild(form.cloneNode(true));
namedNodesCollection = document.forms.myForm;
shouldBe("Object.prototype.isPrototypeOf(namedNodesCollection)", true);
}
</script>
</head>
<body onload="test();">
<p>This test checks some DOM object prototypes that WebKit has gotten wrong in the past.
If the test passes, you'll see a series of 'PASS' messages below.</p>
<hr>
<div id='console'></div>
</body>
</html>
This checks that DOMParser, XMLHttpRequest, XMLSerializer and XSLTProcessor have their prototypes set correctly. If this test is successful, the text "SUCCESS" will be shown below.
SUCCESS!
<html>
<head>
<script>
function debug(str) {
var c = document.getElementById('console')
c.innerHTML += (str + "<br>")
}
var numErrors = 0;
function testPrototype(name)
{
func = eval(name);
if (!func.prototype) {
debug("FAILURE: " + name + " did not have a prototype defined.")
numErrors++;
return;
}
// Create an object
o = new func()
if (!func.prototype.isPrototypeOf(o)) {
debug('FAILURE: Newly created object of type ' + name + " does not have " + name + ".prototype in it's prototype chain.");
numErrors++;
}
}
function runTests() {
if (window.layoutTestController)
layoutTestController.dumpAsText();
testPrototype("DOMParser");
testPrototype("XMLHttpRequest");
testPrototype("XMLSerializer");
testPrototype("XSLTProcessor");
if (numErrors == 0)
debug('SUCCESS!')
}
</script>
</head>
<body onload="runTests();">
This checks that DOMParser, XMLHttpRequest, XMLSerializer and XSLTProcessor have their prototypes set correctly. If this test is successful, the text "SUCCESS" will be shown below.
<pre id="console"></pre>
</body>
</html>
This tests that document.all should be undetectable, and that it should be possible to set document.all to something else. If this test is successful, the text "SUCCESS" should be shown below.
document.all: [object HTMLCollection]
document.all: [object Collection]
SUCCESS!
2006-06-05 Geoffrey Garen <ggaren@apple.com>
Reviewed by Darin.
- http://bugzilla.opendarwin.org/show_bug.cgi?id=9310
Add missing DOM prototypes and other DOM cleanup
- Added the built-in object prototype to DOM objects that were missing it
so that primitive operations like == work on them.
- Removed dead EventConstructor class (it's autogenerated now)
- Changed HTML collections to describe themselves as "[object Collection]",
to match IE.
- Made DOMCSSRule constructor private because JSCSSRule is the class
to use.
* bindings/js/JSHTMLOptionElementConstructor.cpp:
(WebCore::JSHTMLOptionElementConstructor::JSHTMLOptionElementConstructor):
* bindings/js/kjs_css.cpp:
(KJS::DOMStyleSheet::DOMStyleSheet):
(KJS::DOMStyleSheetList::DOMStyleSheetList):
(KJS::DOMCSSRule::DOMCSSRule):
(KJS::DOMCSSValue::DOMCSSValue):
(KJS::toJS):
(KJS::DOMRGBColor::DOMRGBColor):
(KJS::getDOMRGBColor):
(KJS::DOMRect::DOMRect):
* bindings/js/kjs_css.h:
* bindings/js/kjs_dom.cpp:
(KJS::DOMNodeList::DOMNodeList):
(KJS::DOMExceptionConstructor::DOMExceptionConstructor):
(KJS::DOMExceptionConstructor::getOwnPropertySlot):
(KJS::):
(KJS::DOMNamedNodesCollection::DOMNamedNodesCollection):
* bindings/js/kjs_dom.h:
(KJS::DOMNamedNodesCollection::classInfo):
* bindings/js/kjs_events.h:
* bindings/js/kjs_html.cpp:
(KJS::):
2006-06-04 Darin Adler <darin@apple.com>
Reviewed by Maciej.
......
......@@ -32,6 +32,7 @@ namespace WebCore {
JSHTMLOptionElementConstructor::JSHTMLOptionElementConstructor(ExecState* exec, Document* d)
: m_doc(d)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
put(exec, lengthPropertyName, jsNumber(4), ReadOnly|DontDelete|DontEnum);
}
......
......@@ -278,9 +278,10 @@ const ClassInfo DOMStyleSheet::info = { "StyleSheet", 0, &DOMStyleSheetTable, 0
@end
*/
DOMStyleSheet::DOMStyleSheet(ExecState*, WebCore::StyleSheet* ss)
DOMStyleSheet::DOMStyleSheet(ExecState* exec, WebCore::StyleSheet* ss)
: m_impl(ss)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
}
DOMStyleSheet::DOMStyleSheet(WebCore::StyleSheet *ss)
......@@ -359,10 +360,11 @@ const ClassInfo DOMStyleSheetList::info = { "StyleSheetList", 0, &DOMStyleSheetL
*/
KJS_IMPLEMENT_PROTOFUNC(DOMStyleSheetListFunc) // not really a proto, but doesn't matter
DOMStyleSheetList::DOMStyleSheetList(ExecState*, WebCore::StyleSheetList* ssl, WebCore::Document* doc)
DOMStyleSheetList::DOMStyleSheetList(ExecState* exec, WebCore::StyleSheetList* ssl, WebCore::Document* doc)
: m_impl(ssl)
, m_doc(doc)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
}
DOMStyleSheetList::~DOMStyleSheetList()
......@@ -642,7 +644,7 @@ JSValue* DOMCSSStyleSheetProtoFunc::callAsFunction(ExecState* exec, JSObject* th
KJS_IMPLEMENT_PROTOFUNC(DOMCSSRuleFunc) // Not a proto, but doesn't matter
DOMCSSRule::DOMCSSRule(ExecState*, WebCore::CSSRule* r)
DOMCSSRule::DOMCSSRule(ExecState* exec, WebCore::CSSRule* r)
: m_impl(r)
{
}
......@@ -856,6 +858,12 @@ const ClassInfo DOMCSSValue::info = { "CSSValue", 0, &DOMCSSValueTable, 0 };
KJS_IMPLEMENT_PROTOFUNC(DOMCSSValueProtoFunc)
KJS_IMPLEMENT_PROTOTYPE("DOMCSSValue", DOMCSSValueProto, DOMCSSValueProtoFunc)
DOMCSSValue::DOMCSSValue(ExecState* exec, WebCore::CSSValue* v)
: m_impl(v)
{
setPrototype(DOMCSSValueProto::self(exec));
}
DOMCSSValue::~DOMCSSValue()
{
ScriptInterpreter::forgetDOMObject(m_impl.get());
......@@ -908,7 +916,7 @@ JSValue* toJS(ExecState* exec, CSSValue *v)
else if (v->isPrimitiveValue())
ret = new JSCSSPrimitiveValue(exec, static_cast<CSSPrimitiveValue*>(v));
else
ret = new DOMCSSValue(exec,v);
ret = new DOMCSSValue(exec, v);
interp->putDOMObject(v, ret);
return ret;
}
......@@ -925,6 +933,12 @@ const ClassInfo DOMRGBColor::info = { "RGBColor", 0, &DOMRGBColorTable, 0 };
blue DOMRGBColor::Blue DontDelete|ReadOnly
@end
*/
DOMRGBColor::DOMRGBColor(ExecState* exec, unsigned color)
: m_color(color)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
}
DOMRGBColor::~DOMRGBColor()
{
//rgbColors.remove(rgbColor.handle());
......@@ -952,10 +966,10 @@ JSValue* DOMRGBColor::getValueProperty(ExecState* exec, int token) const
}
}
JSValue* getDOMRGBColor(ExecState *, unsigned c)
JSValue* getDOMRGBColor(ExecState* exec, unsigned c)
{
// ### implement equals for RGBColor since they're not refcounted objects
return new DOMRGBColor(c);
return new DOMRGBColor(exec, c);
}
// -------------------------------------------------------------------------
......@@ -969,6 +983,12 @@ const ClassInfo DOMRect::info = { "Rect", 0, &DOMRectTable, 0 };
left DOMRect::Left DontDelete|ReadOnly
@end
*/
DOMRect::DOMRect(ExecState* exec, WebCore::RectImpl* r)
: m_rect(r)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
}
DOMRect::~DOMRect()
{
ScriptInterpreter::forgetDOMObject(m_rect.get());
......
......@@ -36,6 +36,7 @@ namespace WebCore {
class CSSStyleSheet;
class CSSValue;
class CSSValueList;
class JSCSSRule;
class JSCSSStyleDeclaration;
class MediaList;
class StyleSheet;
......@@ -150,7 +151,6 @@ namespace KJS {
class DOMCSSRule : public DOMObject {
public:
DOMCSSRule(ExecState*, WebCore::CSSRule*);
virtual ~DOMCSSRule();
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
JSValue* getValueProperty(ExecState*, int token) const;
......@@ -165,6 +165,8 @@ namespace KJS {
Import_Href, Import_Media, Import_StyleSheet, Charset_Encoding };
WebCore::CSSRule* impl() const { return m_impl.get(); }
private:
friend class WebCore::JSCSSRule;
DOMCSSRule(ExecState*, WebCore::CSSRule*);
RefPtr<WebCore::CSSRule> m_impl;
};
......@@ -172,7 +174,7 @@ namespace KJS {
class DOMCSSValue : public DOMObject {
public:
DOMCSSValue(ExecState*, WebCore::CSSValue* v) : m_impl(v) { }
DOMCSSValue(ExecState*, WebCore::CSSValue*);
virtual ~DOMCSSValue();
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
JSValue* getValueProperty(ExecState*, int token) const;
......@@ -194,7 +196,7 @@ namespace KJS {
class DOMRGBColor : public DOMObject {
public:
DOMRGBColor(unsigned color) : m_color(color) { }
DOMRGBColor(ExecState*, unsigned color);
~DOMRGBColor();
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
JSValue* getValueProperty(ExecState*, int token) const;
......@@ -210,7 +212,7 @@ namespace KJS {
class DOMRect : public DOMObject {
public:
DOMRect(ExecState*, WebCore::RectImpl* r) : m_rect(r) { }
DOMRect(ExecState*, WebCore::RectImpl* r);
~DOMRect();
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
JSValue* getValueProperty(ExecState*, int token) const;
......
......@@ -709,6 +709,12 @@ KJS_IMPLEMENT_PROTOFUNC(DOMNodeListFunc)
const ClassInfo DOMNodeList::info = { "NodeList", 0, &DOMNodeListTable, 0 };
DOMNodeList::DOMNodeList(ExecState* exec, WebCore::NodeList *l)
: m_impl(l)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
}
DOMNodeList::~DOMNodeList()
{
ScriptInterpreter::forgetDOMObject(m_impl.get());
......@@ -1070,7 +1076,12 @@ const ClassInfo DOMExceptionConstructor::info = { "DOMExceptionConstructor", 0,
@end
*/
bool DOMExceptionConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
DOMExceptionConstructor::DOMExceptionConstructor(ExecState* exec)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
}
bool DOMExceptionConstructor::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
{
return getStaticValueSlot<DOMExceptionConstructor, DOMObject>(exec, &DOMExceptionConstructorTable, this, propertyName, slot);
}
......@@ -1088,12 +1099,15 @@ JSObject* getDOMExceptionConstructor(ExecState* exec)
// -------------------------------------------------------------------------
const ClassInfo DOMNamedNodesCollection::info = { "Collection", 0, 0, 0 };
// Such a collection is usually very short-lived, it only exists
// for constructs like document.forms.<name>[1],
// so it shouldn't be a problem that it's storing all the nodes (with the same name). (David)
DOMNamedNodesCollection::DOMNamedNodesCollection(ExecState*, const DeprecatedValueList< RefPtr<WebCore::Node> >& nodes )
: m_nodes(nodes)
DOMNamedNodesCollection::DOMNamedNodesCollection(ExecState* exec, const DeprecatedValueList< RefPtr<WebCore::Node> >& nodes )
: m_nodes(nodes)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
}
JSValue* DOMNamedNodesCollection::lengthGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
......
......@@ -75,7 +75,7 @@ namespace KJS {
class DOMNodeList : public DOMObject {
public:
DOMNodeList(ExecState *, WebCore::NodeList *l) : m_impl(l) { }
DOMNodeList(ExecState *, WebCore::NodeList *l);
~DOMNodeList();
virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
JSValue *getValueProperty(ExecState *exec, int token) const;
......@@ -126,7 +126,7 @@ namespace KJS {
// Constructor for DOMException - constructor stuff not implemented yet
class DOMExceptionConstructor : public DOMObject {
public:
DOMExceptionConstructor(ExecState *) { }
DOMExceptionConstructor(ExecState*);
virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
JSValue *getValueProperty(ExecState *exec, int token) const;
// no put - all read-only
......@@ -149,7 +149,9 @@ namespace KJS {
public:
DOMNamedNodesCollection(ExecState *exec, const DeprecatedValueList< RefPtr<WebCore::Node> >& nodes );
virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
private:
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
private:
static JSValue *lengthGetter(ExecState* exec, JSObject *, const Identifier&, const PropertySlot& slot);
static JSValue *indexGetter(ExecState* exec, JSObject *, const Identifier&, const PropertySlot& slot);
......
......@@ -94,19 +94,6 @@ namespace KJS {
JSValue* getNodeEventListener(WebCore::Node* n, const WebCore::AtomicString& eventType);
// Constructor for Event - currently only used for some global vars
class EventConstructor : public DOMObject {
public:
EventConstructor(ExecState*) { }
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
JSValue* getValueProperty(ExecState*, int token) const;
// no put - all read-only
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
};
JSValue* getEventConstructor(ExecState*);
class DOMEvent : public DOMObject {
public:
DOMEvent(ExecState*, WebCore::Event*);
......
......@@ -1587,7 +1587,7 @@ KJS_DEFINE_PROTOTYPE(HTMLCollectionProto)
KJS_IMPLEMENT_PROTOFUNC(HTMLCollectionProtoFunc)
KJS_IMPLEMENT_PROTOTYPE("HTMLCollection",HTMLCollectionProto,HTMLCollectionProtoFunc)
const ClassInfo JSHTMLCollection::info = { "HTMLCollection", 0, 0, 0 };
const ClassInfo JSHTMLCollection::info = { "Collection", 0, 0, 0 };
JSHTMLCollection::JSHTMLCollection(ExecState* exec, HTMLCollection *c)
: m_impl(c)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment