mirror of
https://github.com/tc39/test262.git
synced 2025-07-27 16:04:36 +02:00
Add tests for Subclassing the built-in String Objects
This commit is contained in:
parent
fc160c78ad
commit
27764aa355
30
test/language/subclassing/String/length.js
Normal file
30
test/language/subclassing/String/length.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 21.1.4
|
||||||
|
description: Instances has the own property length
|
||||||
|
info: >
|
||||||
|
21.1.4 Properties of String Instances
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
String instances have a length property, and a set of enumerable properties
|
||||||
|
with integer indexed names.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class S extends String {}
|
||||||
|
|
||||||
|
var s1 = new S();
|
||||||
|
assert.sameValue(s1.length, 0);
|
||||||
|
|
||||||
|
verifyNotWritable(s1, 'length');
|
||||||
|
verifyNotEnumerable(s1, 'length');
|
||||||
|
verifyNotConfigurable(s1, 'length');
|
||||||
|
|
||||||
|
var s2 = new S('test262');
|
||||||
|
assert.sameValue(s2.length, 7);
|
||||||
|
|
||||||
|
verifyNotWritable(s2, 'length');
|
||||||
|
verifyNotEnumerable(s2, 'length');
|
||||||
|
verifyNotConfigurable(s2, 'length');
|
22
test/language/subclassing/String/regular-subclassing.js
Normal file
22
test/language/subclassing/String/regular-subclassing.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 21.1.1
|
||||||
|
description: Subclassing the String object
|
||||||
|
info: >
|
||||||
|
21.1.1 The String Constructor
|
||||||
|
|
||||||
|
...
|
||||||
|
The String constructor is designed to be subclassable. It may be used as the
|
||||||
|
value of an extends clause of a class definition. Subclass constructors that
|
||||||
|
intend to inherit the specified String behaviour must include a super call to
|
||||||
|
the String constructor to create and initialize the subclass instance with a
|
||||||
|
[[StringData]] internal slot.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class S extends String {}
|
||||||
|
|
||||||
|
var s = new S(' test262 ');
|
||||||
|
|
||||||
|
assert.sameValue(s.trim(), 'test262');
|
||||||
|
|
31
test/language/subclassing/String/super-must-be-called.js
Normal file
31
test/language/subclassing/String/super-must-be-called.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 21.1.1
|
||||||
|
description: Super need to be called to initialize internals
|
||||||
|
info: >
|
||||||
|
21.1.1 The String Constructor
|
||||||
|
|
||||||
|
...
|
||||||
|
The String constructor is designed to be subclassable. It may be used as the
|
||||||
|
value of an extends clause of a class definition. Subclass constructors that
|
||||||
|
intend to inherit the specified String behaviour must include a super call to
|
||||||
|
the String constructor to create and initialize the subclass instance with a
|
||||||
|
[[StringData]] internal slot.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class S1 extends String {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
new S1();
|
||||||
|
});
|
||||||
|
|
||||||
|
class S2 extends String {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new S2();
|
Loading…
x
Reference in New Issue
Block a user