Changeset 202334 in webkit


Ignore:
Timestamp:
Jun 22, 2016 10:50:15 AM (8 years ago)
Author:
Chris Dumez
Message:

JSDOMIterator forEach should support second optional parameter
https://bugs.webkit.org/show_bug.cgi?id=159020

Patch by Youenn Fablet <youennf@gmail.com> on 2016-06-22
Reviewed by Chris Dumez.

Source/WebCore:

Covered by beefed up test.

  • bindings/js/JSDOMIterator.h:

(WebCore::iteratorForEach): Setting callback thisValue to the second argument passed to forEach.

LayoutTests:

  • fast/dom/nodeListIterator-expected.txt:
  • fast/dom/nodeListIterator.html: Adding 'thisValue' various checks.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r202326 r202334  
     12016-06-22  Youenn Fablet  <youennf@gmail.com>
     2
     3        JSDOMIterator forEach should support second optional parameter
     4        https://bugs.webkit.org/show_bug.cgi?id=159020
     5
     6        Reviewed by Chris Dumez.
     7
     8        * fast/dom/nodeListIterator-expected.txt:
     9        * fast/dom/nodeListIterator.html: Adding 'thisValue' various checks.
     10
    1112016-06-22  Per Arne Vollan  <pvollan@apple.com>
    212
  • trunk/LayoutTests/fast/dom/nodeListIterator-expected.txt

    r202307 r202334  
    1212PASS forEachIndex is index
    1313PASS node is children[index++]
     14PASS thisValue is window
    1415PASS forEachContainer is nodeList
    1516PASS forEachIndex is index
    1617PASS node is children[index++]
     18PASS thisValue is window
     19PASS thisValue is window
     20PASS thisValue is window
     21PASS thisValue is givenThisValue
     22PASS thisValue is givenThisValue
    1723PASS iterator.next().value is children[0]
    1824PASS iterator.next().value is children[1]
  • trunk/LayoutTests/fast/dom/nodeListIterator.html

    r202307 r202334  
    4040            var forEachIndex;
    4141            var forEachContainer;
     42            var thisValue;
    4243            nodeList.forEach(function(n, i, c) {
    4344                node = n;
    4445                forEachIndex = i;
    4546                forEachContainer = c;
     47                thisValue = this;
    4648                shouldBe('forEachContainer', 'nodeList');
    4749                shouldBe('forEachIndex', 'index');
    4850                shouldBe('node', 'children[index++]');
     51                shouldBe('thisValue', 'window');
    4952            });
    50                                                                    
     53
     54            nodeList.forEach(function() {
     55                thisValue = this;
     56                shouldBe('thisValue', 'window');
     57            }, undefined);
     58
     59            var givenThisValue = nodeList;
     60            nodeList.forEach(function() {
     61                thisValue = this;
     62                shouldBe('thisValue', 'givenThisValue');
     63            }, givenThisValue);
     64
    5165            var iterator = nodeList.keys();
    5266            shouldBe('iterator.next().value', 'children[0]');
  • trunk/Source/WebCore/ChangeLog

    r202333 r202334  
     12016-06-22  Youenn Fablet  <youennf@gmail.com>
     2
     3        JSDOMIterator forEach should support second optional parameter
     4        https://bugs.webkit.org/show_bug.cgi?id=159020
     5
     6        Reviewed by Chris Dumez.
     7
     8        Covered by beefed up test.
     9
     10        * bindings/js/JSDOMIterator.h:
     11        (WebCore::iteratorForEach): Setting callback thisValue to the second argument passed to forEach.
     12
    1132016-06-22  Jer Noble  <jer.noble@apple.com>
    214
  • trunk/Source/WebCore/bindings/js/JSDOMIterator.h

    r202307 r202334  
    183183        return throwThisTypeError(state, JSWrapper::info()->className, propertyName);
    184184
     185    JSC::JSValue callback = state.argument(0);
     186    JSC::JSValue thisValue = state.argument(1);
     187
    185188    JSC::CallData callData;
    186     JSC::CallType callType = JSC::getCallData(state.argument(0), callData);
     189    JSC::CallType callType = JSC::getCallData(callback, callData);
    187190    if (callType == JSC::CallType::None)
    188191        return throwVMTypeError(&state);
     
    194197        appendForEachArguments(state, wrapper->globalObject(), arguments, value, index);
    195198        arguments.append(wrapper);
    196         JSC::call(&state, state.argument(0), callType, callData, wrapper, arguments);
     199        JSC::call(&state, callback, callType, callData, thisValue, arguments);
    197200        if (state.hadException())
    198201            break;
    199     } 
     202    }
    200203    return JSC::JSValue::encode(JSC::jsUndefined());
    201204}
Note: See TracChangeset for help on using the changeset viewer.