regular-subclassing.js (1266B)
1 // Copyright (C) 2016 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 es6id: 20.3.2 5 description: Subclassing the String object 6 info: | 7 20.3.2 The Date Constructor 8 9 ... 10 11 The Date constructor is a single function whose behaviour is overloaded based 12 upon the number and types of its arguments. 13 14 The Date constructor is designed to be subclassable. It may be used as the 15 value of an extends clause of a class definition. Subclass constructors that 16 intend to inherit the specified Date behaviour must include a super call to 17 the Date constructor to create and initialize the subclass instance with a 18 [[DateValue]] internal slot. 19 ---*/ 20 21 class D extends Date {} 22 23 var d1 = new D(1859, '10', 24, 11); 24 assert.sameValue(d1.getFullYear(), 1859); 25 assert.sameValue(d1.getMonth(), 10); 26 assert.sameValue(d1.getDate(), 24); 27 28 var d2 = new D(-3474558000000); 29 assert.sameValue(d2.getUTCFullYear(), 1859); 30 assert.sameValue(d2.getUTCMonth(), 10); 31 assert.sameValue(d2.getUTCDate(), 24); 32 33 var d3 = new D(); 34 var d4 = new Date(); 35 assert.sameValue(d3.getFullYear(), d4.getFullYear()); 36 assert.sameValue(d3.getMonth(), d4.getMonth()); 37 assert.sameValue(d3.getDate(), d4.getDate()); 38 39 reportCompare(0, 0);