summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/SharedArrayBuffer/newtarget-prototype-is-not-object.js
blob: 2bbe5956693d86d3ad71b32954540a7275061ea5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Foundation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-sharedarraybuffer-length
description: >
  [[Prototype]] defaults to %SharedArrayBufferPrototype% if NewTarget.prototype is not an object.
info: |
  SharedArrayBuffer( length )

  SharedArrayBuffer called with argument length performs the following steps:

  ...
  3. Return AllocateSharedArrayBuffer(NewTarget, byteLength).

  AllocateSharedArrayBuffer( constructor, byteLength )
    1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%SharedArrayBufferPrototype%",
       «[[ArrayBufferData]], [[ArrayBufferByteLength]]» ).
    ...
features: [SharedArrayBuffer, Symbol, Reflect.construct]
---*/

function newTarget() {}

newTarget.prototype = undefined;
var arrayBuffer = Reflect.construct(SharedArrayBuffer, [1], newTarget);
assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is undefined");

newTarget.prototype = null;
var arrayBuffer = Reflect.construct(SharedArrayBuffer, [2], newTarget);
assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is null");

newTarget.prototype = true;
var arrayBuffer = Reflect.construct(SharedArrayBuffer, [3], newTarget);
assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is a Boolean");

newTarget.prototype = "";
var arrayBuffer = Reflect.construct(SharedArrayBuffer, [4], newTarget);
assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is a String");

newTarget.prototype = Symbol();
var arrayBuffer = Reflect.construct(SharedArrayBuffer, [5], newTarget);
assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is a Symbol");

newTarget.prototype = 1;
var arrayBuffer = Reflect.construct(SharedArrayBuffer, [6], newTarget);
assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is a Number");

reportCompare(0, 0);