11cb0ef41Sopenharmony_ci// Copyright 2018 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#ifndef V8_OBJECTS_JS_PROXY_H_ 61cb0ef41Sopenharmony_ci#define V8_OBJECTS_JS_PROXY_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/objects/js-objects.h" 91cb0ef41Sopenharmony_ci#include "torque-generated/builtin-definitions.h" 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards): 121cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h" 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cinamespace v8 { 151cb0ef41Sopenharmony_cinamespace internal { 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/js-proxy-tq.inc" 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci// The JSProxy describes EcmaScript Harmony proxies 201cb0ef41Sopenharmony_ciclass JSProxy : public TorqueGeneratedJSProxy<JSProxy, JSReceiver> { 211cb0ef41Sopenharmony_ci public: 221cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static MaybeHandle<JSProxy> New(Isolate* isolate, 231cb0ef41Sopenharmony_ci Handle<Object>, 241cb0ef41Sopenharmony_ci Handle<Object>); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci V8_INLINE bool IsRevoked() const; 271cb0ef41Sopenharmony_ci static void Revoke(Handle<JSProxy> proxy); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci // ES6 9.5.1 301cb0ef41Sopenharmony_ci static MaybeHandle<HeapObject> GetPrototype(Handle<JSProxy> receiver); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci // ES6 9.5.2 331cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> SetPrototype( 341cb0ef41Sopenharmony_ci Isolate* isolate, Handle<JSProxy> proxy, Handle<Object> value, 351cb0ef41Sopenharmony_ci bool from_javascript, ShouldThrow should_throw); 361cb0ef41Sopenharmony_ci // ES6 9.5.3 371cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> IsExtensible(Handle<JSProxy> proxy); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci // ES6, #sec-isarray. NOT to be confused with %_IsArray. 401cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> IsArray(Handle<JSProxy> proxy); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci // ES6 9.5.4 (when passed kDontThrow) 431cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> PreventExtensions( 441cb0ef41Sopenharmony_ci Handle<JSProxy> proxy, ShouldThrow should_throw); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci // ES6 9.5.5 471cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> GetOwnPropertyDescriptor( 481cb0ef41Sopenharmony_ci Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name, 491cb0ef41Sopenharmony_ci PropertyDescriptor* desc); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci // ES6 9.5.6 521cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> DefineOwnProperty( 531cb0ef41Sopenharmony_ci Isolate* isolate, Handle<JSProxy> object, Handle<Object> key, 541cb0ef41Sopenharmony_ci PropertyDescriptor* desc, Maybe<ShouldThrow> should_throw); 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci // ES6 9.5.7 571cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> HasProperty(Isolate* isolate, 581cb0ef41Sopenharmony_ci Handle<JSProxy> proxy, 591cb0ef41Sopenharmony_ci Handle<Name> name); 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci // This function never returns false. 621cb0ef41Sopenharmony_ci // It returns either true or throws. 631cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> CheckHasTrap( 641cb0ef41Sopenharmony_ci Isolate* isolate, Handle<Name> name, Handle<JSReceiver> target); 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci // ES6 9.5.10 671cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> CheckDeleteTrap( 681cb0ef41Sopenharmony_ci Isolate* isolate, Handle<Name> name, Handle<JSReceiver> target); 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci // ES6 9.5.8 711cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static MaybeHandle<Object> GetProperty( 721cb0ef41Sopenharmony_ci Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name, 731cb0ef41Sopenharmony_ci Handle<Object> receiver, bool* was_found); 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci enum AccessKind { kGet, kSet }; 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci static MaybeHandle<Object> CheckGetSetTrapResult(Isolate* isolate, 781cb0ef41Sopenharmony_ci Handle<Name> name, 791cb0ef41Sopenharmony_ci Handle<JSReceiver> target, 801cb0ef41Sopenharmony_ci Handle<Object> trap_result, 811cb0ef41Sopenharmony_ci AccessKind access_kind); 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci // ES6 9.5.9 841cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> SetProperty( 851cb0ef41Sopenharmony_ci Handle<JSProxy> proxy, Handle<Name> name, Handle<Object> value, 861cb0ef41Sopenharmony_ci Handle<Object> receiver, Maybe<ShouldThrow> should_throw); 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ci // ES6 9.5.10 (when passed LanguageMode::kSloppy) 891cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> DeletePropertyOrElement( 901cb0ef41Sopenharmony_ci Handle<JSProxy> proxy, Handle<Name> name, LanguageMode language_mode); 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_ci // ES6 9.5.12 931cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<bool> OwnPropertyKeys( 941cb0ef41Sopenharmony_ci Isolate* isolate, Handle<JSReceiver> receiver, Handle<JSProxy> proxy, 951cb0ef41Sopenharmony_ci PropertyFilter filter, KeyAccumulator* accumulator); 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci V8_WARN_UNUSED_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes( 981cb0ef41Sopenharmony_ci LookupIterator* it); 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci // Dispatched behavior. 1011cb0ef41Sopenharmony_ci DECL_VERIFIER(JSProxy) 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ci static const int kMaxIterationLimit = 100 * 1024; 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ci // kTargetOffset aliases with the elements of JSObject. The fact that 1061cb0ef41Sopenharmony_ci // JSProxy::target is a Javascript value which cannot be confused with an 1071cb0ef41Sopenharmony_ci // elements backing store is exploited by loading from this offset from an 1081cb0ef41Sopenharmony_ci // unknown JSReceiver. 1091cb0ef41Sopenharmony_ci STATIC_ASSERT(static_cast<int>(JSObject::kElementsOffset) == 1101cb0ef41Sopenharmony_ci static_cast<int>(JSProxy::kTargetOffset)); 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ci using BodyDescriptor = 1131cb0ef41Sopenharmony_ci FixedBodyDescriptor<JSReceiver::kPropertiesOrHashOffset, kSize, kSize>; 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ci static Maybe<bool> SetPrivateSymbol(Isolate* isolate, Handle<JSProxy> proxy, 1161cb0ef41Sopenharmony_ci Handle<Symbol> private_name, 1171cb0ef41Sopenharmony_ci PropertyDescriptor* desc, 1181cb0ef41Sopenharmony_ci Maybe<ShouldThrow> should_throw); 1191cb0ef41Sopenharmony_ci 1201cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(JSProxy) 1211cb0ef41Sopenharmony_ci}; 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ci// JSProxyRevocableResult is just a JSObject with a specific initial map. 1241cb0ef41Sopenharmony_ci// This initial map adds in-object properties for "proxy" and "revoke". 1251cb0ef41Sopenharmony_ci// See https://tc39.github.io/ecma262/#sec-proxy.revocable 1261cb0ef41Sopenharmony_ciclass JSProxyRevocableResult 1271cb0ef41Sopenharmony_ci : public TorqueGeneratedJSProxyRevocableResult<JSProxyRevocableResult, 1281cb0ef41Sopenharmony_ci JSObject> { 1291cb0ef41Sopenharmony_ci public: 1301cb0ef41Sopenharmony_ci // Indices of in-object properties. 1311cb0ef41Sopenharmony_ci static const int kProxyIndex = 0; 1321cb0ef41Sopenharmony_ci static const int kRevokeIndex = 1; 1331cb0ef41Sopenharmony_ci 1341cb0ef41Sopenharmony_ci private: 1351cb0ef41Sopenharmony_ci DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxyRevocableResult); 1361cb0ef41Sopenharmony_ci}; 1371cb0ef41Sopenharmony_ci 1381cb0ef41Sopenharmony_ci} // namespace internal 1391cb0ef41Sopenharmony_ci} // namespace v8 1401cb0ef41Sopenharmony_ci 1411cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h" 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_ci#endif // V8_OBJECTS_JS_PROXY_H_ 144