Changeset 184942 in webkit


Ignore:
Timestamp:
May 27, 2015, 10:47:11 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

Array.of should work with other constructors
https://bugs.webkit.org/show_bug.cgi?id=145365
Source/JavaScriptCore:

Per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.of
step 4

Patch by Jordan Harband <ljharb@gmail.com> on 2015-05-27
Reviewed by Yusuke Suzuki.

  • builtins/ArrayConstructor.js:

(of):

  • runtime/ArrayConstructor.cpp:

(JSC::arrayConstructorOf): Deleted.

LayoutTests:

Patch by Jordan Harband <ljharb@gmail.com> on 2015-05-27
Reviewed by Yusuke Suzuki.

  • js/array-of-expected.txt:
  • js/script-tests/array-of.js:

(Foo):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r184933 r184942  
     12015-05-27  Jordan Harband  <ljharb@gmail.com>
     2
     3        Array.of should work with other constructors
     4        https://bugs.webkit.org/show_bug.cgi?id=145365
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * js/array-of-expected.txt:
     9        * js/script-tests/array-of.js:
     10        (Foo):
     11
    1122015-05-27  Benjamin Poulain  <bpoulain@apple.com>
    213
  • trunk/LayoutTests/js/array-of-expected.txt

    r180441 r184942  
    44
    55
     6PASS Array.of.length is 0
     7PASS Array.of.name is 'of'
    68PASS Array.of(1) is [1]
    79PASS Array.of(1, 2) is [1, 2]
     
    1618Check that a setter isn't called.
    1719PASS Array.of(1, 2, 3) did not throw exception.
     20PASS Array.of.call(Foo, 'a', 'b', 'c') instanceof Foo is true
     21PASS Array.of.call(Foo, 'a', 'b', 'c').givenLength is 3
     22PASS var foo = Array.of.call(Foo, 'a', 'b', 'c'); [foo.length, foo[0], foo[1], foo[2]] is [3, 'a', 'b', 'c']
    1823PASS successfullyParsed is true
    1924
  • trunk/LayoutTests/js/script-tests/array-of.js

    r180441 r184942  
    11description("Tests for Array.of");
     2
     3shouldBe("Array.of.length", "0");
     4shouldBe("Array.of.name", "'of'");
    25
    36shouldBe("Array.of(1)", "[1]");
     
    2326shouldNotThrow("Array.of(1, 2, 3)");
    2427
     28var Foo = function FooBar(length) { this.givenLength = length; };
     29shouldBeTrue("Array.of.call(Foo, 'a', 'b', 'c') instanceof Foo")
     30shouldBe("Array.of.call(Foo, 'a', 'b', 'c').givenLength", "3");
     31shouldBe("var foo = Array.of.call(Foo, 'a', 'b', 'c'); [foo.length, foo[0], foo[1], foo[2]]", "[3, 'a', 'b', 'c']");
  • trunk/Source/JavaScriptCore/ChangeLog

    r184933 r184942  
     12015-05-27  Jordan Harband  <ljharb@gmail.com>
     2
     3        Array.of should work with other constructors
     4        https://bugs.webkit.org/show_bug.cgi?id=145365
     5        Per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.of
     6        step 4
     7
     8        Reviewed by Yusuke Suzuki.
     9
     10        * builtins/ArrayConstructor.js:
     11        (of):
     12        * runtime/ArrayConstructor.cpp:
     13        (JSC::arrayConstructorOf): Deleted.
     14
    1152015-05-27  Benjamin Poulain  <bpoulain@apple.com>
    216
  • trunk/Source/JavaScriptCore/builtins/ArrayConstructor.js

    r184582 r184942  
    2323 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
     25
     26function of(/* items... */)
     27{
     28    "use strict";
     29
     30    var length = arguments.length;
     31    // TODO: Need isConstructor(this) instead of typeof "function" check.
     32    var array = typeof this === 'function' ? new this(length) : new @Array(length);
     33    for (var k = 0; k < length; ++k)
     34        @putByValDirect(array, k, arguments[k]);
     35    array.length = length;
     36    return array;
     37}
    2538
    2639function from(items /*, mapFn, thisArg */) {
  • trunk/Source/JavaScriptCore/runtime/ArrayConstructor.cpp

    r180370 r184942  
    3838
    3939static EncodedJSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState*);
    40 static EncodedJSValue JSC_HOST_CALL arrayConstructorOf(ExecState*);
    4140
    4241}
     
    130129}
    131130
    132 EncodedJSValue JSC_HOST_CALL arrayConstructorOf(ExecState* exec)
    133 {
    134     ArgList args(exec);
    135     size_t length = args.size();
    136 
    137     JSArray* result = constructEmptyArray(exec, nullptr, length);
    138 
    139     for (unsigned i = 0; i < length; i++)
    140         result->putDirectIndex(exec, i, args.at(i));
    141 
    142     return JSValue::encode(result);
    143 }
    144 
    145131} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.