• 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
9// ES #sec-proxy-object-internal-methods-and-internal-slots-delete-p
10// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-delete-p
11transitioning builtin
12ProxyDeleteProperty(implicit context: Context)(
13    proxy: JSProxy, name: PropertyKey, languageMode: LanguageModeSmi): JSAny {
14  const kTrapName: constexpr string = 'deleteProperty';
15  // Handle deeply nested proxy.
16  PerformStackCheck();
17  // 1. Assert: IsPropertyKey(P) is true.
18  dcheck(TaggedIsNotSmi(name));
19  dcheck(Is<Name>(name));
20  dcheck(!IsPrivateSymbol(name));
21
22  try {
23    // 2. Let handler be O.[[ProxyHandler]].
24    // 3. If handler is null, throw a TypeError exception.
25    // 4. Assert: Type(handler) is Object.
26    dcheck(proxy.handler == Null || Is<JSReceiver>(proxy.handler));
27    const handler =
28        Cast<JSReceiver>(proxy.handler) otherwise ThrowProxyHandlerRevoked;
29
30    // 5. Let target be O.[[ProxyTarget]].
31    const target = UnsafeCast<JSReceiver>(proxy.target);
32
33    // 6. Let trap be ? GetMethod(handler, "deleteProperty").
34    // 7. If trap is undefined, then (see 7.a below).
35    const trap: Callable = GetMethod(handler, kTrapName)
36        otherwise goto TrapUndefined(target);
37
38    // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler,
39    // « target, P »)).
40    const trapResult = Call(context, trap, handler, target, name);
41
42    // 9. If booleanTrapResult is false, return false.
43    if (!ToBoolean(trapResult)) {
44      const strictValue: LanguageModeSmi = LanguageMode::kStrict;
45      if (languageMode == strictValue) {
46        ThrowTypeError(
47            MessageTemplate::kProxyTrapReturnedFalsishFor, kTrapName, name);
48      }
49      return False;
50    }
51
52    // 10. Let targetDesc be ? target.[[GetOwnProperty]](P).
53    // 11. If targetDesc is undefined, return true.
54    // 12. If targetDesc.[[Configurable]] is false, throw a TypeError
55    // exception.
56    // 13. Let extensibleTarget be ? IsExtensible(target).
57    // 14. If extensibleTarget is false, throw a TypeError exception.
58    CheckDeleteTrapResult(target, proxy, name);
59
60    // 15. Return true.
61    return True;
62  } label TrapUndefined(target: JSAny) {
63    // 7.a. Return ? target.[[Delete]](P).
64    return DeleteProperty(target, name, languageMode);
65  } label ThrowProxyHandlerRevoked deferred {
66    ThrowTypeError(MessageTemplate::kProxyRevoked, kTrapName);
67  }
68}
69}
70