Attachment #760433: patch v2 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 644-659   selfhosting_srcs := \ Link Here 
644
  $(srcdir)/builtin/Utilities.js \
644
  $(srcdir)/builtin/Utilities.js \
645
  $(srcdir)/builtin/Array.js \
645
  $(srcdir)/builtin/Array.js \
646
  $(srcdir)/builtin/Date.js \
646
  $(srcdir)/builtin/Date.js \
647
  $(srcdir)/builtin/Intl.js \
647
  $(srcdir)/builtin/Intl.js \
648
  $(srcdir)/builtin/IntlData.js \
648
  $(srcdir)/builtin/IntlData.js \
649
  $(srcdir)/builtin/Number.js \
649
  $(srcdir)/builtin/Number.js \
650
  $(srcdir)/builtin/ParallelArray.js \
650
  $(srcdir)/builtin/ParallelArray.js \
651
  $(srcdir)/builtin/String.js \
651
  $(srcdir)/builtin/String.js \
652
  $(srcdir)/builtin/Set.js \
653
  $(srcdir)/builtin/Map.js \
652
  $(NULL)
654
  $(NULL)
653
655
654
selfhosted_out_h_deps := \
656
selfhosted_out_h_deps := \
655
  $(selfhosting_srcs) \
657
  $(selfhosting_srcs) \
656
  $(srcdir)/js.msg \
658
  $(srcdir)/js.msg \
657
  $(srcdir)/builtin/embedjs.py \
659
  $(srcdir)/builtin/embedjs.py \
658
  $(NULL)
660
  $(NULL)
659
661
(-)a/js/src/builtin/Map.js (+29 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(typeof M != "object")
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
    for (var [k, v] of M) {
26
        if (k)
27
            callFunction(callbackfn, thisArg, v, k, M);
28
    }
29
}
(-)a/js/src/builtin/MapObject.cpp (+2 lines)
Line     Link Here 
 Lines 1037-1052   const JSPropertySpec MapObject::properti Link Here 
1037
const JSFunctionSpec MapObject::methods[] = {
1037
const JSFunctionSpec MapObject::methods[] = {
1038
    JS_FN("get", get, 1, 0),
1038
    JS_FN("get", get, 1, 0),
1039
    JS_FN("has", has, 1, 0),
1039
    JS_FN("has", has, 1, 0),
1040
    JS_FN("set", set, 2, 0),
1040
    JS_FN("set", set, 2, 0),
1041
    JS_FN("delete", delete_, 1, 0),
1041
    JS_FN("delete", delete_, 1, 0),
1042
    JS_FN("keys", keys, 0, 0),
1042
    JS_FN("keys", keys, 0, 0),
1043
    JS_FN("values", values, 0, 0),
1043
    JS_FN("values", values, 0, 0),
1044
    JS_FN("clear", clear, 0, 0),
1044
    JS_FN("clear", clear, 0, 0),
1045
    {"forEach", {NULL, NULL}, 1, 0, "MapForEach"},
1045
    JS_FS_END
1046
    JS_FS_END
1046
};
1047
};
1047
1048
1048
static JSObject *
1049
static JSObject *
1049
InitClass(JSContext *cx, Handle<GlobalObject*> global, Class *clasp, JSProtoKey key, Native construct,
1050
InitClass(JSContext *cx, Handle<GlobalObject*> global, Class *clasp, JSProtoKey key, Native construct,
1050
          const JSPropertySpec *properties, const JSFunctionSpec *methods)
1051
          const JSPropertySpec *properties, const JSFunctionSpec *methods)
