Debian Codegraph @

js/public/friend/DOMProxy.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 /*
8 * Specify information about DOMProxy proxies in the DOM, for use by ICs.
9 *
10 * Embedders who don't need to define particularly high-performance proxies that
11 * can have random properties added to them can ignore this header.
12 */
13
14 #ifndef js_friend_DOMProxy_h
15 #define js_friend_DOMProxy_h
16
17 #include <stddef.h> // size_t
18 #include <stdint.h> // uint64_t
19
20 #include "jstypes.h" // JS_PUBLIC_API
21
22 #include "js/Id.h" // JS::PropertyKey
23 #include "js/RootingAPI.h" // JS::Handle, JS::Heap
24 #include "js/Value.h" // JS::UndefinedValue, JS::Value
25
26 struct JS_PUBLIC_API JSContext;
27 class JS_PUBLIC_API JSObject;
28
29 namespace JS {
30
31 /*
32 * The DOMProxyShadowsCheck function will be called to check if the property for
33 * id should be gotten from the prototype, or if there is an own property that
34 * shadows it.
35 * * If ShadowsViaDirectExpando is returned, then the slot at
36 * listBaseExpandoSlot contains an expando object which has the property in
37 * question.
38 * * If ShadowsViaIndirectExpando is returned, then the slot at
39 * listBaseExpandoSlot contains a private pointer to an ExpandoAndGeneration
40 * and the expando object in the ExpandoAndGeneration has the property in
41 * question.
42 * * If DoesntShadow is returned then the slot at listBaseExpandoSlot should
43 * either be undefined or point to an expando object that would contain the
44 * own property.
45 * * If DoesntShadowUnique is returned then the slot at listBaseExpandoSlot
46 * should contain a private pointer to a ExpandoAndGeneration, which contains
47 * a JS::Value that should either be undefined or point to an expando object,
48 * and a uint64 value. If that value changes then the IC for getting a
49 * property will be invalidated.
50 * * If Shadows is returned, that means the property is an own property of the
51 * proxy but doesn't live on the expando object.
52 */
53
54 struct ExpandoAndGeneration {
55 ExpandoAndGeneration() : expando(JS::UndefinedValue()), generation(0) {}
56
57 void OwnerUnlinked() { ++generation; }
58
59 static constexpr size_t offsetOfExpando() {
60 return offsetof(ExpandoAndGeneration, expando);
61 }
62
63 static constexpr size_t offsetOfGeneration() {
64 return offsetof(ExpandoAndGeneration, generation);
65 }
66
67 Heap<Value> expando;
68 uint64_t generation;
69 };
70
71 enum class DOMProxyShadowsResult {
72 ShadowCheckFailed,
73 Shadows,
74 DoesntShadow,
75 DoesntShadowUnique,
76 ShadowsViaDirectExpando,
77 ShadowsViaIndirectExpando
78 };
79
80 using DOMProxyShadowsCheck = DOMProxyShadowsResult (*)(JSContext*,
81 Handle<JSObject*>,
82 Handle<JS::PropertyKey>);
83
84 extern JS_PUBLIC_API void SetDOMProxyInformation(
85 const void* domProxyHandlerFamily,
86 DOMProxyShadowsCheck domProxyShadowsCheck,
87 const void* domRemoteProxyHandlerFamily);
88
89 } // namespace JS
90
91 #endif // js_friend_DOMProxy_h