From b280ad6c44e2f8a38bf5aa5713c58a4d2d8155c9 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Mon, 14 Apr 2014 11:24:40 +0000 Subject: [PATCH] Try to switch Array builtins into strict mode. R=rossberg@chromium.org TEST=mjsunit,test262,webkit Review URL: https://codereview.chromium.org/233083003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20717 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/array.js | 2 ++ src/promise.js | 1 - test/mjsunit/function-caller.js | 6 +++--- test/mjsunit/object-freeze.js | 8 +++++--- test/mjsunit/regress/regress-1548.js | 8 ++++---- test/mjsunit/regress/regress-2419.js | 4 ++-- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/array.js b/src/array.js index b3b25ed..e23ecf3 100644 --- a/src/array.js +++ b/src/array.js @@ -25,6 +25,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +"use strict"; + // This file relies on the fact that the following declarations have been made // in runtime.js: // var $Array = global.Array; diff --git a/src/promise.js b/src/promise.js index 5a834bd..27890a7 100644 --- a/src/promise.js +++ b/src/promise.js @@ -25,7 +25,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - "use strict"; // This file relies on the fact that the following declaration has been made diff --git a/test/mjsunit/function-caller.js b/test/mjsunit/function-caller.js index bc01750..a2c54bb 100644 --- a/test/mjsunit/function-caller.js +++ b/test/mjsunit/function-caller.js @@ -46,10 +46,10 @@ f(null); // Check called from eval. eval('f(null)'); -// Check called from builtin functions. Only show the initially called -// (publicly exposed) builtin function, not it's internal helper functions. -[Array.prototype.sort, Array.prototype.sort].sort(f); +// Check called from strict builtin functions. +[null, null].sort(f); +// Check called from sloppy builtin functions. "abel".replace(/b/g, function h() { assertEquals(String.prototype.replace, h.caller); }); diff --git a/test/mjsunit/object-freeze.js b/test/mjsunit/object-freeze.js index 3b79874..4144936 100644 --- a/test/mjsunit/object-freeze.js +++ b/test/mjsunit/object-freeze.js @@ -322,13 +322,15 @@ Object.freeze(obj); // sufficient. assertTrue(Object.isSealed(obj)); -assertDoesNotThrow(function() { obj.push(); }); -assertDoesNotThrow(function() { obj.unshift(); }); -assertDoesNotThrow(function() { obj.splice(0,0); }); +// Verify that the length can't be written by builtins. +assertThrows(function() { obj.push(); }, TypeError); +assertThrows(function() { obj.unshift(); }, TypeError); +assertThrows(function() { obj.splice(0,0); }, TypeError); assertTrue(Object.isFrozen(obj)); // Verify that an item can't be changed with splice. assertThrows(function() { obj.splice(0,1,1); }, TypeError); +assertTrue(Object.isFrozen(obj)); // Verify that unshift() with no arguments will fail if it reifies from // the prototype into the object. diff --git a/test/mjsunit/regress/regress-1548.js b/test/mjsunit/regress/regress-1548.js index 074007b..5330e13 100644 --- a/test/mjsunit/regress/regress-1548.js +++ b/test/mjsunit/regress/regress-1548.js @@ -30,19 +30,19 @@ function testfn(f) { return [1].map(f)[0]; } function foo() { return [].map.caller; } -assertEquals(null, testfn(foo)); +assertThrows(function() { testfn(foo); } ); // Try to delete the caller property (to make sure that we can't get to the // caller accessor on the prototype. delete Array.prototype.map.caller; -assertEquals(null, testfn(foo)); +assertThrows(function() { testfn(foo); } ); // Redo tests with arguments object. function testarguments(f) { return [1].map(f)[0]; } function bar() { return [].map.arguments; } -assertEquals(null, testfn(bar)); +assertThrows(function() { testarguments(bar); } ); // Try to delete the arguments property (to make sure that we can't get to the // caller accessor on the prototype. delete Array.prototype.map.arguments; -assertEquals(null, testarguments(bar)); +assertThrows(function() { testarguments(bar); } ); diff --git a/test/mjsunit/regress/regress-2419.js b/test/mjsunit/regress/regress-2419.js index 4ffafbe..612e6db 100644 --- a/test/mjsunit/regress/regress-2419.js +++ b/test/mjsunit/regress/regress-2419.js @@ -27,10 +27,10 @@ var a = [5, 4, 3, 2, 1, 0]; Object.freeze(a); -a.sort(); +assertThrows(function() { a.sort(); }); assertArrayEquals([5, 4, 3, 2, 1, 0], a); var b = {0: 5, 1: 4, 2: 3, 3: 2, 4: 1, 5: 0, length: 6}; Object.freeze(b); -Array.prototype.sort.call(b); +assertThrows(function() { Array.prototype.sort.call(b); }); assertPropertiesEqual({0: 5, 1: 4, 2: 3, 3: 2, 4: 1, 5: 0, length: 6}, b); -- 2.7.4