Attachment #776500: patch v5 for bug #866847

View | Details | Raw Unified | Return to bug 866847
Collapse All | Expand All

(-)a/js/src/Makefile.in (+2 lines)
Line     Link Here 
 Lines 637-652   selfhosting_srcs := \ Link Here 
637
  $(srcdir)/builtin/Utilities.js \
637
  $(srcdir)/builtin/Utilities.js \
638
  $(srcdir)/builtin/Array.js \
638
  $(srcdir)/builtin/Array.js \
639
  $(srcdir)/builtin/Date.js \
639
  $(srcdir)/builtin/Date.js \
640
  $(srcdir)/builtin/Intl.js \
640
  $(srcdir)/builtin/Intl.js \
641
  $(srcdir)/builtin/IntlData.js \
641
  $(srcdir)/builtin/IntlData.js \
642
  $(srcdir)/builtin/Number.js \
642
  $(srcdir)/builtin/Number.js \
643
  $(srcdir)/builtin/ParallelArray.js \
643
  $(srcdir)/builtin/ParallelArray.js \
644
  $(srcdir)/builtin/String.js \
644
  $(srcdir)/builtin/String.js \
645
  $(srcdir)/builtin/Set.js \
646
  $(srcdir)/builtin/Map.js \
645
  $(NULL)
647
  $(NULL)
646
648
647
selfhosted_out_h_deps := \
649
selfhosted_out_h_deps := \
648
  $(selfhosting_srcs) \
650
  $(selfhosting_srcs) \
649
  $(srcdir)/js.msg \
651
  $(srcdir)/js.msg \
650
  $(srcdir)/builtin/embedjs.py \
652
  $(srcdir)/builtin/embedjs.py \
651
  $(NULL)
653
  $(NULL)
652
654
(-)a/js/src/builtin/Map.js (+36 lines)
Line     Link Here 
Line 0    Link Here 
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
/* ES6 20121122 draft 15.14.4.4. */
6
7
function MapForEach(callbackfn, thisArg = undefined) {
8
    /* Step 1-2. */
9
    var M = this;
10
    if (!IsObject(M))
11
        ThrowError(JSMSG_BAD_TYPE, typeof M);
12
13
    /* Step 3-4. */
14
    try {
15
        std_Map_has.call(M);
16
    } catch (e) {
17
        ThrowError(JSMSG_BAD_TYPE, typeof M);
18
    }
19
20
    /* Step 5. */
21
    if (!IsCallable(callbackfn))
22
        ThrowError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
23
24
    /* Step 6-8. */
25
    var entries = std_Map_iterator.call(M);
26
    while (true) {
27
        try {
28
            var entry = std_Map_iterator_next.call(entries);
29
        } catch (err) {
30
            if (err instanceof StopIteration)
31
                break;
32
            throw err;
33
        }
34
        callFunction(callbackfn, thisArg, entry[1], entry[0], M);
35
    }
36
}
(-)a/js/src/builtin/MapObject.cpp (+2 lines)
Line     Link Here 
 Lines 1027-1042   const JSPropertySpec MapObject::properti Link Here 
1027
const JSFunctionSpec MapObject::methods[] = {
1027
const JSFunctionSpec MapObject::methods[] = {
1028
    JS_FN("get", get, 1, 0),
1028
    JS_FN("get", get, 1, 0),
1029
    JS_FN("has", has, 1, 0),
1029
    JS_FN("has", has, 1, 0),
1030
    JS_FN("set", set, 2, 0),
1030
    JS_FN("set", set, 2, 0),
1031
    JS_FN("delete", delete_, 1, 0),
1031
    JS_FN("delete", delete_, 1, 0),
1032
    JS_FN("keys", keys, 0, 0),
1032
    JS_FN("keys", keys, 0, 0),
1033
    JS_FN("values", values, 0, 0),
1033
    JS_FN("values", values, 0, 0),
1034
    JS_FN("clear", clear, 0, 0),
1034
    JS_FN("clear", clear, 0, 0),
1035
    {"forEach", {NULL, NULL}, 1, 0, "MapForEach"},
1035
    JS_FS_END
1036
    JS_FS_END
1036
};
1037
};
1037
1038
1038
static JSObject *
1039
static JSObject *
1039
InitClass(JSContext *cx, Handle<GlobalObject*> global, Class *clasp, JSProtoKey key, Native construct,
1040
InitClass(JSContext *cx, Handle<GlobalObject*> global, Class *clasp, JSProtoKey key, Native construct,
1040
          const JSPropertySpec *properties, const JSFunctionSpec *methods)
1041
          const JSPropertySpec *properties, const JSFunctionSpec *methods)
