proxy-get-property.tq 2.47 KB
Newer Older
1 2 3 4 5 6 7 8
// 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 {

9
  extern transitioning builtin GetPropertyWithReceiver(
10
      implicit context: Context)(JSAny, Name, JSAny, Smi): JSAny;
11 12 13 14 15

  // ES #sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver
  // https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver
  transitioning builtin
  ProxyGetProperty(implicit context: Context)(
16 17
      proxy: JSProxy, name: PropertyKey, receiverValue: JSAny,
      onNonExistent: Smi): JSAny {
18
    PerformStackCheck();
19 20 21 22 23 24 25 26
    // 1. Assert: IsPropertyKey(P) is true.
    assert(TaggedIsNotSmi(name));
    assert(IsName(name));
    assert(!IsPrivateSymbol(name));

    // 2. Let handler be O.[[ProxyHandler]].
    // 3. If handler is null, throw a TypeError exception.
    // 4. Assert: Type(handler) is Object.
27 28 29
    let handler: JSReceiver;
    typeswitch (proxy.handler) {
      case (Null): {
30
        ThrowTypeError(MessageTemplate::kProxyRevoked, 'get');
31 32 33 34 35
      }
      case (h: JSReceiver): {
        handler = h;
      }
    }
36 37

    // 5. Let target be O.[[ProxyTarget]].
38
    const target = Cast<JSReceiver>(proxy.target) otherwise unreachable;
39 40 41 42

    // 6. Let trap be ? GetMethod(handler, "get").
    // 7. If trap is undefined, then (see 7.a below).
    // 7.a. Return ? target.[[Get]](P, Receiver).
43
    const trap: Callable = GetMethod(handler, 'get')
44 45 46 47 48
        otherwise return GetPropertyWithReceiver(
        target, name, receiverValue, onNonExistent);

    // 8. Let trapResult be ? Call(trap, handler, « target, P, Receiver »).
    const trapResult =
49
        Call(context, trap, handler, target, name, receiverValue);
50 51 52 53 54 55 56 57 58 59 60 61

    // 9. Let targetDesc be ? target.[[GetOwnProperty]](P).
    // 10. If targetDesc is not undefined and targetDesc.[[Configurable]] is
    // false, then
    //    a. If IsDataDescriptor(targetDesc) is true and targetDesc.[[Writable]]
    //    is false, then
    //      i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a
    //      TypeError exception.
    //    b. If IsAccessorDescriptor(targetDesc) is true and targetDesc.[[Get]]
    //    is undefined, then
    //      i. If trapResult is not undefined, throw a TypeError exception.
    // 11. Return trapResult.
62 63
    CheckGetSetTrapResult(target, proxy, name, trapResult, kProxyGet);
    return trapResult;
64 65
  }
}