diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/return-typedarrayname.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/return-typedarrayname.js new file mode 100644 index 0000000000000000000000000000000000000000..72127f90d212bbfd36ae2017ad525c8f20fd3d91 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/return-typedarrayname.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: | + Return value from the [[TypedArrayName]] internal slot +info: > + 22.2.3.32 get %TypedArray%.prototype [ @@toStringTag ] + + ... + 4. Let name be the value of O's [[TypedArrayName]] internal slot. + 5. Assert: name is a String value. + 6. Return name. +includes: [testTypedArray.js] +features: [Symbol.toStringTag] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta = new TA(); + assert.sameValue(ta[Symbol.toStringTag], TA.name, "property value"); +}); diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/this-has-no-typedarrayname-internal.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/this-has-no-typedarrayname-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..6c6567b824498c7f9cd5aa815a8ccb17e227f9b5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/this-has-no-typedarrayname-internal.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + Return undefined when `this` does not have a [[TypedArrayName]] internal slot +info: > + 22.2.3.32 get %TypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + ... + 3. If O does not have a [[TypedArrayName]] internal slot, return undefined. + ... +includes: [testTypedArray.js] +features: [Symbol.toStringTag, DataView] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, Symbol.toStringTag +).get; + +assert.sameValue(getter.call({}), undefined); +assert.sameValue(getter.call([]), undefined); +assert.sameValue(getter.call(new ArrayBuffer(8)), undefined); + +var ab = new ArrayBuffer(8); +var dv = new DataView(ab, 0, 1); +assert.sameValue(getter.call(dv), undefined); diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/this-is-not-object.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..99a95d608b6a8138a7e8cd3ad36dcf410705be75 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/this-is-not-object.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: Return undefined when `this` is not Object +info: > + 22.2.3.32 get %TypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + 2. If Type(O) is not Object, return undefined. + ... +includes: [testTypedArray.js] +features: [Symbol, Symbol.toStringTag] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, Symbol.toStringTag +).get; + +assert.sameValue(getter.call(undefined), undefined, "this is undefined"); +assert.sameValue(getter.call(42), undefined, "this is 42"); +assert.sameValue(getter.call("foo"), undefined, "this is a string"); +assert.sameValue(getter.call(true), undefined, "this is true"); +assert.sameValue(getter.call(false), undefined, "this is false"); +assert.sameValue(getter.call(Symbol("s")), undefined, "this is a Symbol"); +assert.sameValue(getter.call(null), undefined, "this is null"); diff --git a/test/built-ins/TypedArray/prototype/buffer/return-buffer.js b/test/built-ins/TypedArray/prototype/buffer/return-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..63e3b071394c9d91188d02558a8d020c260bcc25 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/buffer/return-buffer.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.1 +description: | + Return buffer from [[ViewedArrayBuffer]] internal slot +info: > + 22.2.3.1 get %TypedArray%.prototype.buffer + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. Return buffer. +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(TA.BYTES_PER_ELEMENT); + var ta = new TA(buffer); + + assert.sameValue(ta.buffer, buffer); +}); diff --git a/test/built-ins/TypedArray/prototype/buffer/return-dataview-buffer.js b/test/built-ins/TypedArray/prototype/buffer/return-dataview-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..05992e520efa85a6406043fcfafcc7b9c03bfb8b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/buffer/return-dataview-buffer.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.1 +description: | + Return buffer from DataView's instance [[ViewedArrayBuffer]] internal slot +info: > + 22.2.3.1 get %TypedArray%.prototype.buffer + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. Return buffer. +includes: [testTypedArray.js] +features: [DataView] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + TypedArray.prototype, "buffer" +).get; + +var buffer = new ArrayBuffer(8); +var dv = new DataView(buffer, 0); + +assert.sameValue(getter.call(dv), buffer); diff --git a/test/built-ins/TypedArray/prototype/buffer/this-has-no-viewedarraybuffer-internal.js b/test/built-ins/TypedArray/prototype/buffer/this-has-no-viewedarraybuffer-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..8939cad810b2db2260f90fdf20853814a7ab0017 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/buffer/this-has-no-viewedarraybuffer-internal.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: 22.2.3.1 +description: | + Throws a TypeError exception when `this` does not have a [[ViewedArrayBuffer]] + internal slot +info: > + 22.2.3.1 get %TypedArray%.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, "buffer" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}); diff --git a/test/built-ins/TypedArray/prototype/buffer/this-is-not-object.js b/test/built-ins/TypedArray/prototype/buffer/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..b0cdaf828aa0d4704bba6e1624466b84f8abd7ce --- /dev/null +++ b/test/built-ins/TypedArray/prototype/buffer/this-is-not-object.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.1 +description: Throws a TypeError exception when `this` is not Object +info: > + 22.2.3.1 get %TypedArray%.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, "buffer" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/byteLength/return-bytelength.js b/test/built-ins/TypedArray/prototype/byteLength/return-bytelength.js new file mode 100644 index 0000000000000000000000000000000000000000..45ac33ac41ccfe14f14fd4bfd03a9ba96334f0f1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteLength/return-bytelength.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.2 +description: | + Return value from [[ByteLength]] internal slot +info: > + 22.2.3.2 get %TypedArray%.prototype.byteLength + + ... + 6. Let size be the value of O's [[ByteLength]] internal slot. + 7. Return size. +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bytesPerElement = TA.BYTES_PER_ELEMENT; + var ta1 = new TA(); + assert.sameValue(ta1.byteLength, 0); + + var ta2 = new TA(42); + assert.sameValue(ta2.byteLength, 42 * bytesPerElement); +}); diff --git a/test/built-ins/TypedArray/prototype/byteLength/return-dataview-bytelength.js b/test/built-ins/TypedArray/prototype/byteLength/return-dataview-bytelength.js new file mode 100644 index 0000000000000000000000000000000000000000..8f1930d0d005dcbf9b170b06281ad9c49aad0d0a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteLength/return-dataview-bytelength.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.2 +description: | + Return buffer from DataView's instance [[ViewedArrayBuffer]] internal slot +info: > + 22.2.3.2 get %TypedArray%.prototype.byteLength + + ... + 6. Let size be the value of O's [[ByteLength]] internal slot. + 7. Return size. +includes: [testTypedArray.js] +features: [DataView] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + TypedArray.prototype, "byteLength" +).get; + +var buffer = new ArrayBuffer(64); +var dv = new DataView(buffer, 0); + +assert.sameValue(getter.call(dv), 64); diff --git a/test/built-ins/TypedArray/prototype/byteLength/this-has-no-viewedarraybuffer-internal.js b/test/built-ins/TypedArray/prototype/byteLength/this-has-no-viewedarraybuffer-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..935c86c03d540790fc6baa3a8ee61efc7b443cad --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteLength/this-has-no-viewedarraybuffer-internal.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: 22.2.3.2 +description: | + Throws a TypeError exception when `this` does not have a [[ViewedArrayBuffer]] + internal slot +info: > + 22.2.3.2 get %TypedArray%.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}); diff --git a/test/built-ins/TypedArray/prototype/byteLength/this-is-not-object.js b/test/built-ins/TypedArray/prototype/byteLength/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..8dd7a61798bcd644b73fb5ec5773dbf699975767 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteLength/this-is-not-object.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.2 +description: Throws a TypeError exception when `this` is not Object +info: > + 22.2.3.2 get %TypedArray%.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/byteOffset/return-byteoffset.js b/test/built-ins/TypedArray/prototype/byteOffset/return-byteoffset.js new file mode 100644 index 0000000000000000000000000000000000000000..51570aa23a08cda1960ee348860a2e89403e987b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteOffset/return-byteoffset.js @@ -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: 22.2.3.3 +description: | + Return value from [[ByteOffset]] internal slot +info: > + 22.2.3.3 get %TypedArray%.prototype.byteOffset + + ... + 6. Let offset be the value of O's [[ByteOffset]] internal slot. + 7. Return size. +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.byteOffset, 0, "Regular typedArray"); + + var offset = 4 * TA.BYTES_PER_ELEMENT; + + var buffer1 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT); + var ta2 = new TA(buffer1, offset); + assert.sameValue(ta2.byteOffset, offset, "TA(buffer, offset)"); + + var buffer2 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT); + var sample = new TA(buffer2, offset) + var ta3 = new TA(sample); + assert.sameValue(ta3.byteOffset, 0, "TA(typedArray)"); +}); diff --git a/test/built-ins/TypedArray/prototype/byteOffset/return-dataview-byteoffset.js b/test/built-ins/TypedArray/prototype/byteOffset/return-dataview-byteoffset.js new file mode 100644 index 0000000000000000000000000000000000000000..916514a5c5a4763032f67f5c9dda408fe3f6ff3a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteOffset/return-dataview-byteoffset.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.2 +description: | + Return buffer from DataView's instance [[ViewedArrayBuffer]] internal slot +info: > + 22.2.3.2 get %TypedArray%.prototype.byteOffset + + ... + 6. Let offset be the value of O's [[ByteOffset]] internal slot. + 7. Return size. +includes: [testTypedArray.js] +features: [DataView] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + TypedArray.prototype, "byteOffset" +).get; + +var buffer = new ArrayBuffer(64); + +var dv1 = new DataView(buffer, 0); +assert.sameValue(getter.call(dv1), 0); + +var dv2 = new DataView(buffer, 32); +assert.sameValue(getter.call(dv2), 32); diff --git a/test/built-ins/TypedArray/prototype/byteOffset/this-has-no-viewedarraybuffer-internal.js b/test/built-ins/TypedArray/prototype/byteOffset/this-has-no-viewedarraybuffer-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..a444fdbf147ccdf8811c50bff1266bb5b77f9e81 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteOffset/this-has-no-viewedarraybuffer-internal.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: 22.2.3.3 +description: | + Throws a TypeError exception when `this` does not have a [[ViewedArrayBuffer]] + internal slot +info: > + 22.2.3.3 get %TypedArray%.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, "byteOffset" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}); diff --git a/test/built-ins/TypedArray/prototype/byteOffset/this-is-not-object.js b/test/built-ins/TypedArray/prototype/byteOffset/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..244072f9faf63e757eab197d718594d56e72e3b8 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteOffset/this-is-not-object.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.3 +description: Throws a TypeError exception when `this` is not Object +info: > + 22.2.3.3 get %TypedArray%.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, "byteOffset" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/length/return-length.js b/test/built-ins/TypedArray/prototype/length/return-length.js new file mode 100644 index 0000000000000000000000000000000000000000..61e3f9dfcbd6969a8865f4701b0750f956496f9e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/return-length.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype.length +description: | + Return value from the [[ArrayLength]] internal slot +info: > + 22.2.3.18 get %TypedArray%.prototype.length + + ... + 6. Let length be the value of O's [[ArrayLength]] internal slot. + 7. Return length. + + --- + + The current tests on `prop-desc.js` and `length.js` already assert `length` is + not a dynamic property as in regular arrays. +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.length, 0); + + var ta2 = new TA(42); + assert.sameValue(ta2.length, 42); +}); diff --git a/test/built-ins/TypedArray/prototype/length/this-has-no-typedarrayname-internal.js b/test/built-ins/TypedArray/prototype/length/this-has-no-typedarrayname-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..94db7aa5791dd21bf262e5dd976744937e06ba24 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/this-has-no-typedarrayname-internal.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype.length +description: | + Throws a TypeError exception when `this` does not have a [[TypedArrayName]] + internal slot +info: > + 22.2.3.18 get %TypedArray%.prototype.length + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [DataView] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, "length" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}); + +var dv = new DataView(new ArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/built-ins/TypedArray/prototype/length/this-is-not-object-strict-mode.js b/test/built-ins/TypedArray/prototype/length/this-is-not-object-strict-mode.js new file mode 100644 index 0000000000000000000000000000000000000000..d22f4d5ad70a56505227e19d64a265b905845dff --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/this-is-not-object-strict-mode.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype.length +description: Throws a TypeError exception when `this` is null or undefined +info: > + 22.2.3.18 get %TypedArray%.prototype.length + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +flags: [onlyStrict] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, "length" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}); + +assert.throws(TypeError, function() { + getter.call(null); +}); diff --git a/test/built-ins/TypedArray/prototype/length/this-is-not-object.js b/test/built-ins/TypedArray/prototype/length/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..77685b43a1e712638553ec9c4d8b6227b5e2c679 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/this-is-not-object.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype.length +description: Throws a TypeError exception when `this` is not Object +info: > + 22.2.3.18 get %TypedArray%.prototype.length + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, "length" +).get; + +assert.throws(TypeError, function() { + getter.call(42); +}); + +assert.throws(TypeError, function() { + getter.call("1"); +}); + +assert.throws(TypeError, function() { + getter.call(true); +}); + +assert.throws(TypeError, function() { + getter.call(false); +}); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +});