Welcome to mirror list, hosted at ThFree Co, Russian Federation.

proxy-revocable.tq « builtins « src « v8 « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2b853afefea61878a1b27c21e917afd8f7aab840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include 'src/builtins/builtins-proxy-gen.h'

namespace proxy {

  extern macro ProxiesCodeStubAssembler::AllocateProxyRevokeFunction(
      implicit context: Context)(JSProxy): JSFunction;

  // Proxy.revocable(target, handler)
  // https://tc39.github.io/ecma262/#sec-proxy.revocable
  transitioning javascript builtin
  ProxyRevocable(js-implicit context: NativeContext)(
      target: JSAny, handler: JSAny): JSProxyRevocableResult {
    try {
      const targetJSReceiver =
          Cast<JSReceiver>(target) otherwise ThrowProxyNonObject;
      if (IsRevokedProxy(targetJSReceiver)) {
        goto ThrowProxyHandlerOrTargetRevoked;
      }

      const handlerJSReceiver =
          Cast<JSReceiver>(handler) otherwise ThrowProxyNonObject;
      if (IsRevokedProxy(handlerJSReceiver)) {
        goto ThrowProxyHandlerOrTargetRevoked;
      }

      // 1. Let p be ? ProxyCreate(target, handler).
      const proxy: JSProxy = AllocateProxy(targetJSReceiver, handlerJSReceiver);

      // 2. Let steps be the algorithm steps defined in Proxy Revocation
      // Functions.
      // 3. Let revoker be CreateBuiltinFunction(steps, « [[RevocableProxy]] »).
      // 4. Set revoker.[[RevocableProxy]] to p.
      const revoke: JSFunction = AllocateProxyRevokeFunction(proxy);

      // 5. Let result be ObjectCreate(%ObjectPrototype%).
      // 6. Perform CreateDataProperty(result, "proxy", p).
      // 7. Perform CreateDataProperty(result, "revoke", revoker).
      // 8. Return result.
      return NewJSProxyRevocableResult(proxy, revoke);
    }
    label ThrowProxyNonObject deferred {
      ThrowTypeError(MessageTemplate::kProxyNonObject, 'Proxy.revocable');
    }
    label ThrowProxyHandlerOrTargetRevoked deferred {
      ThrowTypeError(
          MessageTemplate::kProxyHandlerOrTargetRevoked, 'Proxy.revocable');
    }
  }
}