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 9extern macro ProxiesCodeStubAssembler::AllocateProxyRevokeFunction( 10 implicit context: Context)(JSProxy): JSFunction; 11 12// Proxy.revocable(target, handler) 13// https://tc39.github.io/ecma262/#sec-proxy.revocable 14transitioning javascript builtin 15ProxyRevocable(js-implicit context: NativeContext)( 16 target: JSAny, handler: JSAny): JSProxyRevocableResult { 17 try { 18 // 1. Let p be ? ProxyCreate(target, handler). 19 const targetJSReceiver = 20 Cast<JSReceiver>(target) otherwise ThrowProxyNonObject; 21 const handlerJSReceiver = 22 Cast<JSReceiver>(handler) otherwise ThrowProxyNonObject; 23 const proxy: JSProxy = AllocateProxy(targetJSReceiver, handlerJSReceiver); 24 25 // 2. Let steps be the algorithm steps defined in Proxy Revocation 26 // Functions. 27 // 3. Let revoker be CreateBuiltinFunction(steps, « [[RevocableProxy]] »). 28 // 4. Set revoker.[[RevocableProxy]] to p. 29 const revoke: JSFunction = AllocateProxyRevokeFunction(proxy); 30 31 // 5. Let result be ObjectCreate(%ObjectPrototype%). 32 // 6. Perform CreateDataProperty(result, "proxy", p). 33 // 7. Perform CreateDataProperty(result, "revoke", revoker). 34 // 8. Return result. 35 return NewJSProxyRevocableResult(proxy, revoke); 36 } label ThrowProxyNonObject deferred { 37 ThrowTypeError(MessageTemplate::kProxyNonObject, 'Proxy.revocable'); 38 } 39} 40} 41