summaryrefslogtreecommitdiff
path: root/test/built-ins/TypedArrays/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js
blob: 5c788c69a657fc8876a52da0d9ea801ef90ed3eb (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
56
57
58
59
60
61
62
63
// 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-integer-indexed-exotic-objects-hasproperty-p
description: Return abrupt from OrdinaryHasProperty parent's [[HasProperty]]
info: |
  9.4.5.2 [[HasProperty]](P)

  ...
  3. If Type(P) is String, then
    a. Let numericIndex be ! CanonicalNumericIndexString(P).
    b. If numericIndex is not undefined, then
      i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
      ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  ...

  9.1.7.1 OrdinaryHasProperty (O, P)

  ...
  2. Let hasOwn be ? O.[[GetOwnProperty]](P).
  3. If hasOwn is not undefined, return true.
  4. Let parent be ? O.[[GetPrototypeOf]]().
  5. If parent is not null, then
    a. Return ? parent.[[HasProperty]](P).
  6. Return false.
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
features: [BigInt, Reflect, Proxy, TypedArray]
---*/

var handler = {
  has: function() {
    throw new Test262Error();
  }
};

var proxy = new Proxy(TypedArray.prototype, handler);

testWithBigIntTypedArrayConstructors(function(TA) {
  var sample = new TA(1);

  Object.setPrototypeOf(sample, proxy);

  assert.sameValue(
    Reflect.has(sample, 0), true,
    "OrdinaryHasProperty does not affect numericIndex properties [0]"
  );
  assert.sameValue(
    Reflect.has(sample, 1), false,
    "OrdinaryHasProperty does not affect numericIndex properties [1]"
  );

  assert.throws(Test262Error, function() {
    Reflect.has(sample, "foo");
  }, "Return abrupt from parent's [[HasProperty]] 'foo'");

  Object.defineProperty(sample, "foo", { value: 42 });

  assert.sameValue(
    Reflect.has(sample, "foo"),
    true,
    "trap is not triggered if [[GetOwnProperty]] returns a defined value"
  );
});