• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 transitioning builtin GetPropertyWithReceiver(implicit context: Context)(
10    JSAny, Name, JSAny, Smi): JSAny;
11
12// ES #sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver
13// https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver
14transitioning builtin
15ProxyGetProperty(implicit context: Context)(
16    proxy: JSProxy, name: PropertyKey, receiverValue: JSAny,
17    onNonExistent: Smi): JSAny {
18  PerformStackCheck();
19  // 1. Assert: IsPropertyKey(P) is true.
20  assert(TaggedIsNotSmi(name));
21  assert(Is<Name>(name));
22  assert(!IsPrivateSymbol(name));
23
24  // 2. Let handler be O.[[ProxyHandler]].
25  // 3. If handler is null, throw a TypeError exception.
26  // 4. Assert: Type(handler) is Object.
27  let handler: JSReceiver;
28  typeswitch (proxy.handler) {
29    case (Null): {
30      ThrowTypeError(MessageTemplate::kProxyRevoked, 'get');
31    }
32    case (h: JSReceiver): {
33      handler = h;
34    }
35  }
36
37  // 5. Let target be O.[[ProxyTarget]].
38  const target = Cast<JSReceiver>(proxy.target) otherwise unreachable;
39
40  // 6. Let trap be ? GetMethod(handler, "get").
41  // 7. If trap is undefined, then (see 7.a below).
42  // 7.a. Return ? target.[[Get]](P, Receiver).
43  const trap: Callable = GetMethod(handler, 'get')
44      otherwise return GetPropertyWithReceiver(
45      target, name, receiverValue, onNonExistent);
46
47  // 8. Let trapResult be ? Call(trap, handler, « target, P, Receiver »).
48  const trapResult = Call(context, trap, handler, target, name, receiverValue);
49
50  // 9. Let targetDesc be ? target.[[GetOwnProperty]](P).
51  // 10. If targetDesc is not undefined and targetDesc.[[Configurable]] is
52  // false, then
53  //    a. If IsDataDescriptor(targetDesc) is true and targetDesc.[[Writable]]
54  //    is false, then
55  //      i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a
56  //      TypeError exception.
57  //    b. If IsAccessorDescriptor(targetDesc) is true and targetDesc.[[Get]]
58  //    is undefined, then
59  //      i. If trapResult is not undefined, throw a TypeError exception.
60  // 11. Return trapResult.
61  CheckGetSetTrapResult(target, proxy, name, trapResult, kProxyGet);
62  return trapResult;
63}
64}
65