1041
{
1042
{
1042
    Rooted<JSObject*> proto(cx, global->createBlankPrototype(cx, clasp));
1043
    Rooted<JSObject*> proto(cx, global->createBlankPrototype(cx, clasp));
 Lines 1583-1598   const JSPropertySpec SetObject::properti Link Here 
1583
};
1584
};
1584
1585
1585
const JSFunctionSpec SetObject::methods[] = {
1586
const JSFunctionSpec SetObject::methods[] = {
1586
    JS_FN("has", has, 1, 0),
1587
    JS_FN("has", has, 1, 0),
1587
    JS_FN("add", add, 1, 0),
1588
    JS_FN("add", add, 1, 0),
1588
    JS_FN("delete", delete_, 1, 0),
1589
    JS_FN("delete", delete_, 1, 0),
1589
    JS_FN("entries", entries, 0, 0),
1590
    JS_FN("entries", entries, 0, 0),
1590
    JS_FN("clear", clear, 0, 0),
1591
    JS_FN("clear", clear, 0, 0),
1592
    {"forEach", {NULL, NULL}, 1, 0, "SetForEach"},
1591
    JS_FS_END
1593
    JS_FS_END
1592
};
1594
};
1593
1595
1594
JSObject *
1596
JSObject *
1595
SetObject::initClass(JSContext *cx, JSObject *obj)
1597
SetObject::initClass(JSContext *cx, JSObject *obj)
1596
{
1598
{
1597
    Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
1599
    Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
1598
    RootedObject proto(cx,
1600
    RootedObject proto(cx,
(-)a/js/src/builtin/Set.js (+36 lines)
Line     Link Here 
Line 0    Link Here 
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
/* ES6 20121122 draft 15.16.4.6. */
6
7
function SetForEach(callbackfn, thisArg = undefined) {
8
    /* Step 1-2. */
9
    var S = this;
10
    if (!IsObject(S))
11
        ThrowError(JSMSG_BAD_TYPE, typeof S);
12
13
    /* Step 3-4. */
14
    try {
15
        std_Set_has.call(S);
16
    } catch (e) {
17
        ThrowError(JSMSG_BAD_TYPE, typeof S);
18
    }
19
20
    /* Step 5-6. */
21
    if (!IsCallable(callbackfn))
22
        ThrowError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
23
24
    /* Step 7-8. */
25
    var values = std_Set_iterator.call(S);
26
    while (true) {
27
        try {
28
            var entry = std_Set_iterator_next.call(values);
29
        } catch (err) {
30
            if (err instanceof StopIteration)
31
                break;
32
            throw err;
33
        }
34
        callFunction(callbackfn, thisArg, entry, entry, S);
35
    }
36
}
(-)a/js/src/builtin/Utilities.js (-1 / +6 lines)
Line     Link Here 
 Lines 68-84   var std_String_replace = String.prototyp Link Here 
68
var std_String_split = String.prototype.split;
68
var std_String_split = String.prototype.split;
69
var std_String_startsWith = String.prototype.startsWith;
69
var std_String_startsWith = String.prototype.startsWith;
70
var std_String_substring = String.prototype.substring;
70
var std_String_substring = String.prototype.substring;
71
var std_String_toLowerCase = String.prototype.toLowerCase;
71
var std_String_toLowerCase = String.prototype.toLowerCase;
72
var std_String_toUpperCase = String.prototype.toUpperCase;
72
var std_String_toUpperCase = String.prototype.toUpperCase;
73
var std_WeakMap_get = WeakMap.prototype.get;
73
var std_WeakMap_get = WeakMap.prototype.get;
74
var std_WeakMap_has = WeakMap.prototype.has;
74
var std_WeakMap_has = WeakMap.prototype.has;
75
var std_WeakMap_set = WeakMap.prototype.set;
75
var std_WeakMap_set = WeakMap.prototype.set;
76
76
var std_Map_has = Map.prototype.has;
77
var std_Set_has = Set.prototype.has;
78
var std_Map_iterator = Map().iterator;
79
var std_Set_iterator = Set().iterator;
80
var std_Map_iterator_next = Object.getPrototypeOf(Map().iterator()).next;
81
var std_Set_iterator_next = Object.getPrototypeOf(Set().iterator()).next;
77
82
78
/********** List specification type **********/
83
/********** List specification type **********/
79
84
80
85
81
/* Spec: ECMAScript Language Specification, 5.1 edition, 8.8 */
86
/* Spec: ECMAScript Language Specification, 5.1 edition, 8.8 */
82
function List() {}
87
function List() {}
83
{
88
{
84
  let ListProto = std_Object_create(null);
89
  let ListProto = std_Object_create(null);
(-)a/js/src/jit-test/tests/collections/Map-forEach.js (+58 lines)
Line     Link Here 
Line 0    Link Here 
1
/* test Map.prototype.forEach */
2
3
load(libdir + 'asserts.js');
4
5
// testing success conditions of Map.prototype.forEach
6
7
var testMap = new Map();
8
9
function callback(value, key, map) {
10
	testMap.set(key, value);
11
	assertEq(map.has(key), true);
12
	assertEq(map.get(key), value);
13
}
14
15
var initialMap = new Map([['a', 1], ['b', 2.3], [false, undefined]]);
16
initialMap.forEach(callback);
17
18
// test that both the Maps are equal and are in same order
19
var iterator = initialMap.iterator();
20
var count = 0;
21
for (var [k, v] of testMap) {
22
    assertEq(initialMap.has(k), true);
23
    assertEq(initialMap.get(k), testMap.get(k));
24
    assertEq(iterator.next()[1], testMap.get(k));
25
    count++;
26
}
27
28
//check both the Maps we have are equal in size
29
assertEq(initialMap.size, testMap.size);
30
assertEq(initialMap.size, count);
31
32
var x = { abc: 'test'};
33
function callback2(value, key, map) {
34
    assertEq(x, this);
35
}
36
initialMap = new Map([['a', 1]]);
37
initialMap.forEach(callback2, x);
38
39
// testing failure conditions of Map.prototype.forEach
40
41
var s = new Set([1, 2, 3]);
42
assertThrowsInstanceOf(function() {
43
    Map.prototype.forEach.call(s, callback);
44
}, TypeError, "Map.prototype.forEach should raise TypeError if not used on a Map");
45
46
var fn = 2;
47
assertThrowsInstanceOf(function() {
48
    initialMap.forEach(fn);
49
}, TypeError, "Map.prototype.forEach should raise TypeError if callback is not a function");
50
51
// testing that Map#forEach uses internal next() function and does not stop when
52
// StopIteration exception is thrown
53
54
var m = new Map([["one", 1]]);
55
Object.getPrototypeOf(m.iterator()).next = function () { throw "FAIL"; };
56
assertThrowsInstanceOf(function () {
57
  m.forEach(function () { throw StopIteration; });
58
}, StopIteration, "Map.prototype.forEach should use intrinsic next method.");
(-)a/js/src/jit-test/tests/collections/Set-forEach.js (+57 lines)
Line     Link Here 
Line 0    Link Here 
1
/* test Set.prototype.forEach */
2
3
load(libdir + 'asserts.js');
4
5
// testing success conditions of Set.prototype.forEach
6
7
var testSet = new Set();
8
9
function callback(value, key, set) {
10
    assertEq(value, key);
11
    testSet.add(value);
12
    assertEq(set.has(key), true);
13
}
14
15
var initialSet = new Set(['a', 1, undefined]);
16
initialSet.forEach(callback);
17
18
// test that both the Sets are equal and are in same order
19
var iterator = initialSet.iterator();
20
var count = 0;
21
for (var v of testSet) {
22
    assertEq(initialSet.has(v), true);
23
    assertEq(iterator.next(), v);
24
    count++;
25
}
26
27
//check both the Sets we have are equal in size
28
assertEq(initialSet.size, testSet.size);
29
assertEq(initialSet.size, count);
30
31
var x = { abc: 'test'};
32
function callback2(value, key, set) {
33
    assertEq(x, this);
34
}
35
initialSet = new Set(['a']);
36
initialSet.forEach(callback2, x);
37
38
// testing failure conditions of Set.prototype.forEach
39
40
var m = new Map([['a', 1], ['b', 2.3], ['c', undefined]]);
41
assertThrowsInstanceOf(function() {
42
    Set.prototype.forEach.call(m, callback);
43
}, TypeError, "Set.prototype.forEach should raise TypeError if not a used on a Set");
44
45
var fn = 2;
46
assertThrowsInstanceOf(function() {
47
    initialSet.forEach(fn);
48
}, TypeError, "Set.prototype.forEach should raise TypeError if callback is not a function");
49
50
// testing that Set#forEach uses internal next() function and does not stop when
51
// StopIteration exception is thrown
52
53
var s = new Set(["one", 1]);
54
Object.getPrototypeOf(s.iterator()).next = function () { throw "FAIL"; };
55
assertThrowsInstanceOf(function () {
56
  s.forEach(function () { throw StopIteration; });
57
}, StopIteration, "Set.prototype.forEach should use intrinsic next method.");

Return to bug 866847