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

Unified Diff: test/mjsunit/array-methods-read-only-length.js

Issue 726773002: Throw as per spec when modifying an Array with builtin methods (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added a TODO Created 6 years, 1 month 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/objects.cc ('k') | test/mjsunit/array-push-unshift-read-only-length.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/array-methods-read-only-length.js
diff --git a/test/mjsunit/array-push-unshift-read-only-length.js b/test/mjsunit/array-methods-read-only-length.js
similarity index 58%
rename from test/mjsunit/array-push-unshift-read-only-length.js
rename to test/mjsunit/array-methods-read-only-length.js
index 67aa39787aaf8b6f1b0febc15f4d7394782587a6..925ef1f67fe2047fe78297d7e27031a7c8a2487a 100644
--- a/test/mjsunit/array-push-unshift-read-only-length.js
+++ b/test/mjsunit/array-methods-read-only-length.js
@@ -4,14 +4,12 @@
// Flags: --allow-natives-syntax
-function test(mode) {
+function testAdd(mode) {
var a = [];
Object.defineProperty(a, "length", { writable : false});
function check(f) {
- try {
- f(a);
- } catch(e) { }
+ assertThrows(function() { f(a) }, TypeError);
assertFalse(0 in a);
assertEquals(0, a.length);
}
@@ -37,11 +35,67 @@ function test(mode) {
check(unshift);
%OptimizeFunctionOnNextCall(unshift);
check(unshift);
+
+ function splice(a) {
+ a.splice(0, 0, 3);
+ }
+
+ check(splice);
+ check(splice);
+ check(splice);
+ %OptimizeFunctionOnNextCall(splice);
+ check(splice);
}
-test("fast properties");
+testAdd("fast properties");
+
+testAdd("normalized");
+
+function testRemove(mode) {
+ var a = [1, 2, 3];
+ Object.defineProperty(a, "length", { writable : false});
+
+ function check(f) {
+ assertThrows(function() { f(a) }, TypeError);
+ assertEquals(3, a.length);
+ }
+
+ if (mode == "fast properties") %ToFastProperties(a);
-test("normalized");
+ function pop(a) {
+ a.pop();
+ }
+
+ check(pop);
+ check(pop);
+ check(pop);
+ %OptimizeFunctionOnNextCall(pop);
+ check(pop);
+
+ function shift(a) {
+ a.shift();
+ }
+
+ check(shift);
+ check(shift);
+ check(shift);
+ %OptimizeFunctionOnNextCall(shift);
+ check(shift);
+
+ function splice(a) {
+ a.splice(0, 1);
+ }
+
+ check(splice);
+ check(splice);
+ check(splice);
+ %OptimizeFunctionOnNextCall(splice);
+ check(splice);
+}
+
+testRemove("fast properties");
+
+testRemove("normalized");
var b = [];
Object.defineProperty(b.__proto__, "0", {
@@ -97,11 +151,6 @@ try {
b.unshift(3, 4, 5);
} catch(e) { }
-// TODO(ulan): According to the ECMA-262 unshift should throw an exception
-// when moving b[0] to b[3] (see 15.4.4.13 step 6.d.ii). This is difficult
-// to do with our current implementation of SmartMove() in src/array.js and
-// it will regress performance. Uncomment the following line once acceptable
-// solution is found:
-// assertFalse(2 in b);
-// assertFalse(3 in b);
-// assertEquals(2, b.length);
+assertFalse(2 in b);
+assertFalse(3 in b);
+assertEquals(2, b.length);
« no previous file with comments | « src/objects.cc ('k') | test/mjsunit/array-push-unshift-read-only-length.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698