Range should be constructable.

https://bugs.webkit.org/show_bug.cgi?id=115639

Patch by László Langó <llango.u-szeged@partner.samsung.com> on 2014-01-23
Reviewed by Ryosuke Niwa.

Source/WebCore:

http://www.w3.org/TR/2013/WD-dom-20131107/#interface-range
Now we can do `new Range()` instead of `document.createRange()`.

Backported from Blink: https://chromium.googlesource.com/chromium/blink/+/47ca40efdf58a4787aa33aa75a35778899b1c002%5E%21

Test: fast/dom/Range/range-constructor.html

* dom/Range.cpp:
(WebCore::Range::create):
* dom/Range.h:
* dom/Range.idl:

LayoutTests:

* fast/dom/Range/range-constructor-expected.txt: Added.
* fast/dom/Range/range-constructor.html: Added.
* fast/dom/dom-constructors-expected.txt:
* fast/dom/dom-constructors.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@162601 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ac433e32
2014-01-23 László Langó <llango.u-szeged@partner.samsung.com>
Range should be constructable.
https://bugs.webkit.org/show_bug.cgi?id=115639
Reviewed by Ryosuke Niwa.
* fast/dom/Range/range-constructor-expected.txt: Added.
* fast/dom/Range/range-constructor.html: Added.
* fast/dom/dom-constructors-expected.txt:
* fast/dom/dom-constructors.html:
2014-01-22 Jinwoo Song <jinwoo7.song@samsung.com>
Unreviewed EFL gardening after r162553.
Tests that we can create instances of Range using new
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS typeof new Range is "object"
PASS Object.prototype.toString.call(new Range) is "[object Range]"
PASS new Range instanceof Range is true
PASS Object.getPrototypeOf(new Range) is Range.prototype
PASS r.toString() is "Test"
PASS new innerWindow.Range instanceof innerWindow.Range is true
PASS Object.getPrototypeOf(new innerWindow.Range) is innerWindow.Range.prototype
PASS r.toString() is "Inner"
PASS successfullyParsed is true
TEST COMPLETE
Test
<!DOCTYPE html>
<script src="../../../resources/js-test-pre.js"></script>
<div id="test-div">Test</div>
<script>
description('Tests that we can create instances of Range using new');
shouldBe('typeof new Range', '"object"');
shouldBe('Object.prototype.toString.call(new Range)', '"[object Range]"');
shouldBeTrue('new Range instanceof Range');
shouldBe('Object.getPrototypeOf(new Range)', 'Range.prototype');
var r = new Range();
r.selectNodeContents(document.getElementById('test-div'));
shouldBe('r.toString()', '"Test"')
var frame = document.createElement('iframe');
document.body.appendChild(frame);
var innerWindow = frame.contentWindow;
var innerDocument = frame.contentDocument;
innerDocument.body.textContent = 'Inner';
shouldBeTrue('new innerWindow.Range instanceof innerWindow.Range');
shouldBe('Object.getPrototypeOf(new innerWindow.Range)', 'innerWindow.Range.prototype');
var r = new innerWindow.Range();
r.selectNodeContents(innerDocument.body);
shouldBe('r.toString()', '"Inner"');
</script>
<script src="../../../resources/js-test-post.js"></script>
......@@ -98,7 +98,6 @@ PASS TryAllocate('NodeFilter') is 'exception'
PASS TryAllocate('NodeList') is 'exception'
PASS TryAllocate('Plugin') is 'exception'
PASS TryAllocate('PluginArray') is 'exception'
PASS TryAllocate('Range') is 'exception'
PASS TryAllocate('Rect') is 'exception'
PASS TryAllocate('StyleSheet') is 'exception'
PASS TryAllocate('StyleSheetList') is 'exception'
......@@ -135,6 +134,9 @@ PASS TryAllocate('DOMParser') is '[object DOMParser]'
PASS TryAllocate('DocumentFragment') is '[object DocumentFragment]'
PASS TryAllocate('DocumentFragment') is '[object DocumentFragment]'
PASS TryAllocate('DocumentFragment') is '[object DocumentFragment]'
PASS TryAllocate('Range') is '[object Range]'
PASS TryAllocate('Range') is '[object Range]'
PASS TryAllocate('Range') is '[object Range]'
PASS TryAllocate('Text') is '[object Text]'
PASS TryAllocate('Text') is '[object Text]'
PASS TryAllocate('Text') is '[object Text]'
......
......@@ -108,7 +108,6 @@ var objects_exception = [
'NodeList',
'Plugin',
'PluginArray',
'Range',
'Rect',
'StyleSheet',
'StyleSheetList',
......@@ -137,6 +136,7 @@ var objects_constructor = [
'Comment',
'DOMParser',
'DocumentFragment',
'Range',
'Text',
'XMLHttpRequest',
'XMLSerializer',
......@@ -162,7 +162,7 @@ var objects_different_constructor = {
function TryAllocate(node) {
var Cons = this[node];
if (!Cons) return 'no constructor';
try { return new Cons() + ''; }
try { return Object.prototype.toString.call(new Cons()); }
catch (e) { return 'exception'; }
}
......
2014-01-23 László Langó <llango.u-szeged@partner.samsung.com>
Range should be constructable.
https://bugs.webkit.org/show_bug.cgi?id=115639
Reviewed by Ryosuke Niwa.
http://www.w3.org/TR/2013/WD-dom-20131107/#interface-range
Now we can do `new Range()` instead of `document.createRange()`.
Backported from Blink: https://chromium.googlesource.com/chromium/blink/+/47ca40efdf58a4787aa33aa75a35778899b1c002%5E%21
Test: fast/dom/Range/range-constructor.html
* dom/Range.cpp:
(WebCore::Range::create):
* dom/Range.h:
* dom/Range.idl:
2014-01-23 ChangSeok Oh <changseok.oh@collabora.com>
Unreviewed build fix for gles after r162565. Add missing definitions.
......@@ -104,6 +104,11 @@ PassRefPtr<Range> Range::create(Document& ownerDocument, const Position& start,
return adoptRef(new Range(ownerDocument, start.containerNode(), start.computeOffsetInContainerNode(), end.containerNode(), end.computeOffsetInContainerNode()));
}
PassRefPtr<Range> Range::create(ScriptExecutionContext& context)
{
return adoptRef(new Range(toDocument(context)));
}
#if PLATFORM(IOS)
PassRefPtr<Range> Range::create(Document& ownerDocument, const VisiblePosition& visibleStart, const VisiblePosition& visibleEnd)
{
......
......@@ -55,6 +55,7 @@ public:
static PassRefPtr<Range> create(Document&);
static PassRefPtr<Range> create(Document&, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
static PassRefPtr<Range> create(Document&, const Position&, const Position&);
static PassRefPtr<Range> create(ScriptExecutionContext&);
#if PLATFORM(IOS)
// FIXME: Consider making this a static non-member, non-friend function.
static PassRefPtr<Range> create(Document&, const VisiblePosition&, const VisiblePosition&);
......
......@@ -20,7 +20,9 @@
// Introduced in DOM Level 2:
[
ImplementationLacksVTable,
Constructor,
ConstructorCallWith=ScriptExecutionContext,
ImplementationLacksVTable
] interface Range {
[GetterRaisesException] readonly attribute Node startContainer;
......
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