proxy-delete-property.tq 2.54 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 11 12 13 14 15 16 17
// ES #sec-proxy-object-internal-methods-and-internal-slots-delete-p
// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-delete-p
transitioning builtin
ProxyDeleteProperty(implicit context: Context)(
    proxy: JSProxy, name: PropertyKey, languageMode: LanguageModeSmi): JSAny {
  const kTrapName: constexpr string = 'deleteProperty';
  // Handle deeply nested proxy.
  PerformStackCheck();
  // 1. Assert: IsPropertyKey(P) is true.
18 19 20
  dcheck(TaggedIsNotSmi(name));
  dcheck(Is<Name>(name));
  dcheck(!IsPrivateSymbol(name));
21

22 23 24 25
  try {
    // 2. Let handler be O.[[ProxyHandler]].
    // 3. If handler is null, throw a TypeError exception.
    // 4. Assert: Type(handler) is Object.
26
    dcheck(proxy.handler == Null || Is<JSReceiver>(proxy.handler));
27 28
    const handler =
        Cast<JSReceiver>(proxy.handler) otherwise ThrowProxyHandlerRevoked;
29

30 31
    // 5. Let target be O.[[ProxyTarget]].
    const target = UnsafeCast<JSReceiver>(proxy.target);
32

33 34 35 36
    // 6. Let trap be ? GetMethod(handler, "deleteProperty").
    // 7. If trap is undefined, then (see 7.a below).
    const trap: Callable = GetMethod(handler, kTrapName)
        otherwise goto TrapUndefined(target);
37

38 39 40
    // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler,
    // « target, P »)).
    const trapResult = Call(context, trap, handler, target, name);
41

42 43 44 45 46 47
    // 9. If booleanTrapResult is false, return false.
    if (!ToBoolean(trapResult)) {
      const strictValue: LanguageModeSmi = LanguageMode::kStrict;
      if (languageMode == strictValue) {
        ThrowTypeError(
            MessageTemplate::kProxyTrapReturnedFalsishFor, kTrapName, name);
48
      }
49 50
      return False;
    }
51

52 53 54 55 56 57 58
    // 10. Let targetDesc be ? target.[[GetOwnProperty]](P).
    // 11. If targetDesc is undefined, return true.
    // 12. If targetDesc.[[Configurable]] is false, throw a TypeError
    // exception.
    // 13. Let extensibleTarget be ? IsExtensible(target).
    // 14. If extensibleTarget is false, throw a TypeError exception.
    CheckDeleteTrapResult(target, proxy, name);
59

60 61 62 63 64 65 66
    // 15. Return true.
    return True;
  } label TrapUndefined(target: JSAny) {
    // 7.a. Return ? target.[[Delete]](P).
    return DeleteProperty(target, name, languageMode);
  } label ThrowProxyHandlerRevoked deferred {
    ThrowTypeError(MessageTemplate::kProxyRevoked, kTrapName);
67 68
  }
}
69
}