From 4e079a8cabd96ed8e8bd52a5a3d5be16e288583d Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Tue, 12 Jan 2016 14:02:00 -0500 Subject: [PATCH] Add tests for Subclassing the built-in DataView Objects --- .../DataView/regular-subclassing.js | 28 +++++++++++++++ .../DataView/super-must-be-called.js | 35 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/language/subclassing/DataView/regular-subclassing.js create mode 100644 test/language/subclassing/DataView/super-must-be-called.js diff --git a/test/language/subclassing/DataView/regular-subclassing.js b/test/language/subclassing/DataView/regular-subclassing.js new file mode 100644 index 0000000000..e54a7de6b9 --- /dev/null +++ b/test/language/subclassing/DataView/regular-subclassing.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 24.2.2 +description: Subclassing the DataView object +info: > + 24.2.2 The DataView Constructor + + ... + + The DataView 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 DataView behaviour must include a super call + to the DataView constructor to create and initialize subclass instances with + the internal state necessary to support the DataView.prototype built-in + methods. +---*/ + +class DV extends DataView {} + +var buffer = new ArrayBuffer(1); + +var dv = new DV(buffer); +assert.sameValue(dv.buffer, buffer); + +assert.throws(TypeError, function() { + new DV(); +}); diff --git a/test/language/subclassing/DataView/super-must-be-called.js b/test/language/subclassing/DataView/super-must-be-called.js new file mode 100644 index 0000000000..34103c829d --- /dev/null +++ b/test/language/subclassing/DataView/super-must-be-called.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 24.2.2 +description: Super need to be called to initialize internals +info: > + 24.2.2 The DataView Constructor + + ... + + The DataView 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 DataView behaviour must include a super call + to the DataView constructor to create and initialize subclass instances with + the internal state necessary to support the DataView.prototype built-in + methods. +---*/ + +class DV1 extends DataView { + constructor() {} +} + +var buffer = new ArrayBuffer(1); + +assert.throws(ReferenceError, function() { + new DV1(buffer); +}); + +class DV2 extends DataView { + constructor(length) { + super(length); + } +} + +new DV2(buffer);