proxy-has-property.tq 2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include 'src/builtins/builtins-proxy-gen.h'

namespace proxy {

  // ES #sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p
  // https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p
  transitioning builtin ProxyHasProperty(implicit context: Context)(
12
      proxy: JSProxy, name: PropertyKey): JSAny {
13 14 15 16 17 18 19 20 21 22 23 24
    assert(IsJSProxy(proxy));

    PerformStackCheck();

    // 1. Assert: IsPropertyKey(P) is true.
    assert(IsName(name));
    assert(!IsPrivateSymbol(name));

    try {
      // 2. Let handler be O.[[ProxyHandler]].
      // 3. If handler is null, throw a TypeError exception.
      // 4. Assert: Type(handler) is Object.
25
      assert(proxy.handler == Null || Is<JSReceiver>(proxy.handler));
26 27 28 29
      const handler =
          Cast<JSReceiver>(proxy.handler) otherwise ThrowProxyHandlerRevoked;

      // 5. Let target be O.[[ProxyTarget]].
30
      const target = Cast<JSReceiver>(proxy.target) otherwise unreachable;
31 32 33 34 35 36 37 38 39 40 41 42

      // 6. Let trap be ? GetMethod(handler, "has").
      // 7. If trap is undefined, then (see 7.a below).
      const trap: Callable = GetMethod(handler, 'has')
          otherwise goto TrapUndefined(target);

      // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, «
      // target»)).
      // 9. If booleanTrapResult is false, then (see 9.a. in
      // CheckHasTrapResult).
      // 10. Return booleanTrapResult.
      const trapResult = Call(context, trap, handler, target, name);
43
      if (ToBoolean(trapResult)) {
44 45
        return True;
      }
46 47
      CheckHasTrapResult(target, proxy, name);
      return False;
48
    }
49
    label TrapUndefined(target: JSAny) {
50 51 52 53
      // 7.a. Return ? target.[[HasProperty]](P).
      tail HasProperty(target, name);
    }
    label ThrowProxyHandlerRevoked deferred {
54
      ThrowTypeError(MessageTemplate::kProxyRevoked, 'has');
55 56 57
    }
  }
}