// Copyright 2018 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. #ifndef V8_OBJECTS_JS_PROXY_H_ #define V8_OBJECTS_JS_PROXY_H_ #include "src/objects/js-objects.h" #include "torque-generated/builtin-definitions.h" // Has to be the last include (doesn't have include guards): #include "src/objects/object-macros.h" namespace v8 { namespace internal { #include "torque-generated/src/objects/js-proxy-tq.inc" // The JSProxy describes EcmaScript Harmony proxies class JSProxy : public TorqueGeneratedJSProxy { public: V8_WARN_UNUSED_RESULT static MaybeHandle New(Isolate* isolate, Handle, Handle); static MaybeHandle GetFunctionRealm(Handle proxy); V8_INLINE bool IsRevoked() const; static void Revoke(Handle proxy); // ES6 9.5.1 static MaybeHandle GetPrototype(Handle receiver); // ES6 9.5.2 V8_WARN_UNUSED_RESULT static Maybe SetPrototype( Handle proxy, Handle value, bool from_javascript, ShouldThrow should_throw); // ES6 9.5.3 V8_WARN_UNUSED_RESULT static Maybe IsExtensible(Handle proxy); // ES6, #sec-isarray. NOT to be confused with %_IsArray. V8_WARN_UNUSED_RESULT static Maybe IsArray(Handle proxy); // ES6 9.5.4 (when passed kDontThrow) V8_WARN_UNUSED_RESULT static Maybe PreventExtensions( Handle proxy, ShouldThrow should_throw); // ES6 9.5.5 V8_WARN_UNUSED_RESULT static Maybe GetOwnPropertyDescriptor( Isolate* isolate, Handle proxy, Handle name, PropertyDescriptor* desc); // ES6 9.5.6 V8_WARN_UNUSED_RESULT static Maybe DefineOwnProperty( Isolate* isolate, Handle object, Handle key, PropertyDescriptor* desc, Maybe should_throw); // ES6 9.5.7 V8_WARN_UNUSED_RESULT static Maybe HasProperty(Isolate* isolate, Handle proxy, Handle name); // This function never returns false. // It returns either true or throws. V8_WARN_UNUSED_RESULT static Maybe CheckHasTrap( Isolate* isolate, Handle name, Handle target); // ES6 9.5.10 V8_WARN_UNUSED_RESULT static Maybe CheckDeleteTrap( Isolate* isolate, Handle name, Handle target); // ES6 9.5.8 V8_WARN_UNUSED_RESULT static MaybeHandle GetProperty( Isolate* isolate, Handle proxy, Handle name, Handle receiver, bool* was_found); enum AccessKind { kGet, kSet }; static MaybeHandle CheckGetSetTrapResult(Isolate* isolate, Handle name, Handle target, Handle trap_result, AccessKind access_kind); // ES6 9.5.9 V8_WARN_UNUSED_RESULT static Maybe SetProperty( Handle proxy, Handle name, Handle value, Handle receiver, Maybe should_throw); // ES6 9.5.10 (when passed LanguageMode::kSloppy) V8_WARN_UNUSED_RESULT static Maybe DeletePropertyOrElement( Handle proxy, Handle name, LanguageMode language_mode); // ES6 9.5.12 V8_WARN_UNUSED_RESULT static Maybe OwnPropertyKeys( Isolate* isolate, Handle receiver, Handle proxy, PropertyFilter filter, KeyAccumulator* accumulator); V8_WARN_UNUSED_RESULT static Maybe GetPropertyAttributes( LookupIterator* it); // Dispatched behavior. DECL_PRINTER(JSProxy) DECL_VERIFIER(JSProxy) static const int kMaxIterationLimit = 100 * 1024; // kTargetOffset aliases with the elements of JSObject. The fact that // JSProxy::target is a Javascript value which cannot be confused with an // elements backing store is exploited by loading from this offset from an // unknown JSReceiver. STATIC_ASSERT(static_cast(JSObject::kElementsOffset) == static_cast(JSProxy::kTargetOffset)); using BodyDescriptor = FixedBodyDescriptor; static Maybe SetPrivateSymbol(Isolate* isolate, Handle proxy, Handle private_name, PropertyDescriptor* desc, Maybe should_throw); TQ_OBJECT_CONSTRUCTORS(JSProxy) }; // JSProxyRevocableResult is just a JSObject with a specific initial map. // This initial map adds in-object properties for "proxy" and "revoke". // See https://tc39.github.io/ecma262/#sec-proxy.revocable class JSProxyRevocableResult : public JSObject { public: // Layout description. DEFINE_FIELD_OFFSET_CONSTANTS( JSObject::kHeaderSize, TORQUE_GENERATED_JS_PROXY_REVOCABLE_RESULT_FIELDS) // Indices of in-object properties. static const int kProxyIndex = 0; static const int kRevokeIndex = 1; private: DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxyRevocableResult); }; } // namespace internal } // namespace v8 #include "src/objects/object-macros-undef.h" #endif // V8_OBJECTS_JS_PROXY_H_