proxy-get-property.tq 2.37 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 10
extern transitioning builtin GetPropertyWithReceiver(implicit context: Context)(
    JSAny, Name, JSAny, Smi): JSAny;
11

12 13 14 15 16 17 18 19 20
// 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)(
    proxy: JSProxy, name: PropertyKey, receiverValue: JSAny,
    onNonExistent: Smi): JSAny {
  PerformStackCheck();
  // 1. Assert: IsPropertyKey(P) is true.
  assert(TaggedIsNotSmi(name));
21
  assert(Is<Name>(name));
22
  assert(!IsPrivateSymbol(name));
23

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

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

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

47 48
  // 8. Let trapResult be ? Call(trap, handler, « target, P, Receiver »).
  const trapResult = Call(context, trap, handler, target, name, receiverValue);
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63
  // 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.
  CheckGetSetTrapResult(target, proxy, name, trapResult, kProxyGet);
  return trapResult;
}
64
}