11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include 'src/builtins/builtins-proxy-gen.h'
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cinamespace proxy {
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci// ES #sec-proxy-object-internal-methods-and-internal-slots-delete-p
101cb0ef41Sopenharmony_ci// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-delete-p
111cb0ef41Sopenharmony_citransitioning builtin
121cb0ef41Sopenharmony_ciProxyDeleteProperty(implicit context: Context)(
131cb0ef41Sopenharmony_ci    proxy: JSProxy, name: PropertyKey, languageMode: LanguageModeSmi): JSAny {
141cb0ef41Sopenharmony_ci  const kTrapName: constexpr string = 'deleteProperty';
151cb0ef41Sopenharmony_ci  // Handle deeply nested proxy.
161cb0ef41Sopenharmony_ci  PerformStackCheck();
171cb0ef41Sopenharmony_ci  // 1. Assert: IsPropertyKey(P) is true.
181cb0ef41Sopenharmony_ci  dcheck(TaggedIsNotSmi(name));
191cb0ef41Sopenharmony_ci  dcheck(Is<Name>(name));
201cb0ef41Sopenharmony_ci  dcheck(!IsPrivateSymbol(name));
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  try {
231cb0ef41Sopenharmony_ci    // 2. Let handler be O.[[ProxyHandler]].
241cb0ef41Sopenharmony_ci    // 3. If handler is null, throw a TypeError exception.
251cb0ef41Sopenharmony_ci    // 4. Assert: Type(handler) is Object.
261cb0ef41Sopenharmony_ci    dcheck(proxy.handler == Null || Is<JSReceiver>(proxy.handler));
271cb0ef41Sopenharmony_ci    const handler =
281cb0ef41Sopenharmony_ci        Cast<JSReceiver>(proxy.handler) otherwise ThrowProxyHandlerRevoked;
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci    // 5. Let target be O.[[ProxyTarget]].
311cb0ef41Sopenharmony_ci    const target = UnsafeCast<JSReceiver>(proxy.target);
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci    // 6. Let trap be ? GetMethod(handler, "deleteProperty").
341cb0ef41Sopenharmony_ci    // 7. If trap is undefined, then (see 7.a below).
351cb0ef41Sopenharmony_ci    const trap: Callable = GetMethod(handler, kTrapName)
361cb0ef41Sopenharmony_ci        otherwise goto TrapUndefined(target);
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci    // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler,
391cb0ef41Sopenharmony_ci    // « target, P »)).
401cb0ef41Sopenharmony_ci    const trapResult = Call(context, trap, handler, target, name);
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci    // 9. If booleanTrapResult is false, return false.
431cb0ef41Sopenharmony_ci    if (!ToBoolean(trapResult)) {
441cb0ef41Sopenharmony_ci      const strictValue: LanguageModeSmi = LanguageMode::kStrict;
451cb0ef41Sopenharmony_ci      if (languageMode == strictValue) {
461cb0ef41Sopenharmony_ci        ThrowTypeError(
471cb0ef41Sopenharmony_ci            MessageTemplate::kProxyTrapReturnedFalsishFor, kTrapName, name);
481cb0ef41Sopenharmony_ci      }
491cb0ef41Sopenharmony_ci      return False;
501cb0ef41Sopenharmony_ci    }
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci    // 10. Let targetDesc be ? target.[[GetOwnProperty]](P).
531cb0ef41Sopenharmony_ci    // 11. If targetDesc is undefined, return true.
541cb0ef41Sopenharmony_ci    // 12. If targetDesc.[[Configurable]] is false, throw a TypeError
551cb0ef41Sopenharmony_ci    // exception.
561cb0ef41Sopenharmony_ci    // 13. Let extensibleTarget be ? IsExtensible(target).
571cb0ef41Sopenharmony_ci    // 14. If extensibleTarget is false, throw a TypeError exception.
581cb0ef41Sopenharmony_ci    CheckDeleteTrapResult(target, proxy, name);
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci    // 15. Return true.
611cb0ef41Sopenharmony_ci    return True;
621cb0ef41Sopenharmony_ci  } label TrapUndefined(target: JSAny) {
631cb0ef41Sopenharmony_ci    // 7.a. Return ? target.[[Delete]](P).
641cb0ef41Sopenharmony_ci    return DeleteProperty(target, name, languageMode);
651cb0ef41Sopenharmony_ci  } label ThrowProxyHandlerRevoked deferred {
661cb0ef41Sopenharmony_ci    ThrowTypeError(MessageTemplate::kProxyRevoked, kTrapName);
671cb0ef41Sopenharmony_ci  }
681cb0ef41Sopenharmony_ci}
691cb0ef41Sopenharmony_ci}
70