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
parent de50f63f
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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 // This file relies on the fact that the following declarations have been made
// in runtime.js: // in runtime.js:
// var $Array = global.Array; // var $Array = global.Array;
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"use strict"; "use strict";
// This file relies on the fact that the following declaration has been made // This file relies on the fact that the following declaration has been made
......
...@@ -46,10 +46,10 @@ f(null); ...@@ -46,10 +46,10 @@ f(null);
// Check called from eval. // Check called from eval.
eval('f(null)'); eval('f(null)');
// Check called from builtin functions. Only show the initially called // Check called from strict builtin functions.
// (publicly exposed) builtin function, not it's internal helper functions. [null, null].sort(f);
[Array.prototype.sort, Array.prototype.sort].sort(f);
// Check called from sloppy builtin functions.
"abel".replace(/b/g, function h() { "abel".replace(/b/g, function h() {
assertEquals(String.prototype.replace, h.caller); assertEquals(String.prototype.replace, h.caller);
}); });
...@@ -322,13 +322,15 @@ Object.freeze(obj); ...@@ -322,13 +322,15 @@ Object.freeze(obj);
// sufficient. // sufficient.
assertTrue(Object.isSealed(obj)); assertTrue(Object.isSealed(obj));
assertDoesNotThrow(function() { obj.push(); }); // Verify that the length can't be written by builtins.
assertDoesNotThrow(function() { obj.unshift(); }); assertThrows(function() { obj.push(); }, TypeError);
assertDoesNotThrow(function() { obj.splice(0,0); }); assertThrows(function() { obj.unshift(); }, TypeError);
assertThrows(function() { obj.splice(0,0); }, TypeError);
assertTrue(Object.isFrozen(obj)); assertTrue(Object.isFrozen(obj));
// Verify that an item can't be changed with splice. // Verify that an item can't be changed with splice.
assertThrows(function() { obj.splice(0,1,1); }, TypeError); assertThrows(function() { obj.splice(0,1,1); }, TypeError);
assertTrue(Object.isFrozen(obj));
// Verify that unshift() with no arguments will fail if it reifies from // Verify that unshift() with no arguments will fail if it reifies from
// the prototype into the object. // the prototype into the object.
......
...@@ -30,19 +30,19 @@ ...@@ -30,19 +30,19 @@
function testfn(f) { return [1].map(f)[0]; } function testfn(f) { return [1].map(f)[0]; }
function foo() { return [].map.caller; } 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 // Try to delete the caller property (to make sure that we can't get to the
// caller accessor on the prototype. // caller accessor on the prototype.
delete Array.prototype.map.caller; delete Array.prototype.map.caller;
assertEquals(null, testfn(foo)); assertThrows(function() { testfn(foo); } );
// Redo tests with arguments object. // Redo tests with arguments object.
function testarguments(f) { return [1].map(f)[0]; } function testarguments(f) { return [1].map(f)[0]; }
function bar() { return [].map.arguments; } 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 // Try to delete the arguments property (to make sure that we can't get to the
// caller accessor on the prototype. // caller accessor on the prototype.
delete Array.prototype.map.arguments; delete Array.prototype.map.arguments;
assertEquals(null, testarguments(bar)); assertThrows(function() { testarguments(bar); } );
...@@ -27,10 +27,10 @@ ...@@ -27,10 +27,10 @@
var a = [5, 4, 3, 2, 1, 0]; var a = [5, 4, 3, 2, 1, 0];
Object.freeze(a); Object.freeze(a);
a.sort(); assertThrows(function() { a.sort(); });
assertArrayEquals([5, 4, 3, 2, 1, 0], a); assertArrayEquals([5, 4, 3, 2, 1, 0], a);
var b = {0: 5, 1: 4, 2: 3, 3: 2, 4: 1, 5: 0, length: 6}; var b = {0: 5, 1: 4, 2: 3, 3: 2, 4: 1, 5: 0, length: 6};
Object.freeze(b); 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); assertPropertiesEqual({0: 5, 1: 4, 2: 3, 3: 2, 4: 1, 5: 0, length: 6}, b);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment