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_ciextern macro ProxiesCodeStubAssembler::AllocateProxyRevokeFunction(
101cb0ef41Sopenharmony_ci    implicit context: Context)(JSProxy): JSFunction;
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci// Proxy.revocable(target, handler)
131cb0ef41Sopenharmony_ci// https://tc39.github.io/ecma262/#sec-proxy.revocable
141cb0ef41Sopenharmony_citransitioning javascript builtin
151cb0ef41Sopenharmony_ciProxyRevocable(js-implicit context: NativeContext)(
161cb0ef41Sopenharmony_ci    target: JSAny, handler: JSAny): JSProxyRevocableResult {
171cb0ef41Sopenharmony_ci  try {
181cb0ef41Sopenharmony_ci    // 1. Let p be ? ProxyCreate(target, handler).
191cb0ef41Sopenharmony_ci    const targetJSReceiver =
201cb0ef41Sopenharmony_ci        Cast<JSReceiver>(target) otherwise ThrowProxyNonObject;
211cb0ef41Sopenharmony_ci    const handlerJSReceiver =
221cb0ef41Sopenharmony_ci        Cast<JSReceiver>(handler) otherwise ThrowProxyNonObject;
231cb0ef41Sopenharmony_ci    const proxy: JSProxy = AllocateProxy(targetJSReceiver, handlerJSReceiver);
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci    // 2. Let steps be the algorithm steps defined in Proxy Revocation
261cb0ef41Sopenharmony_ci    // Functions.
271cb0ef41Sopenharmony_ci    // 3. Let revoker be CreateBuiltinFunction(steps, « [[RevocableProxy]] »).
281cb0ef41Sopenharmony_ci    // 4. Set revoker.[[RevocableProxy]] to p.
291cb0ef41Sopenharmony_ci    const revoke: JSFunction = AllocateProxyRevokeFunction(proxy);
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci    // 5. Let result be ObjectCreate(%ObjectPrototype%).
321cb0ef41Sopenharmony_ci    // 6. Perform CreateDataProperty(result, "proxy", p).
331cb0ef41Sopenharmony_ci    // 7. Perform CreateDataProperty(result, "revoke", revoker).
341cb0ef41Sopenharmony_ci    // 8. Return result.
351cb0ef41Sopenharmony_ci    return NewJSProxyRevocableResult(proxy, revoke);
361cb0ef41Sopenharmony_ci  } label ThrowProxyNonObject deferred {
371cb0ef41Sopenharmony_ci    ThrowTypeError(MessageTemplate::kProxyNonObject, 'Proxy.revocable');
381cb0ef41Sopenharmony_ci  }
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci}
41