Title: [267125] trunk
- Revision
- 267125
- Author
- [email protected]
- Date
- 2020-09-15 18:17:07 -0700 (Tue, 15 Sep 2020)
Log Message
Check whether the iterator is callable in spread
https://bugs.webkit.org/show_bug.cgi?id=215974
Patch by HyeockJin Kim <[email protected]> on 2020-09-15
Reviewed by Darin Adler.
JSTests:
* stress/spread-array-iterator.js: Added.
(shouldThrowTypeError):
(shouldThrowExactly):
(f):
(C):
Source/_javascript_Core:
* builtins/IteratorHelpers.js:
(performIteration):
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (267124 => 267125)
--- trunk/JSTests/ChangeLog 2020-09-16 01:07:47 UTC (rev 267124)
+++ trunk/JSTests/ChangeLog 2020-09-16 01:17:07 UTC (rev 267125)
@@ -1,3 +1,16 @@
+2020-09-15 HyeockJin Kim <[email protected]>
+
+ Check whether the iterator is callable in spread
+ https://bugs.webkit.org/show_bug.cgi?id=215974
+
+ Reviewed by Darin Adler.
+
+ * stress/spread-array-iterator.js: Added.
+ (shouldThrowTypeError):
+ (shouldThrowExactly):
+ (f):
+ (C):
+
2020-09-15 Yusuke Suzuki <[email protected]>
Unreviewed, skip construct-return-early-from-infinite-loop-for-fuzzer.js when JIT is disabled
Added: trunk/JSTests/stress/spread-array-iterator.js (0 => 267125)
--- trunk/JSTests/stress/spread-array-iterator.js (rev 0)
+++ trunk/JSTests/stress/spread-array-iterator.js 2020-09-16 01:17:07 UTC (rev 267125)
@@ -0,0 +1,72 @@
+function shouldThrowTypeError(func, messagePrefix) {
+ let error;
+ try {
+ func();
+ } catch (e) {
+ error = e;
+ }
+
+ if (!(error instanceof TypeError))
+ throw new Error('Expected TypeError!');
+
+ if (!error.message.startsWith(messagePrefix))
+ throw new Error('TypeError has wrong message!');
+}
+
+function shouldThrowExactly(func, expectedError) {
+ let error;
+ try {
+ func();
+ } catch (e) {
+ error = e;
+ }
+
+ if (error !== expectedError)
+ throw new Error(`Expected ${errorType.name}!`);
+}
+
+shouldThrowTypeError(() => ([...1]), 'Spread syntax requires ...iterable[Symbol.iterator] to be a function');
+shouldThrowTypeError(() => ([...undefined]), 'Spread syntax requires ...iterable not be null or undefined');
+shouldThrowTypeError(() => ([...null]), 'Spread syntax requires ...iterable not be null or undefined');
+shouldThrowTypeError(() => ([...3.14]), 'Spread syntax requires ...iterable[Symbol.iterator] to be a function');
+shouldThrowTypeError(() => ([.../a/g]), 'Spread syntax requires ...iterable[Symbol.iterator] to be a function');
+shouldThrowTypeError(() => ([...{}]), 'Spread syntax requires ...iterable[Symbol.iterator] to be a function');
+shouldThrowTypeError(() => ([...{a:[].join()}]), 'Spread syntax requires ...iterable[Symbol.iterator] to be a function');
+
+function f() {}
+shouldThrowTypeError(() => ([...f]), 'Spread syntax requires ...iterable[Symbol.iterator] to be a function');
+shouldThrowTypeError(() => ([...[...() => undefined]]), 'Spread syntax requires ...iterable[Symbol.iterator] to be a function');
+
+class C {}
+shouldThrowTypeError(() => ([...new C()]), 'Spread syntax requires ...iterable[Symbol.iterator] to be a function');
+shouldThrowTypeError(() => ([...C]), 'Spread syntax requires ...iterable[Symbol.iterator] to be a function');
+
+const myErr = new Error('Custom Error');
+shouldThrowExactly(() => [...{ [Symbol.iterator]() { throw myErr; }}], myErr);
+
+let iteratorCount = 0;
+let toStringCount = 0;
+const myIterable = {
+ [Symbol.iterator]() {
+ iteratorCount += 1;
+ return {
+ next() {
+ return { done: true };
+ }
+ };
+ },
+ toString() {
+ toStringCount += 1;
+ return "Iterable";
+ }
+};
+
+function assertEqual(a, b) {
+ if (a !== b)
+ throw new Error(`${a} !== ${b}`);
+}
+
+[...myIterable];
+assertEqual(iteratorCount, 1);
+assertEqual(toStringCount, 0);
+
Modified: trunk/Source/_javascript_Core/ChangeLog (267124 => 267125)
--- trunk/Source/_javascript_Core/ChangeLog 2020-09-16 01:07:47 UTC (rev 267124)
+++ trunk/Source/_javascript_Core/ChangeLog 2020-09-16 01:17:07 UTC (rev 267125)
@@ -1,3 +1,13 @@
+2020-09-15 HyeockJin Kim <[email protected]>
+
+ Check whether the iterator is callable in spread
+ https://bugs.webkit.org/show_bug.cgi?id=215974
+
+ Reviewed by Darin Adler.
+
+ * builtins/IteratorHelpers.js:
+ (performIteration):
+
2020-09-15 Tadeu Zagallo <[email protected]>
Object allocation sinking forgets escaped nodes when structure changes
Modified: trunk/Source/_javascript_Core/builtins/IteratorHelpers.js (267124 => 267125)
--- trunk/Source/_javascript_Core/builtins/IteratorHelpers.js 2020-09-16 01:07:47 UTC (rev 267124)
+++ trunk/Source/_javascript_Core/builtins/IteratorHelpers.js 2020-09-16 01:17:07 UTC (rev 267125)
@@ -31,8 +31,14 @@
// https://tc39.github.io/ecma262/#sec-runtime-semantics-arrayaccumulation
var result = [];
+ if (@isUndefinedOrNull(iterable))
+ @throwTypeError('Spread syntax requires ...iterable not be null or undefined');
+
+ var iteratorMethod = iterable.@@iterator;
+ if (!@isCallable(iteratorMethod))
+ @throwTypeError('Spread syntax requires ...iterable[Symbol.iterator] to be a function');
- var iterator = iterable.@@iterator();
+ var iterator = iteratorMethod.@call(iterable);
var next = iterator.next;
var item;
var index = 0;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes