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