Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: test/mjsunit/regress/regress-595319.js

Issue 1814933002: Throw the right exceptions from setting elements in Array.prototype.concat (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: format Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/regress/regress-595319.js
diff --git a/test/mjsunit/regress/regress-595319.js b/test/mjsunit/regress/regress-595319.js
new file mode 100644
index 0000000000000000000000000000000000000000..46ca27444f4f8902a9d53864c794c9cc987057c5
--- /dev/null
+++ b/test/mjsunit/regress/regress-595319.js
@@ -0,0 +1,39 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// https://bugs.chromium.org/p/chromium/issues/detail?id=595319
+// Ensure exceptions are checked for by Array.prototype.concat from adding
+// an element, and that elements are added to array subclasses appropriately
+
+// If adding a property does throw, the exception is propagated
+class MyException extends Error { }
+class NoDefinePropertyArray extends Array {
+ constructor(...args) {
+ super(...args);
+ return new Proxy(this, {
+ defineProperty() { throw new MyException(); }
+ });
+ }
+}
+assertThrows(() => new NoDefinePropertyArray().concat([1]), MyException);
+
+// Ensure elements are added to the instance, rather than calling [[Set]].
+class ZeroGetterArray extends Array { get 0() {} };
+assertArrayEquals([1], new ZeroGetterArray().concat(1));
+
+// Frozen arrays lead to throwing
+
+class FrozenArray extends Array {
+ constructor(...args) { super(...args); Object.freeze(this); }
+}
+assertThrows(() => new FrozenArray().concat([1]), TypeError);
+
+// Non-configurable non-writable zero leads to throwing
+class ZeroFrozenArray extends Array {
+ constructor(...args) {
+ super(...args);
+ Object.defineProperty(this, 0, {value: 1});
+ }
+}
+assertThrows(() => new ZeroFrozenArray().concat([1]), TypeError);
« no previous file with comments | « src/builtins.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698