1051
{
1052
{
1052
    Rooted<JSObject*> proto(cx, global->createBlankPrototype(cx, clasp));
1053
    Rooted<JSObject*> proto(cx, global->createBlankPrototype(cx, clasp));
 Lines 1615-1630   const JSPropertySpec SetObject::properti Link Here 
1615
};
1616
};
1616
1617
1617
const JSFunctionSpec SetObject::methods[] = {
1618
const JSFunctionSpec SetObject::methods[] = {
1618
    JS_FN("has", has, 1, 0),
1619
    JS_FN("has", has, 1, 0),
1619
    JS_FN("add", add, 1, 0),
1620
    JS_FN("add", add, 1, 0),
1620
    JS_FN("delete", delete_, 1, 0),
1621
    JS_FN("delete", delete_, 1, 0),
1621
    JS_FN("entries", entries, 0, 0),
1622
    JS_FN("entries", entries, 0, 0),
1622
    JS_FN("clear", clear, 0, 0),
1623
    JS_FN("clear", clear, 0, 0),
1624
    {"forEach", {NULL, NULL}, 1, 0, "SetForEach"},
1623
    JS_FS_END
1625
    JS_FS_END
1624
};
1626
};
1625
1627
1626
JSObject *
1628
JSObject *
1627
SetObject::initClass(JSContext *cx, JSObject *obj)
1629
SetObject::initClass(JSContext *cx, JSObject *obj)
1628
{
1630
{
1629
    Rooted<GlobalObject*> global(cx, &obj->asGlobal());
1631
    Rooted<GlobalObject*> global(cx, &obj->asGlobal());
1630
    RootedObject proto(cx,
1632
    RootedObject proto(cx,
(-)a/js/src/builtin/Set.js (+29 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(typeof S != "object")
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 M);
18
    }
19
20
    /* Step 5-6 */
21
	if (!IsCallable(callbackfn))
22
        ThrowError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
23
24
    /* Step 7-8 */
25
    for (var e of S) {
26
        if (e)
27
    	   callFunction(callbackfn, thisArg, e, e, S);
28
    }
29
}
(-)a/js/src/builtin/Utilities.js (-1 / +2 lines)
Line     Link Here 
 Lines 61-77   var std_String_replace = String.prototyp Link Here 
61
var std_String_split = String.prototype.split;
61
var std_String_split = String.prototype.split;
62
var std_String_startsWith = String.prototype.startsWith;
62
var std_String_startsWith = String.prototype.startsWith;
63
var std_String_substring = String.prototype.substring;
63
var std_String_substring = String.prototype.substring;
64
var std_String_toLowerCase = String.prototype.toLowerCase;
64
var std_String_toLowerCase = String.prototype.toLowerCase;
65
var std_String_toUpperCase = String.prototype.toUpperCase;
65
var std_String_toUpperCase = String.prototype.toUpperCase;
66
var std_WeakMap_get = WeakMap.prototype.get;
66
var std_WeakMap_get = WeakMap.prototype.get;
67
var std_WeakMap_has = WeakMap.prototype.has;
67
var std_WeakMap_has = WeakMap.prototype.has;
68
var std_WeakMap_set = WeakMap.prototype.set;
68
var std_WeakMap_set = WeakMap.prototype.set;
69
69
var std_Map_has = Map.prototype.has;
70
var std_Set_has = Set.prototype.has;
70
71
71
/********** List specification type **********/
72
/********** List specification type **********/
72
73
73
74
74
/* Spec: ECMAScript Language Specification, 5.1 edition, 8.8 */
75
/* Spec: ECMAScript Language Specification, 5.1 edition, 8.8 */
75
function List() {}
76
function List() {}
76
{
77
{
77
  let ListProto = std_Object_create(null);
78
  let ListProto = std_Object_create(null);
(-)a/js/src/jit-test/tests/collections/Map-forEach.js (+40 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], ['c', undefined]]);
16
initialMap.forEach(callback);
17
18
for (var [k, v] of testMap) {
19
    assertEq(initialMap.has(k), true);
20
    assertEq(initialMap.get(k), testMap.get(k));
21
}
22
23
var x = { abc: 'test'};
24
function callback2(value, key, map) {
25
    assertEq(x, this);
26
}
27
initialMap = new Map([['a', 1]]);
28
initialMap.forEach(callback2, x);
29
30
// testing failure conditions of Map.prototype.forEach
31
32
var s = new Set([1, 2, 3]);
33
assertThrowsInstanceOf(function() {
34
    Map.prototype.forEach.call(s, callback);
35
}, TypeError, "Map.prototype.forEach should raise TypeError if not a Map");
36
37
var fn = 2;
38
assertThrowsInstanceOf(function() {
39
    initialMap.forEach(fn);
40
}, TypeError, "Map.prototype.forEach should raise TypeError if callback is not a function");
(-)a/js/src/jit-test/tests/collections/Set-forEach.js (+39 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
for (var v of testSet) {
19
    assertEq(initialSet.has(v), true);
20
}
21
22
var x = { abc: 'test'};
23
function callback2(value, key, set) {
24
    assertEq(x, this);
25
}
26
initialSet = new Set(['a']);
27
initialSet.forEach(callback2, x);
28
29
// testing failure conditions of Map.prototype.forEach
30
31
var m = new Map([['a', 1], ['b', 2.3], ['c', undefined]]);
32
assertThrowsInstanceOf(function() {
33
    Set.prototype.forEach.call(m, callback);
34
}, TypeError, "Set.prototype.forEach should raise TypeError if not a Set");
35
36
var fn = 2;
37
assertThrowsInstanceOf(function() {
38
    initialSet.forEach(fn);
39
}, TypeError, "Set.prototype.forEach should raise TypeError if callback is not a function");

Return to bug 866847