[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.21-584-g1e41756

eric at webkit.org eric at webkit.org
Fri Feb 26 22:25:25 UTC 2010


The following commit has been merged in the webkit-1.1 branch:
commit 00b885b76d664ef9f4a49044500a689544139c72
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Feb 19 05:00:52 2010 +0000

    2010-02-18  Yaar Schnitman  <yaar at chromium.org>
    
            Reviewed by Darin Adler.
    
            Normalize custom ctors for Image, Option, Audio
            https://bugs.webkit.org/show_bug.cgi?id=34782
    
            * fast/js/custom-constructors-expected.txt: Added.
            * fast/js/custom-constructors.html: Added.
            * fast/js/script-tests/custom-constructors.js: Added.
    2010-02-18  Yaar Schnitman  <yaar at chromium.org>
    
            Reviewed by Darin Adler.
    
            Normalize custom ctors for Image, Option, Audio
            https://bugs.webkit.org/show_bug.cgi?id=34782
    
            Test: fast/js/custom-constructors.html
    
            * bindings/js/JSAudioConstructor.cpp:
            (WebCore::JSAudioConstructor::JSAudioConstructor):
            (WebCore::constructAudio):
            * bindings/js/JSImageConstructor.cpp:
            (WebCore::constructImage):
            * bindings/js/JSOptionConstructor.cpp:
            (WebCore::constructHTMLOptionElement):
            * bindings/v8/custom/V8HTMLAudioElementConstructor.cpp:
            (WebCore::v8HTMLAudioElementConstructorCallback):
            * bindings/v8/custom/V8HTMLImageElementConstructor.cpp:
            (WebCore::v8HTMLImageElementConstructorCallback):
            * bindings/v8/custom/V8HTMLOptionElementConstructor.cpp:
            (WebCore::v8HTMLOptionElementConstructorCallback):
            * html/HTMLAudioElement.cpp:
            (WebCore::HTMLAudioElement::HTMLAudioElement):
            (WebCore::HTMLAudioElement::createForJSConstructor):
            * html/HTMLAudioElement.h:
            * html/HTMLImageElement.cpp:
            (WebCore::HTMLImageElement::createForJSConstructor):
            (WebCore::HTMLImageElement::mapToEntry):
            (WebCore::HTMLImageElement::createRenderer):
            (WebCore::HTMLImageElement::attach):
            (WebCore::HTMLImageElement::width):
            (WebCore::HTMLImageElement::height):
            (WebCore::HTMLImageElement::naturalHeight):
            * html/HTMLImageElement.h:
            * html/HTMLOptionElement.cpp:
            (WebCore::HTMLOptionElement::HTMLOptionElement):
            (WebCore::HTMLOptionElement::createForJSConstructor):
            (WebCore::HTMLOptionElement::ownerSelectElement):
            (WebCore::HTMLOptionElement::nonRendererRenderStyle):
            (WebCore::HTMLOptionElement::disabled):
            (WebCore::HTMLOptionElement::insertedIntoTree):
            * html/HTMLOptionElement.h:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54999 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index edb5110..ec755b5 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,14 @@
+2010-02-18  Yaar Schnitman  <yaar at chromium.org>
+
+        Reviewed by Darin Adler.
+
+        Normalize custom ctors for Image, Option, Audio
+        https://bugs.webkit.org/show_bug.cgi?id=34782
+
+        * fast/js/custom-constructors-expected.txt: Added.
+        * fast/js/custom-constructors.html: Added.
+        * fast/js/script-tests/custom-constructors.js: Added.
+
 2010-02-18  Alexey Proskuryakov  <ap at apple.com>
 
         Reviewed by Dan Bernstein.
diff --git a/LayoutTests/fast/js/custom-constructors-expected.txt b/LayoutTests/fast/js/custom-constructors-expected.txt
new file mode 100644
index 0000000..e082d10
--- /dev/null
+++ b/LayoutTests/fast/js/custom-constructors-expected.txt
@@ -0,0 +1,48 @@
+This test checks construction of objects with custom constructors.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS new Image() is non-null.
+PASS new Image().tagName is "IMG"
+PASS new Image().height is 0
+PASS new Image().width is 0
+PASS new Image(100).width is 100
+PASS new Image(100, 200).height is 200
+PASS new Image(-100).width is -100
+PASS new Image(-100, -200).height is -200
+PASS new Image().outerHTML is "<img>"
+PASS new Image(100, 100).outerHTML.replace(/"/g, "'") is "<img width='100' height='100'>"
+PASS new Option() is non-null.
+PASS new Option().tagName is "OPTION"
+PASS new Option().innerText is ""
+PASS new Option(null).innerText is "null"
+PASS new Option(undefined).innerText is ""
+PASS new Option('somedata').innerText is "somedata"
+PASS new Option().value is ""
+PASS new Option('somedata', null).value is "null"
+PASS new Option('somedata', undefined).value is "somedata"
+PASS new Option('somedata', 'somevalue').value is "somevalue"
+PASS new Option().defaultSelected is false
+PASS new Option('somedata', 'somevalue').defaultSelected is false
+PASS new Option('somedata', 'somevalue', false).defaultSelected is false
+PASS new Option('somedata', 'somevalue', true).defaultSelected is true
+PASS new Option().selected is false
+PASS new Option('somedata', 'somevalue').selected is false
+PASS new Option('somedata', 'somevalue', false).selected is false
+PASS new Option('somedata', 'somevalue', true).selected is false
+PASS new Option('somedata', 'somevalue', true, false).selected is false
+PASS new Option('somedata', 'somevalue', true, true).selected is true
+PASS new Option().outerHTML is "<option></option>"
+PASS new Option('somedata', 'somevalue', false).outerHTML.replace(/"/g,"'") is "<option value='somevalue'>somedata</option>"
+PASS new Option('somedata', 'somevalue', true).outerHTML.replace(/"/g,"'") is "<option value='somevalue' selected=''>somedata</option>"
+PASS new Audio() is non-null.
+PASS new Audio().tagName is "AUDIO"
+PASS new Audio().src is ""
+PASS new Audio().autobuffer is true
+PASS new Audio('http://localhost/someurl').src is "http://localhost/someurl"
+PASS new Audio('http://localhost/someurl').autobuffer is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/js/custom-constructors.html b/LayoutTests/fast/js/custom-constructors.html
new file mode 100644
index 0000000..c30cbf9
--- /dev/null
+++ b/LayoutTests/fast/js/custom-constructors.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="resources/js-test-style.css">
+<script src="resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/custom-constructors.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/js/script-tests/custom-constructors.js b/LayoutTests/fast/js/script-tests/custom-constructors.js
new file mode 100644
index 0000000..2945e57
--- /dev/null
+++ b/LayoutTests/fast/js/script-tests/custom-constructors.js
@@ -0,0 +1,59 @@
+description(
+"This test checks construction of objects with custom constructors."
+);
+
+// Image tests
+shouldBeNonNull("new Image()");
+shouldBeEqualToString("new Image().tagName", "IMG");
+
+shouldBe("new Image().height", "0");
+shouldBe("new Image().width", "0");
+shouldBe("new Image(100).width", "100");
+shouldBe("new Image(100, 200).height", "200");
+shouldBe("new Image(-100).width", "-100");
+shouldBe("new Image(-100, -200).height", "-200");
+
+shouldBeEqualToString("new Image().outerHTML","<img>");
+// FIXME: shouldBeEqualToString strips quotes from the string.
+shouldBeEqualToString("new Image(100, 100).outerHTML.replace(/\"/g, \"'\")", "<img width='100' height='100'>");
+
+// Option tests
+shouldBeNonNull("new Option()");
+shouldBeEqualToString("new Option().tagName", "OPTION");
+
+shouldBeEqualToString("new Option().innerText", "");
+shouldBeEqualToString("new Option(null).innerText", "null");
+shouldBeEqualToString("new Option(undefined).innerText", "");
+shouldBeEqualToString("new Option('somedata').innerText", "somedata");
+
+shouldBeEqualToString("new Option().value", "");
+shouldBeEqualToString("new Option('somedata', null).value", "null");
+shouldBeEqualToString("new Option('somedata', undefined).value", "somedata");
+shouldBeEqualToString("new Option('somedata', 'somevalue').value", "somevalue");
+
+shouldBeFalse("new Option().defaultSelected");
+shouldBeFalse("new Option('somedata', 'somevalue').defaultSelected");
+shouldBeFalse("new Option('somedata', 'somevalue', false).defaultSelected");
+shouldBeTrue("new Option('somedata', 'somevalue', true).defaultSelected");
+
+shouldBeFalse("new Option().selected");
+shouldBeFalse("new Option('somedata', 'somevalue').selected");
+shouldBeFalse("new Option('somedata', 'somevalue', false).selected");
+shouldBeFalse("new Option('somedata', 'somevalue', true).selected");
+shouldBeFalse("new Option('somedata', 'somevalue', true, false).selected");
+shouldBeTrue("new Option('somedata', 'somevalue', true, true).selected");
+
+shouldBeEqualToString("new Option().outerHTML","<option></option>");
+shouldBeEqualToString("new Option('somedata', 'somevalue', false).outerHTML.replace(/\"/g,\"'\")", "<option value='somevalue'>somedata</option>");
+shouldBeEqualToString("new Option('somedata', 'somevalue', true).outerHTML.replace(/\"/g,\"'\")", "<option value='somevalue' selected=''>somedata</option>");
+
+// Audio tests
+shouldBeNonNull("new Audio()");
+shouldBeEqualToString("new Audio().tagName", "AUDIO");
+
+shouldBeEqualToString("new Audio().src", "");
+shouldBeTrue("new Audio().autobuffer");
+shouldBeEqualToString("new Audio('http://localhost/someurl').src", "http://localhost/someurl");
+shouldBeTrue("new Audio('http://localhost/someurl').autobuffer");
+
+var successfullyParsed = true;
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index c6b99bd..c5714e2 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,47 @@
+2010-02-18  Yaar Schnitman  <yaar at chromium.org>
+
+        Reviewed by Darin Adler.
+
+        Normalize custom ctors for Image, Option, Audio
+        https://bugs.webkit.org/show_bug.cgi?id=34782
+
+        Test: fast/js/custom-constructors.html
+
+        * bindings/js/JSAudioConstructor.cpp:
+        (WebCore::JSAudioConstructor::JSAudioConstructor):
+        (WebCore::constructAudio):
+        * bindings/js/JSImageConstructor.cpp:
+        (WebCore::constructImage):
+        * bindings/js/JSOptionConstructor.cpp:
+        (WebCore::constructHTMLOptionElement):
+        * bindings/v8/custom/V8HTMLAudioElementConstructor.cpp:
+        (WebCore::v8HTMLAudioElementConstructorCallback):
+        * bindings/v8/custom/V8HTMLImageElementConstructor.cpp:
+        (WebCore::v8HTMLImageElementConstructorCallback):
+        * bindings/v8/custom/V8HTMLOptionElementConstructor.cpp:
+        (WebCore::v8HTMLOptionElementConstructorCallback):
+        * html/HTMLAudioElement.cpp:
+        (WebCore::HTMLAudioElement::HTMLAudioElement):
+        (WebCore::HTMLAudioElement::createForJSConstructor):
+        * html/HTMLAudioElement.h:
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::createForJSConstructor):
+        (WebCore::HTMLImageElement::mapToEntry):
+        (WebCore::HTMLImageElement::createRenderer):
+        (WebCore::HTMLImageElement::attach):
+        (WebCore::HTMLImageElement::width):
+        (WebCore::HTMLImageElement::height):
+        (WebCore::HTMLImageElement::naturalHeight):
+        * html/HTMLImageElement.h:
+        * html/HTMLOptionElement.cpp:
+        (WebCore::HTMLOptionElement::HTMLOptionElement):
+        (WebCore::HTMLOptionElement::createForJSConstructor):
+        (WebCore::HTMLOptionElement::ownerSelectElement):
+        (WebCore::HTMLOptionElement::nonRendererRenderStyle):
+        (WebCore::HTMLOptionElement::disabled):
+        (WebCore::HTMLOptionElement::insertedIntoTree):
+        * html/HTMLOptionElement.h:
+
 2010-02-12  Brett Wilson  <brettw at chromium.org>
 
         Reviewed by Adam Barth.
diff --git a/WebCore/bindings/js/JSAudioConstructor.cpp b/WebCore/bindings/js/JSAudioConstructor.cpp
index 174cc11..77bb120 100644
--- a/WebCore/bindings/js/JSAudioConstructor.cpp
+++ b/WebCore/bindings/js/JSAudioConstructor.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
@@ -30,10 +30,7 @@
 #include "JSAudioConstructor.h"
 
 #include "HTMLAudioElement.h"
-#include "HTMLNames.h"
 #include "JSHTMLAudioElement.h"
-#include "ScriptExecutionContext.h"
-#include "Text.h"
 #include <runtime/Error.h>
 
 using namespace JSC;
@@ -46,24 +43,30 @@ JSAudioConstructor::JSAudioConstructor(ExecState* exec, JSDOMGlobalObject* globa
     : DOMConstructorWithDocument(JSAudioConstructor::createStructure(globalObject->objectPrototype()), globalObject)
 {
     putDirect(exec->propertyNames().prototype, JSHTMLAudioElementPrototype::self(exec, globalObject), None);
-    putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly|DontDelete|DontEnum);
+    putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontDelete | DontEnum);
 }
 
 static JSObject* constructAudio(ExecState* exec, JSObject* constructor, const ArgList& args)
 {
-    JSAudioConstructor* jsAudio = static_cast<JSAudioConstructor*>(constructor);
-    // FIXME: Why doesn't this need the call toJS on the document like JSImageConstructor?
-    Document* document = jsAudio->document();
+    JSAudioConstructor* jsConstructor = static_cast<JSAudioConstructor*>(constructor);
+
+    Document* document = jsConstructor->document();
     if (!document)
         return throwError(exec, ReferenceError, "Audio constructor associated document is unavailable");
 
-    RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(HTMLNames::audioTag, document);
-    audio->setAutobuffer(true);
-    if (args.size() > 0) {
-        audio->setSrc(args.at(0).toString(exec));
-        audio->scheduleLoad();
-    }
-    return asObject(toJS(exec, jsAudio->globalObject(), audio.release()));
+    // Calling toJS on the document causes the JS document wrapper to be
+    // added to the window object. This is done to ensure that JSDocument::markChildren
+    // will be called, which will cause the audio element to be marked if necessary.
+    toJS(exec, jsConstructor->globalObject(), document);
+
+    // FIXME: This converts an undefined argument to the string "undefined", but possibly we
+    // should treat it as if no argument was passed instead, by checking the value of args.at
+    // rather than looking at args.size.
+    String src;
+    if (args.size() > 0)
+        src = args.at(0).toString(exec);
+    return asObject(toJS(exec, jsConstructor->globalObject(),
+        HTMLAudioElement::createForJSConstructor(document, src)));
 }
 
 ConstructType JSAudioConstructor::getConstructData(ConstructData& constructData)
diff --git a/WebCore/bindings/js/JSImageConstructor.cpp b/WebCore/bindings/js/JSImageConstructor.cpp
index 0f4a991..a574326 100644
--- a/WebCore/bindings/js/JSImageConstructor.cpp
+++ b/WebCore/bindings/js/JSImageConstructor.cpp
@@ -1,6 +1,6 @@
 /*
  *  Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
- *  Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ *  Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -24,7 +24,6 @@
 #include "HTMLNames.h"
 #include "JSHTMLImageElement.h"
 #include "JSNode.h"
-#include "ScriptExecutionContext.h"
 #include <runtime/Error.h>
 
 using namespace JSC;
@@ -43,35 +42,30 @@ JSImageConstructor::JSImageConstructor(ExecState* exec, JSDOMGlobalObject* globa
 
 static JSObject* constructImage(ExecState* exec, JSObject* constructor, const ArgList& args)
 {
-    bool widthSet = false;
-    bool heightSet = false;
-    int width = 0;
-    int height = 0;
-    if (args.size() > 0) {
-        widthSet = true;
-        width = args.at(0).toInt32(exec);
-    }
-    if (args.size() > 1) {
-        heightSet = true;
-        height = args.at(1).toInt32(exec);
-    }
-
     JSImageConstructor* jsConstructor = static_cast<JSImageConstructor*>(constructor);
     Document* document = jsConstructor->document();
     if (!document)
         return throwError(exec, ReferenceError, "Image constructor associated document is unavailable");
 
     // Calling toJS on the document causes the JS document wrapper to be
-    // added to the window object. This is done to ensure that JSDocument::mark
-    // will be called (which will cause the image element to be marked if necessary).
+    // added to the window object. This is done to ensure that JSDocument::markChildren
+    // will be called, which will cause the image element to be marked if necessary.
     toJS(exec, jsConstructor->globalObject(), document);
+    int width;
+    int height;
+    int* optionalWidth = 0;
+    int* optionalHeight = 0;
+    if (args.size() > 0) {
+        width = args.at(0).toInt32(exec);
+        optionalWidth = &width;
+    }
+    if (args.size() > 1) {
+        height = args.at(1).toInt32(exec);
+        optionalHeight = &height;
+    }
 
-    RefPtr<HTMLImageElement> image = new HTMLImageElement(HTMLNames::imgTag, document);
-    if (widthSet)
-        image->setWidth(width);
-    if (heightSet)
-        image->setHeight(height);
-    return asObject(toJS(exec, jsConstructor->globalObject(), image.release()));
+    return asObject(toJS(exec, jsConstructor->globalObject(),
+        HTMLImageElement::createForJSConstructor(document, optionalWidth, optionalHeight)));
 }
 
 ConstructType JSImageConstructor::getConstructData(ConstructData& constructData)
diff --git a/WebCore/bindings/js/JSOptionConstructor.cpp b/WebCore/bindings/js/JSOptionConstructor.cpp
index 7da0666..995903e 100644
--- a/WebCore/bindings/js/JSOptionConstructor.cpp
+++ b/WebCore/bindings/js/JSOptionConstructor.cpp
@@ -49,21 +49,18 @@ static JSObject* constructHTMLOptionElement(ExecState* exec, JSObject* construct
     if (!document)
         return throwError(exec, ReferenceError, "Option constructor associated document is unavailable");
 
-    RefPtr<HTMLOptionElement> element = static_pointer_cast<HTMLOptionElement>(document->createElement(HTMLNames::optionTag, false));
-
-    ExceptionCode ec = 0;
-    RefPtr<Text> text = document->createTextNode("");
+    String data;
     if (!args.at(0).isUndefined())
-        text->setData(args.at(0).toString(exec), ec);
-    if (ec == 0)
-        element->appendChild(text.release(), ec);
-    if (ec == 0 && !args.at(1).isUndefined())
-        element->setValue(args.at(1).toString(exec));
-    if (ec == 0)
-        element->setDefaultSelected(args.at(2).toBoolean(exec));
-    if (ec == 0)
-        element->setSelected(args.at(3).toBoolean(exec));
+        data = args.at(0).toString(exec);
 
+    String value;
+    if (!args.at(1).isUndefined())
+        value = args.at(1).toString(exec);
+    bool defaultSelected = args.at(2).toBoolean(exec);
+    bool selected = args.at(3).toBoolean(exec);
+
+    ExceptionCode ec = 0;
+    RefPtr<HTMLOptionElement> element = HTMLOptionElement::createForJSConstructor(document, data, value, defaultSelected, selected, ec);
     if (ec) {
         setDOMException(exec, ec);
         return 0;
diff --git a/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp b/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp
index 06c6c1d..9b75db8 100644
--- a/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp
+++ b/WebCore/bindings/v8/custom/V8HTMLAudioElementConstructor.cpp
@@ -14,7 +14,7 @@
  *     * Neither the name of Google Inc. nor the names of its
  * contributors may be used to endorse or promote products derived from
  * this software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -60,15 +60,14 @@ static v8::Handle<v8::Value> v8HTMLAudioElementConstructorCallback(const v8::Arg
         return throwError("Audio constructor associated document is unavailable", V8Proxy::ReferenceError);
 
     // Make sure the document is added to the DOM Node map. Otherwise, the HTMLAudioElement instance
-    // may end up being the only node in the map and get garbage-ccollected prematurely.
+    // may end up being the only node in the map and get garbage-collected prematurely.
     toV8(document);
 
-    RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(HTMLNames::audioTag, document);
-    audio->setAutobuffer(true);
-    if (args.Length() > 0) {
-        audio->setSrc(toWebCoreString(args[0]));
-        audio->scheduleLoad();
-    }
+
+    String src;
+    if (args.Length() > 0)
+        src = toWebCoreString(args[0]);
+    RefPtr<HTMLAudioElement> audio = HTMLAudioElement::createForJSConstructor(document, src);
 
     V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::AUDIO), audio.get());
     audio->ref();
diff --git a/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp b/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp
index 1873188..29b4813 100644
--- a/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp
+++ b/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Google Inc. All rights reserved.
+ * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -14,7 +14,7 @@
  *     * Neither the name of Google Inc. nor the names of its
  * contributors may be used to endorse or promote products derived from
  * this software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -61,15 +61,25 @@ static v8::Handle<v8::Value> v8HTMLImageElementConstructorCallback(const v8::Arg
 
     // Make sure the document is added to the DOM Node map. Otherwise, the HTMLImageElement instance
     // may end up being the only node in the map and get garbage-ccollected prematurely.
+    // FIXME: The correct way to do this would be to make HTMLImageElement derive from
+    // ActiveDOMObject and use its interface to keep its wrapper alive. Then we would
+    // remove this code and the special case in isObservableThroughDOM.
     toV8(document);
 
-    RefPtr<HTMLImageElement> image = new HTMLImageElement(HTMLNames::imgTag, document);
+    int width;
+    int height;
+    int* optionalWidth = 0;
+    int* optionalHeight = 0;
     if (args.Length() > 0) {
-        image->setWidth(toInt32(args[0]));
-        if (args.Length() > 1)
-            image->setHeight(toInt32(args[1]));
+        width = toInt32(args[0]);
+        optionalWidth = &width;
+    }
+    if (args.Length() > 1) {
+        height = toInt32(args[1]);
+        optionalHeight = &height;
     }
 
+    RefPtr<HTMLImageElement> image = HTMLImageElement::createForJSConstructor(document, optionalWidth, optionalHeight);
     V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::IMAGE), image.get());
     image->ref();
     V8DOMWrapper::setJSWrapperForDOMNode(image.get(), v8::Persistent<v8::Object>::New(args.Holder()));
diff --git a/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp b/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp
index 3113eb5..1ff1d2e 100644
--- a/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp
+++ b/WebCore/bindings/v8/custom/V8HTMLOptionElementConstructor.cpp
@@ -14,7 +14,7 @@
  *     * Neither the name of Google Inc. nor the names of its
  * contributors may be used to endorse or promote products derived from
  * this software without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -59,32 +59,24 @@ static v8::Handle<v8::Value> v8HTMLOptionElementConstructorCallback(const v8::Ar
     if (!document)
         return throwError("Option constructor associated document is unavailable", V8Proxy::ReferenceError);
 
-    RefPtr<HTMLOptionElement> option = new HTMLOptionElement(HTMLNames::optionTag, document);
+    String data;
+    String value;
+    bool defaultSelected = false;
+    bool selected = false;
+    if (args.Length() > 0 && !args[0]->IsUndefined())
+        data = toWebCoreString(args[0]);
+    if (args.Length() > 1 && !args[1]->IsUndefined())
+        value = toWebCoreString(args[1]);
+    if (args.Length() > 2)
+        defaultSelected = args[2]->BooleanValue();
+    if (args.Length() > 3)
+        selected = args[3]->BooleanValue();
 
     ExceptionCode ec = 0;
-    RefPtr<Text> text = document->createTextNode("");
-    if (args.Length() > 0) {
-        if (!args[0]->IsUndefined()) {
-            text->setData(toWebCoreString(args[0]), ec);
-            if (ec)
-                throwError(ec);
-        }
-
-        option->appendChild(text.release(), ec);
-        if (ec)
-            throwError(ec);
-
-        if (args.Length() > 1) {
-            if (!args[1]->IsUndefined())
-                option->setValue(toWebCoreString(args[1]));
-
-            if (args.Length() > 2) {
-                option->setDefaultSelected(args[2]->BooleanValue());
-                if (args.Length() > 3)
-                    option->setSelected(args[3]->BooleanValue());
-            }
-        }
-    }
+    RefPtr<HTMLOptionElement> option = HTMLOptionElement::createForJSConstructor(document, data, value, defaultSelected, selected, ec);
+
+    if (ec)
+        throwError(ec);
 
     V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::OPTION), option.get());
     option->ref();
diff --git a/WebCore/html/HTMLAudioElement.cpp b/WebCore/html/HTMLAudioElement.cpp
index 6adf9ea..347b8c4 100644
--- a/WebCore/html/HTMLAudioElement.cpp
+++ b/WebCore/html/HTMLAudioElement.cpp
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -20,7 +21,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
@@ -34,11 +35,22 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-HTMLAudioElement::HTMLAudioElement(const QualifiedName& tagName, Document* doc)
-    : HTMLMediaElement(tagName, doc)
+HTMLAudioElement::HTMLAudioElement(const QualifiedName& tagName, Document* document)
+    : HTMLMediaElement(tagName, document)
 {
     ASSERT(hasTagName(audioTag));
 }
 
+PassRefPtr<HTMLAudioElement> HTMLAudioElement::createForJSConstructor(Document* document, const String& src)
+{
+    RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(audioTag, document);
+    audio->setAutobuffer(true);
+    if (!src.isNull()) {
+        audio->setSrc(src);
+        audio->scheduleLoad();
+    }
+    return audio.release();
+}
+
 }
 #endif
diff --git a/WebCore/html/HTMLAudioElement.h b/WebCore/html/HTMLAudioElement.h
index 0c9777d..2f06f1a 100644
--- a/WebCore/html/HTMLAudioElement.h
+++ b/WebCore/html/HTMLAudioElement.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2007, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -20,7 +21,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef HTMLAudioElement_h
@@ -28,14 +29,15 @@
 
 #if ENABLE(VIDEO)
 
+#include "Document.h"
 #include "HTMLMediaElement.h"
 
 namespace WebCore {
 
 class HTMLAudioElement : public HTMLMediaElement {
 public:
+    static PassRefPtr<HTMLAudioElement> createForJSConstructor(Document*, const String& src);
     HTMLAudioElement(const QualifiedName&, Document*);
-
 private:
     virtual bool isVideo() const { return false; }
     virtual int tagPriority() const { return 5; }
diff --git a/WebCore/html/HTMLImageElement.cpp b/WebCore/html/HTMLImageElement.cpp
index 4592461..d3cea92 100644
--- a/WebCore/html/HTMLImageElement.cpp
+++ b/WebCore/html/HTMLImageElement.cpp
@@ -1,7 +1,8 @@
 /*
  * Copyright (C) 1999 Lars Knoll (knoll at kde.org)
  *           (C) 1999 Antti Koivisto (koivisto at kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -58,6 +59,16 @@ HTMLImageElement::~HTMLImageElement()
         m_form->removeImgElement(this);
 }
 
+PassRefPtr<HTMLImageElement> HTMLImageElement::createForJSConstructor(Document* document, const int* optionalWidth, const int* optionalHeight)
+{
+    RefPtr<HTMLImageElement> image = new HTMLImageElement(imgTag, document);
+    if (optionalWidth)
+        image->setWidth(*optionalWidth);
+    if (optionalHeight > 0)
+        image->setHeight(*optionalHeight);
+    return image.release();
+}
+
 bool HTMLImageElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
 {
     if (attrName == widthAttr ||
@@ -68,7 +79,7 @@ bool HTMLImageElement::mapToEntry(const QualifiedName& attrName, MappedAttribute
         result = eUniversal;
         return false;
     }
-    
+
     if (attrName == borderAttr || attrName == alignAttr) {
         result = eReplaced; // Shared with embed and iframe elements.
         return false;
@@ -161,7 +172,7 @@ RenderObject* HTMLImageElement::createRenderer(RenderArena* arena, RenderStyle*
 {
      if (style->contentData())
         return RenderObject::createObject(this, style);
-     
+
      return new (arena) RenderImage(this);
 }
 
@@ -174,7 +185,7 @@ void HTMLImageElement::attach()
         if (imageObj->hasImage())
             return;
         imageObj->setCachedImage(m_imageLoader.image());
-        
+
         // If we have no image at all because we have no src attribute, set
         // image height and width for the alt text instead.
         if (!m_imageLoader.image() && !imageObj->cachedImage())
@@ -241,7 +252,7 @@ int HTMLImageElement::width(bool ignorePendingStylesheets) const
         int width = getAttribute(widthAttr).toInt(&ok);
         if (ok)
             return width;
-        
+
         // if the image is available, use its width
         if (m_imageLoader.image()) {
             float zoomFactor = document()->frame() ? document()->frame()->pageZoomFactor() : 1.0f;
@@ -265,7 +276,7 @@ int HTMLImageElement::height(bool ignorePendingStylesheets) const
         int height = getAttribute(heightAttr).toInt(&ok);
         if (ok)
             return height;
-        
+
         // if the image is available, use its height
         if (m_imageLoader.image()) {
             float zoomFactor = document()->frame() ? document()->frame()->pageZoomFactor() : 1.0f;
@@ -293,10 +304,10 @@ int HTMLImageElement::naturalHeight() const
 {
     if (!m_imageLoader.image())
         return 0;
-    
+
     return m_imageLoader.image()->imageSize(1.0f).height();
 }
-    
+
 bool HTMLImageElement::isURLAttribute(Attribute* attr) const
 {
     return attr->name() == srcAttr
diff --git a/WebCore/html/HTMLImageElement.h b/WebCore/html/HTMLImageElement.h
index 14e5fa3..d7df1dc 100644
--- a/WebCore/html/HTMLImageElement.h
+++ b/WebCore/html/HTMLImageElement.h
@@ -1,7 +1,8 @@
 /*
  * Copyright (C) 1999 Lars Knoll (knoll at kde.org)
  *           (C) 1999 Antti Koivisto (koivisto at kde.org)
- * Copyright (C) 2004, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2008, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -34,6 +35,8 @@ class HTMLFormElement;
 class HTMLImageElement : public HTMLElement {
     friend class HTMLFormElement;
 public:
+    static PassRefPtr<HTMLImageElement> createForJSConstructor(Document*, const int* optionalWidth, const int* optionalHeight);
+
     HTMLImageElement(const QualifiedName&, Document*, HTMLFormElement* = 0);
     ~HTMLImageElement();
 
@@ -53,7 +56,7 @@ public:
 
     int naturalWidth() const;
     int naturalHeight() const;
-    
+
     bool isServerMap() const { return ismap && usemap.isEmpty(); }
 
     String altText() const;
diff --git a/WebCore/html/HTMLOptionElement.cpp b/WebCore/html/HTMLOptionElement.cpp
index 8598e87..b33f628 100644
--- a/WebCore/html/HTMLOptionElement.cpp
+++ b/WebCore/html/HTMLOptionElement.cpp
@@ -2,8 +2,9 @@
  * Copyright (C) 1999 Lars Knoll (knoll at kde.org)
  *           (C) 1999 Antti Koivisto (koivisto at kde.org)
  *           (C) 2001 Dirk Mueller (mueller at kde.org)
- * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
  *           (C) 2006 Alexey Proskuryakov (ap at nypop.com)
+ * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -41,13 +42,33 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-HTMLOptionElement::HTMLOptionElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f)
-    : HTMLFormControlElement(tagName, doc, f)
+HTMLOptionElement::HTMLOptionElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
+    : HTMLFormControlElement(tagName, document, form)
     , m_style(0)
 {
     ASSERT(hasTagName(optionTag));
 }
 
+PassRefPtr<HTMLOptionElement> HTMLOptionElement::createForJSConstructor(Document* document, const String& data, const String& value,
+        bool defaultSelected, bool selected, ExceptionCode& ec)
+{
+    RefPtr<HTMLOptionElement> element = new HTMLOptionElement(optionTag, document);
+
+    RefPtr<Text> text = Text::create(document, data.isNull() ? "" : data);
+
+    ec = 0;
+    element->appendChild(text.release(), ec);
+    if (ec)
+        return 0;
+
+    if (!value.isNull())
+        element->setValue(value);
+    element->setDefaultSelected(defaultSelected);
+    element->setSelected(selected);
+
+    return element.release();
+}
+
 bool HTMLOptionElement::checkDTD(const Node* newChild)
 {
     return newChild->isTextNode() || newChild->hasTagName(scriptTag);
@@ -174,7 +195,7 @@ HTMLSelectElement* HTMLOptionElement::ownerSelectElement() const
 
     if (!select)
         return 0;
-    
+
     return static_cast<HTMLSelectElement*>(select);
 }
 
@@ -203,9 +224,9 @@ void HTMLOptionElement::setRenderStyle(PassRefPtr<RenderStyle> newStyle)
     m_style = newStyle;
 }
 
-RenderStyle* HTMLOptionElement::nonRendererRenderStyle() const 
-{ 
-    return m_style.get(); 
+RenderStyle* HTMLOptionElement::nonRendererRenderStyle() const
+{
+    return m_style.get();
 }
 
 String HTMLOptionElement::textIndentedToRespectGroupLabel() const
@@ -214,8 +235,8 @@ String HTMLOptionElement::textIndentedToRespectGroupLabel() const
 }
 
 bool HTMLOptionElement::disabled() const
-{ 
-    return ownElementDisabled() || (parentNode() && static_cast<HTMLFormControlElement*>(parentNode())->disabled()); 
+{
+    return ownElementDisabled() || (parentNode() && static_cast<HTMLFormControlElement*>(parentNode())->disabled());
 }
 
 void HTMLOptionElement::insertedIntoTree(bool deep)
@@ -227,7 +248,7 @@ void HTMLOptionElement::insertedIntoTree(bool deep)
             select->setSelectedIndex(index(), false);
         select->scrollToSelection();
     }
-    
+
     HTMLFormControlElement::insertedIntoTree(deep);
 }
 
diff --git a/WebCore/html/HTMLOptionElement.h b/WebCore/html/HTMLOptionElement.h
index 7be9e9a..4255f25 100644
--- a/WebCore/html/HTMLOptionElement.h
+++ b/WebCore/html/HTMLOptionElement.h
@@ -3,6 +3,7 @@
  *           (C) 1999 Antti Koivisto (koivisto at kde.org)
  *           (C) 2000 Dirk Mueller (mueller at kde.org)
  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -39,6 +40,9 @@ class HTMLOptionElement : public HTMLFormControlElement, public OptionElement {
 public:
     HTMLOptionElement(const QualifiedName&, Document*, HTMLFormElement* = 0);
 
+    static PassRefPtr<HTMLOptionElement> createForJSConstructor(Document*, const String& data, const String& value,
+       bool defaultSelected, bool selected, ExceptionCode&);
+
     virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; }
     virtual int tagPriority() const { return 2; }
     virtual bool checkDTD(const Node* newChild);
@@ -48,7 +52,7 @@ public:
     virtual void attach();
     virtual void detach();
     virtual void setRenderStyle(PassRefPtr<RenderStyle>);
-    
+
     virtual const AtomicString& formControlType() const;
 
     virtual String text() const;
@@ -78,10 +82,10 @@ public:
 
     bool ownElementDisabled() const { return HTMLFormControlElement::disabled(); }
     virtual bool disabled() const;
-    
+
     virtual void insertedIntoTree(bool);
     virtual void accessKeyAction(bool);
-    
+
 private:
     virtual RenderStyle* nonRendererRenderStyle() const;
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list