11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include 'src/builtins/builtins-proxy-gen.h'
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cinamespace proxy {
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci// ES #sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p
101cb0ef41Sopenharmony_ci// https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p
111cb0ef41Sopenharmony_citransitioning builtin ProxyHasProperty(implicit context: Context)(
121cb0ef41Sopenharmony_ci    proxy: JSProxy, name: PropertyKey): JSAny {
131cb0ef41Sopenharmony_ci  dcheck(Is<JSProxy>(proxy));
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  PerformStackCheck();
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci  // 1. Assert: IsPropertyKey(P) is true.
181cb0ef41Sopenharmony_ci  dcheck(Is<Name>(name));
191cb0ef41Sopenharmony_ci  dcheck(!IsPrivateSymbol(name));
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  try {
221cb0ef41Sopenharmony_ci    // 2. Let handler be O.[[ProxyHandler]].
231cb0ef41Sopenharmony_ci    // 3. If handler is null, throw a TypeError exception.
241cb0ef41Sopenharmony_ci    // 4. Assert: Type(handler) is Object.
251cb0ef41Sopenharmony_ci    dcheck(proxy.handler == Null || Is<JSReceiver>(proxy.handler));
261cb0ef41Sopenharmony_ci    const handler =
271cb0ef41Sopenharmony_ci        Cast<JSReceiver>(proxy.handler) otherwise ThrowProxyHandlerRevoked;
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci    // 5. Let target be O.[[ProxyTarget]].
301cb0ef41Sopenharmony_ci    const target = Cast<JSReceiver>(proxy.target) otherwise unreachable;
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci    // 6. Let trap be ? GetMethod(handler, "has").
331cb0ef41Sopenharmony_ci    // 7. If trap is undefined, then (see 7.a below).
341cb0ef41Sopenharmony_ci    const trap: Callable = GetMethod(handler, 'has')
351cb0ef41Sopenharmony_ci        otherwise goto TrapUndefined(target);
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci    // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, «
381cb0ef41Sopenharmony_ci    // target»)).
391cb0ef41Sopenharmony_ci    // 9. If booleanTrapResult is false, then (see 9.a. in
401cb0ef41Sopenharmony_ci    // CheckHasTrapResult).
411cb0ef41Sopenharmony_ci    // 10. Return booleanTrapResult.
421cb0ef41Sopenharmony_ci    const trapResult = Call(context, trap, handler, target, name);
431cb0ef41Sopenharmony_ci    if (ToBoolean(trapResult)) {
441cb0ef41Sopenharmony_ci      return True;
451cb0ef41Sopenharmony_ci    }
461cb0ef41Sopenharmony_ci    CheckHasTrapResult(target, proxy, name);
471cb0ef41Sopenharmony_ci    return False;
481cb0ef41Sopenharmony_ci  } label TrapUndefined(target: JSAny) {
491cb0ef41Sopenharmony_ci    // 7.a. Return ? target.[[HasProperty]](P).
501cb0ef41Sopenharmony_ci    tail HasProperty(target, name);
511cb0ef41Sopenharmony_ci  } label ThrowProxyHandlerRevoked deferred {
521cb0ef41Sopenharmony_ci    ThrowTypeError(MessageTemplate::kProxyRevoked, 'has');
531cb0ef41Sopenharmony_ci  }
541cb0ef41Sopenharmony_ci}
551cb0ef41Sopenharmony_ci}
56