| 1 |
var g_foo = "foo"; |
| 2 |
var g_bar = "bar"; |
| 3 |
|
| 4 |
// Define base class with a read-only and a writable data property |
| 5 |
class Base |
| 6 |
{ |
| 7 |
} |
| 8 |
Object.defineProperty(Base.prototype, "foo", { value: "Base", writable: true }); |
| 9 |
Object.defineProperty(Base.prototype, "bar", { value: "Base", writable: false }); |
| 10 |
|
| 11 |
// Test various cases that should throw during SETPROP_SUPER |
| 12 |
class Derived extends Base |
| 13 |
{ |
| 14 |
// ECMA-2018 9.1.9.1, step 4.a |
| 15 |
testReadonly() { |
| 16 |
super.bar = "Derived"; |
| 17 |
} |
| 18 |
testReadonlyElem() { |
| 19 |
super[g_bar] = "Derived"; |
| 20 |
} |
| 21 |
|
| 22 |
// ECMA-2018 9.1.9.1, step 4.b |
| 23 |
testPrimitiveReceiver() { |
| 24 |
super.foo = "Derived"; |
| 25 |
} |
| 26 |
testPrimitiveReceiverElem() { |
| 27 |
super[g_foo] = "Derived"; |
| 28 |
} |
| 29 |
|
| 30 |
// ECMA-2018 9.1.9.1, step 4.d.i |
| 31 |
testAccessorShadow() { |
| 32 |
Object.defineProperty(this, "foo", { get: function() { } }); |
| 33 |
super.foo = "Derived"; |
| 34 |
} |
| 35 |
testAccessorShadowElem() { |
| 36 |
Object.defineProperty(this, "foo", { get: function() { } }); |
| 37 |
super[g_foo] = "Derived"; |
| 38 |
} |
| 39 |
|
| 40 |
// ECMA-2018 9.1.9.1, step 4.d.ii |
| 41 |
testReadonlyShadow() { |
| 42 |
Object.defineProperty(this, "foo", { writable: false }); |
| 43 |
super.foo = "Derived"; |
| 44 |
} |
| 45 |
testReadonlyShadowElem() { |
| 46 |
Object.defineProperty(this, "foo", { writable: false }); |
| 47 |
super[g_foo] = "Derived"; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
for (let i = 0; i < 10; ++i) { |
| 52 |
var cnt = 0; |
| 53 |
|
| 54 |
try { new Derived().testReadonly(); } catch(e) { cnt++; } |
| 55 |
try { new Derived().testReadonlyElem(); } catch(e) { cnt++; } |
| 56 |
try { Derived.prototype.testPrimitiveReceiver.call(null); } catch(e) { cnt++; } |
| 57 |
try { Derived.prototype.testPrimitiveReceiverElem.call(null); } catch(e) { cnt++; } |
| 58 |
try { new Derived().testAccessorShadow(); } catch(e) { cnt++; } |
| 59 |
try { new Derived().testAccessorShadowElem(); } catch(e) { cnt++; } |
| 60 |
try { new Derived().testReadonlyShadow(); } catch(e) { cnt++; } |
| 61 |
try { new Derived().testReadonlyShadowElem(); } catch(e) { cnt++; } |
| 62 |
|
| 63 |
assertEq(cnt, 8); |
| 64 |
} |