summaryrefslogtreecommitdiffstats
path: root/js/src/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/builtin')
-rw-r--r--js/src/builtin/Map.js11
-rw-r--r--js/src/builtin/Set.js7
-rw-r--r--js/src/builtin/Utilities.js23
-rw-r--r--js/src/builtin/WeakMap.js11
-rw-r--r--js/src/builtin/WeakSet.js7
5 files changed, 53 insertions, 6 deletions
diff --git a/js/src/builtin/Map.js b/js/src/builtin/Map.js
index 432364614..27a12bfff 100644
--- a/js/src/builtin/Map.js
+++ b/js/src/builtin/Map.js
@@ -40,11 +40,18 @@ function MapConstructorInit(iterable) {
var nextItem = next.value;
// Step 8.d.
- if (!IsObject(nextItem))
+ if (!IsObject(nextItem)) {
+ IteratorCloseThrow(iter);
ThrowTypeError(JSMSG_INVALID_MAP_ITERABLE, "Map");
+ }
// Steps 8.e-j.
- callContentFunction(adder, map, nextItem[0], nextItem[1]);
+ try {
+ callContentFunction(adder, map, nextItem[0], nextItem[1]);
+ } catch (e) {
+ IteratorCloseThrow(iter);
+ throw e;
+ }
}
}
diff --git a/js/src/builtin/Set.js b/js/src/builtin/Set.js
index accc70120..c61a49ef8 100644
--- a/js/src/builtin/Set.js
+++ b/js/src/builtin/Set.js
@@ -40,7 +40,12 @@ function SetConstructorInit(iterable) {
var nextValue = next.value;
// Steps 8.d-e.
- callContentFunction(adder, set, nextValue);
+ try {
+ callContentFunction(adder, set, nextValue);
+ } catch (e) {
+ IteratorCloseThrow(iter);
+ throw e;
+ }
}
}
diff --git a/js/src/builtin/Utilities.js b/js/src/builtin/Utilities.js
index bfb1fe7f4..2dece3801 100644
--- a/js/src/builtin/Utilities.js
+++ b/js/src/builtin/Utilities.js
@@ -154,6 +154,29 @@ function GetIterator(obj, method) {
return iterator;
}
+// ES2017 draft rev 7.4.6.
+// When completion.[[Type]] is throw.
+function IteratorCloseThrow(iter) {
+ // Steps 1-2 (implicit)
+
+ // Step 3.
+ var returnMethod = GetMethod(iter, "return");
+
+ // Step 4 (done in caller).
+ if (returnMethod === undefined)
+ return;
+
+ try {
+ // Step 5.
+ callContentFunction(returnMethod, iter);
+ } catch (e) {
+ }
+
+ // Step 6 (done in caller).
+
+ // Steps 7-9 (skipped).
+}
+
var _builtinCtorsCache = {__proto__: null};
function GetBuiltinConstructor(builtinName) {
diff --git a/js/src/builtin/WeakMap.js b/js/src/builtin/WeakMap.js
index 066a72bfe..708be8424 100644
--- a/js/src/builtin/WeakMap.js
+++ b/js/src/builtin/WeakMap.js
@@ -40,10 +40,17 @@ function WeakMapConstructorInit(iterable) {
var nextItem = next.value;
// Step 8.d.
- if (!IsObject(nextItem))
+ if (!IsObject(nextItem)) {
+ IteratorCloseThrow(iter);
ThrowTypeError(JSMSG_INVALID_MAP_ITERABLE, "WeakMap");
+ }
// Steps 8.e-j.
- callContentFunction(adder, map, nextItem[0], nextItem[1]);
+ try {
+ callContentFunction(adder, map, nextItem[0], nextItem[1]);
+ } catch (e) {
+ IteratorCloseThrow(iter);
+ throw e;
+ }
}
}
diff --git a/js/src/builtin/WeakSet.js b/js/src/builtin/WeakSet.js
index eb7c2378f..8589f9dc6 100644
--- a/js/src/builtin/WeakSet.js
+++ b/js/src/builtin/WeakSet.js
@@ -40,7 +40,12 @@ function WeakSetConstructorInit(iterable) {
var nextValue = next.value;
// Steps 8.d-e.
- callContentFunction(adder, set, nextValue);
+ try {
+ callContentFunction(adder, set, nextValue);
+ } catch (e) {
+ IteratorCloseThrow(iter);
+ throw e;
+ }
}
}