test262-automation e9a5a7f918 [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time) (#1620)
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
2018-07-03 15:59:58 -04:00

67 lines
2.7 KiB
JavaScript

//@ skip
function shouldBe(actual, expected)
{
if (actual !== expected)
throw new Error(`bad value: ${String(actual)}`);
}
function shouldThrow(func, errorMessage)
{
var errorThrown = false;
var error = null;
try {
func();
} catch (e) {
errorThrown = true;
error = e;
}
if (!errorThrown)
throw new Error('not thrown');
if (String(error) !== errorMessage)
throw new Error(`bad error: ${String(error)}`);
}
{
let arrayBuffer = new ArrayBuffer(42);
let sharedArrayBuffer = new SharedArrayBuffer(500);
shouldBe(arrayBuffer.byteLength, 42);
shouldBe(sharedArrayBuffer.byteLength, 500);
shouldBe(ArrayBuffer.prototype.hasOwnProperty('byteLength'), true);
shouldBe(SharedArrayBuffer.prototype.hasOwnProperty('byteLength'), true);
shouldBe(arrayBuffer.hasOwnProperty('byteLength'), false);
shouldBe(sharedArrayBuffer.hasOwnProperty('byteLength'), false);
shouldBe(!!Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get, true);
shouldBe(!!Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get, true);
shouldBe(!!Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').set, false);
shouldBe(!!Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').set, false);
shouldBe(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get !== Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get, true);
shouldThrow(() => {
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get.call(sharedArrayBuffer);
}, `TypeError: Receiver should not be a shared array buffer`);
shouldThrow(() => {
Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get.call(arrayBuffer);
}, `TypeError: Receiver should be a shared array buffer`);
for (let value of [ 0, true, "Cocoa", null, undefined, Symbol("Cappuccino") ]) {
shouldThrow(() => {
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get.call(value);
}, `TypeError: Receiver should be an array buffer but was not an object`);
shouldThrow(() => {
Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get.call(value);
}, `TypeError: Receiver should be an array buffer but was not an object`);
}
shouldThrow(() => {
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get.call({});
}, `TypeError: Receiver should be an array buffer`);
shouldThrow(() => {
Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get.call({});
}, `TypeError: Receiver should be an array buffer`);
}