Skip to content
Snippets Groups Projects
Commit 27764aa3 authored by Leonardo Balter's avatar Leonardo Balter
Browse files

Add tests for Subclassing the built-in String Objects

parent fc160c78
No related branches found
No related tags found
No related merge requests found
// 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');
\ No newline at end of file
// 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');
// 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();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment