1// Copyright 2019 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include 'src/builtins/builtins-proxy-gen.h' 6 7namespace proxy { 8 9// ES #sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p 10// https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-hasproperty-p 11transitioning builtin ProxyHasProperty(implicit context: Context)( 12 proxy: JSProxy, name: PropertyKey): JSAny { 13 assert(Is<JSProxy>(proxy)); 14 15 PerformStackCheck(); 16 17 // 1. Assert: IsPropertyKey(P) is true. 18 assert(Is<Name>(name)); 19 assert(!IsPrivateSymbol(name)); 20 21 try { 22 // 2. Let handler be O.[[ProxyHandler]]. 23 // 3. If handler is null, throw a TypeError exception. 24 // 4. Assert: Type(handler) is Object. 25 assert(proxy.handler == Null || Is<JSReceiver>(proxy.handler)); 26 const handler = 27 Cast<JSReceiver>(proxy.handler) otherwise ThrowProxyHandlerRevoked; 28 29 // 5. Let target be O.[[ProxyTarget]]. 30 const target = Cast<JSReceiver>(proxy.target) otherwise unreachable; 31 32 // 6. Let trap be ? GetMethod(handler, "has"). 33 // 7. If trap is undefined, then (see 7.a below). 34 const trap: Callable = GetMethod(handler, 'has') 35 otherwise goto TrapUndefined(target); 36 37 // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « 38 // target»)). 39 // 9. If booleanTrapResult is false, then (see 9.a. in 40 // CheckHasTrapResult). 41 // 10. Return booleanTrapResult. 42 const trapResult = Call(context, trap, handler, target, name); 43 if (ToBoolean(trapResult)) { 44 return True; 45 } 46 CheckHasTrapResult(target, proxy, name); 47 return False; 48 } label TrapUndefined(target: JSAny) { 49 // 7.a. Return ? target.[[HasProperty]](P). 50 tail HasProperty(target, name); 51 } label ThrowProxyHandlerRevoked deferred { 52 ThrowTypeError(MessageTemplate::kProxyRevoked, 'has'); 53 } 54} 55} 56