1 // Copyright 2018 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 #ifndef V8_OBJECTS_JS_PROXY_H_ 6 #define V8_OBJECTS_JS_PROXY_H_ 7 8 #include "src/objects/js-objects.h" 9 #include "torque-generated/builtin-definitions.h" 10 11 // Has to be the last include (doesn't have include guards): 12 #include "src/objects/object-macros.h" 13 14 namespace v8 { 15 namespace internal { 16 17 #include "torque-generated/src/objects/js-proxy-tq.inc" 18 19 // The JSProxy describes EcmaScript Harmony proxies 20 class JSProxy : public TorqueGeneratedJSProxy<JSProxy, JSReceiver> { 21 public: 22 V8_WARN_UNUSED_RESULT static MaybeHandle<JSProxy> New(Isolate* isolate, 23 Handle<Object>, 24 Handle<Object>); 25 26 V8_INLINE bool IsRevoked() const; 27 static void Revoke(Handle<JSProxy> proxy); 28 29 // ES6 9.5.1 30 static MaybeHandle<HeapObject> GetPrototype(Handle<JSProxy> receiver); 31 32 // ES6 9.5.2 33 V8_WARN_UNUSED_RESULT static Maybe<bool> SetPrototype( 34 Handle<JSProxy> proxy, Handle<Object> value, bool from_javascript, 35 ShouldThrow should_throw); 36 // ES6 9.5.3 37 V8_WARN_UNUSED_RESULT static Maybe<bool> IsExtensible(Handle<JSProxy> proxy); 38 39 // ES6, #sec-isarray. NOT to be confused with %_IsArray. 40 V8_WARN_UNUSED_RESULT static Maybe<bool> IsArray(Handle<JSProxy> proxy); 41 42 // ES6 9.5.4 (when passed kDontThrow) 43 V8_WARN_UNUSED_RESULT static Maybe<bool> PreventExtensions( 44 Handle<JSProxy> proxy, ShouldThrow should_throw); 45 46 // ES6 9.5.5 47 V8_WARN_UNUSED_RESULT static Maybe<bool> GetOwnPropertyDescriptor( 48 Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name, 49 PropertyDescriptor* desc); 50 51 // ES6 9.5.6 52 V8_WARN_UNUSED_RESULT static Maybe<bool> DefineOwnProperty( 53 Isolate* isolate, Handle<JSProxy> object, Handle<Object> key, 54 PropertyDescriptor* desc, Maybe<ShouldThrow> should_throw); 55 56 // ES6 9.5.7 57 V8_WARN_UNUSED_RESULT static Maybe<bool> HasProperty(Isolate* isolate, 58 Handle<JSProxy> proxy, 59 Handle<Name> name); 60 61 // This function never returns false. 62 // It returns either true or throws. 63 V8_WARN_UNUSED_RESULT static Maybe<bool> CheckHasTrap( 64 Isolate* isolate, Handle<Name> name, Handle<JSReceiver> target); 65 66 // ES6 9.5.10 67 V8_WARN_UNUSED_RESULT static Maybe<bool> CheckDeleteTrap( 68 Isolate* isolate, Handle<Name> name, Handle<JSReceiver> target); 69 70 // ES6 9.5.8 71 V8_WARN_UNUSED_RESULT static MaybeHandle<Object> GetProperty( 72 Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name, 73 Handle<Object> receiver, bool* was_found); 74 75 enum AccessKind { kGet, kSet }; 76 77 static MaybeHandle<Object> CheckGetSetTrapResult(Isolate* isolate, 78 Handle<Name> name, 79 Handle<JSReceiver> target, 80 Handle<Object> trap_result, 81 AccessKind access_kind); 82 83 // ES6 9.5.9 84 V8_WARN_UNUSED_RESULT static Maybe<bool> SetProperty( 85 Handle<JSProxy> proxy, Handle<Name> name, Handle<Object> value, 86 Handle<Object> receiver, Maybe<ShouldThrow> should_throw); 87 88 // ES6 9.5.10 (when passed LanguageMode::kSloppy) 89 V8_WARN_UNUSED_RESULT static Maybe<bool> DeletePropertyOrElement( 90 Handle<JSProxy> proxy, Handle<Name> name, LanguageMode language_mode); 91 92 // ES6 9.5.12 93 V8_WARN_UNUSED_RESULT static Maybe<bool> OwnPropertyKeys( 94 Isolate* isolate, Handle<JSReceiver> receiver, Handle<JSProxy> proxy, 95 PropertyFilter filter, KeyAccumulator* accumulator); 96 97 V8_WARN_UNUSED_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes( 98 LookupIterator* it); 99 100 // Dispatched behavior. 101 DECL_VERIFIER(JSProxy) 102 103 static const int kMaxIterationLimit = 100 * 1024; 104 105 // kTargetOffset aliases with the elements of JSObject. The fact that 106 // JSProxy::target is a Javascript value which cannot be confused with an 107 // elements backing store is exploited by loading from this offset from an 108 // unknown JSReceiver. 109 STATIC_ASSERT(static_cast<int>(JSObject::kElementsOffset) == 110 static_cast<int>(JSProxy::kTargetOffset)); 111 112 using BodyDescriptor = 113 FixedBodyDescriptor<JSReceiver::kPropertiesOrHashOffset, kSize, kSize>; 114 115 static Maybe<bool> SetPrivateSymbol(Isolate* isolate, Handle<JSProxy> proxy, 116 Handle<Symbol> private_name, 117 PropertyDescriptor* desc, 118 Maybe<ShouldThrow> should_throw); 119 120 TQ_OBJECT_CONSTRUCTORS(JSProxy) 121 }; 122 123 // JSProxyRevocableResult is just a JSObject with a specific initial map. 124 // This initial map adds in-object properties for "proxy" and "revoke". 125 // See https://tc39.github.io/ecma262/#sec-proxy.revocable 126 class JSProxyRevocableResult 127 : public TorqueGeneratedJSProxyRevocableResult<JSProxyRevocableResult, 128 JSObject> { 129 public: 130 // Indices of in-object properties. 131 static const int kProxyIndex = 0; 132 static const int kRevokeIndex = 1; 133 134 private: 135 DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxyRevocableResult); 136 }; 137 138 } // namespace internal 139 } // namespace v8 140 141 #include "src/objects/object-macros-undef.h" 142 143 #endif // V8_OBJECTS_JS_PROXY_H_ 144