Follow-up to a pre-existing regression test.

R=yangguo@chromium.org
BUG=v8:1530,v8:1872
TEST=mjsunit/regress/regress-1530
LOG=N

Review URL: https://codereview.chromium.org/378233006

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22295 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 22005222
......@@ -33,34 +33,52 @@ var f = function() {};
// Verify that normal assignment of 'prototype' property works properly
// and updates the internal value.
var x = { foo: 'bar' };
f.prototype = x;
assertSame(f.prototype, x);
var a = { foo: 'bar' };
f.prototype = a;
assertSame(f.prototype, a);
assertSame(f.prototype.foo, 'bar');
assertSame(new f().foo, 'bar');
assertSame(Object.getPrototypeOf(new f()), x);
assertSame(Object.getOwnPropertyDescriptor(f, 'prototype').value, x);
assertSame(Object.getPrototypeOf(new f()), a);
assertSame(Object.getOwnPropertyDescriptor(f, 'prototype').value, a);
assertTrue(Object.getOwnPropertyDescriptor(f, 'prototype').writable);
// Verify that 'prototype' behaves like a data property when it comes to
// redefining with Object.defineProperty() and the internal value gets
// updated.
var y = { foo: 'baz' };
Object.defineProperty(f, 'prototype', { value: y, writable: true });
assertSame(f.prototype, y);
var b = { foo: 'baz' };
Object.defineProperty(f, 'prototype', { value: b, writable: true });
assertSame(f.prototype, b);
assertSame(f.prototype.foo, 'baz');
assertSame(new f().foo, 'baz');
assertSame(Object.getPrototypeOf(new f()), y);
assertSame(Object.getOwnPropertyDescriptor(f, 'prototype').value, y);
assertSame(Object.getPrototypeOf(new f()), b);
assertSame(Object.getOwnPropertyDescriptor(f, 'prototype').value, b);
assertTrue(Object.getOwnPropertyDescriptor(f, 'prototype').writable);
// Verify that the previous redefinition didn't screw up callbacks and
// the internal value still gets updated.
var z = { foo: 'other' };
f.prototype = z;
assertSame(f.prototype, z);
var c = { foo: 'other' };
f.prototype = c;
assertSame(f.prototype, c);
assertSame(f.prototype.foo, 'other');
assertSame(new f().foo, 'other');
assertSame(Object.getPrototypeOf(new f()), z);
assertSame(Object.getOwnPropertyDescriptor(f, 'prototype').value, z);
assertSame(Object.getPrototypeOf(new f()), c);
assertSame(Object.getOwnPropertyDescriptor(f, 'prototype').value, c);
assertTrue(Object.getOwnPropertyDescriptor(f, 'prototype').writable);
// Verify that 'prototype' can be redefined to contain a different value
// and have a different writability attribute at the same time.
var d = { foo: 'final' };
Object.defineProperty(f, 'prototype', { value: d, writable: false });
assertSame(f.prototype, d);
assertSame(f.prototype.foo, 'final');
assertSame(new f().foo, 'final');
assertSame(Object.getPrototypeOf(new f()), d);
assertSame(Object.getOwnPropertyDescriptor(f, 'prototype').value, d);
assertFalse(Object.getOwnPropertyDescriptor(f, 'prototype').writable);
// Verify that non-writability of redefined 'prototype' is respected.
assertThrows("'use strict'; f.prototype = {}");
assertThrows("Object.defineProperty(f, 'prototype', { value: {} })");
// Verify that non-writability of other properties is respected.
assertThrows("Object.defineProperty(f, 'name', { value: {} })");
......
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