ShadowRealmCallbacks.h (1927B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef js_ShadowReamCallbacks_h 7 #define js_ShadowReamCallbacks_h 8 9 #include "jstypes.h" 10 #include "js/RootingAPI.h" 11 #include "js/TypeDecls.h" 12 13 struct JS_PUBLIC_API JSContext; 14 15 namespace JS { 16 17 class RealmOptions; 18 19 using GlobalInitializeCallback = bool (*)(JSContext*, JS::Handle<JSObject*>); 20 21 // Install the HostInitializeShadowRealm callback that will be invoked when 22 // creating a shadow realm. 23 // 24 // The callback will be passed the realm's global object, so that it is possible 25 // for the embedding to make any host-determined manipulations to the global, 26 // such as installing interfaces or helpers that should exist even within 27 // ShadowRealms. (For example, in the web platform, WebIDL with the 28 // [Exposed=*] attribute should be installed within a shadow realm.) 29 extern JS_PUBLIC_API void SetShadowRealmInitializeGlobalCallback( 30 JSContext* cx, GlobalInitializeCallback callback); 31 32 using GlobalCreationCallback = 33 JSObject* (*)(JSContext* cx, JS::RealmOptions& creationOptions, 34 JSPrincipals* principals, 35 JS::Handle<JSObject*> enclosingGlobal); 36 37 // Create the Global object for a ShadowRealm. 38 // 39 // This isn't directly specified, however at least in Gecko, in order to 40 // correctly implement HostInitializeShadowRealm, there are requirements 41 // placed on the global for the ShadowRealm. 42 // 43 // This callback should return a Global object compatible with the 44 // callback installed by SetShadowRealmInitializeGlobalCallback 45 extern JS_PUBLIC_API void SetShadowRealmGlobalCreationCallback( 46 JSContext* cx, GlobalCreationCallback callback); 47 48 } // namespace JS 49 50 #endif // js_ShadowReamCallbacks_h