summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/TypedArray/prototype-constructor-identity.js
blob: 10324f5720001e42354f02044ceb4aca3111628e (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
52
53
54
55
/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

var gTestfile = 'prototype-constructor-identity.js';
//-----------------------------------------------------------------------------
var BUGNUMBER = 896116;
var summary =
  "Typed array prototypes/constructors should be largely empty, inheriting "
  "most functionality from %TypedArray% and %TypedArray%.prototype";

print(BUGNUMBER + ": " + summary);

/**************
 * BEGIN TEST *
 **************/

var TypedArray = Object.getPrototypeOf(Int8Array);

assertEq(TypedArray !== Function.prototype, true,
         "%TypedArray% should be in constructors' [[Prototype]] chains");
assertEq(Object.getPrototypeOf(TypedArray), Function.prototype,
         "%TypedArray%.prototype should inherit from Function.prototype");

assertEq(TypedArray.prototype.constructor, TypedArray,
         "bad %TypedArray%.prototype.constructor");

// Check a few different functions we implement are here, as a sanity check.
var typedArrayProps = Object.getOwnPropertyNames(TypedArray.prototype);
assertEq(typedArrayProps.indexOf("copyWithin") >= 0, true);
assertEq(typedArrayProps.indexOf("subarray") >= 0, true);
assertEq(typedArrayProps.indexOf("set") >= 0, true);

anyTypedArrayConstructors.forEach(function(ctor) {
  assertEq(Object.getPrototypeOf(ctor), TypedArray);

  var proto = ctor.prototype;

  // Inherited functions aren't present.
  var props = Object.getOwnPropertyNames(proto).sort();
  assertEq(props[0], "BYTES_PER_ELEMENT");
  assertEq(props[1], "constructor");
  assertEq(props.length, 2);

  // The inheritance chain should be set up properly.
  assertEq(Object.getPrototypeOf(proto), TypedArray.prototype,
           "prototype should inherit from %TypedArray%.prototype");
});

/******************************************************************************/

reportCompare(true, true);

print("Tests complete");