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-isextensible 10// https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-isextensible 11transitioning builtin ProxyIsExtensible(implicit context: Context)( 12 proxy: JSProxy): JSAny { 13 PerformStackCheck(); 14 const kTrapName: constexpr string = 'isExtensible'; 15 try { 16 // 1. Let handler be O.[[ProxyHandler]]. 17 // 2. If handler is null, throw a TypeError exception. 18 // 3. Assert: Type(handler) is Object. 19 assert(proxy.handler == Null || Is<JSReceiver>(proxy.handler)); 20 const handler = 21 Cast<JSReceiver>(proxy.handler) otherwise ThrowProxyHandlerRevoked; 22 23 // 4. Let target be O.[[ProxyTarget]]. 24 const target = proxy.target; 25 26 // 5. Let trap be ? GetMethod(handler, "isExtensible"). 27 // 6. If trap is undefined, then (see 6.a below). 28 const trap: Callable = GetMethod(handler, kTrapName) 29 otherwise goto TrapUndefined(target); 30 31 // 7. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « 32 // target»)). 33 const trapResult = ToBoolean(Call(context, trap, handler, target)); 34 35 // 8. Let targetResult be ? IsExtensible(target). 36 const targetResult: bool = 37 ToBoolean(object::ObjectIsExtensibleImpl(target)); 38 39 // 9. If SameValue(booleanTrapResult, targetResult) is false, throw a 40 // TypeError exception. 41 if (trapResult != targetResult) { 42 ThrowTypeError( 43 MessageTemplate::kProxyIsExtensibleInconsistent, 44 SelectBooleanConstant(targetResult)); 45 } 46 // 10. Return booleanTrapResult. 47 return SelectBooleanConstant(trapResult); 48 } label TrapUndefined(target: JSAny) { 49 // 6.a. Return ? IsExtensible(target). 50 return object::ObjectIsExtensibleImpl(target); 51 } label ThrowProxyHandlerRevoked deferred { 52 ThrowTypeError(MessageTemplate::kProxyRevoked, kTrapName); 53 } 54} 55} 56