[gjs/esm/static-imports] WIP - remove code that exposes GI namespaces in internal global
- From: Evan Welsh <ewlsh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/esm/static-imports] WIP - remove code that exposes GI namespaces in internal global
- Date: Sat, 2 Jan 2021 18:19:08 +0000 (UTC)
commit 55fb16572eb154b24a9a71890735f13a1259d947
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Dec 13 15:22:45 2020 -0800
WIP - remove code that exposes GI namespaces in internal global
gi/repo.cpp | 49 ++++++-------------------------------------------
gjs/global.cpp | 50 +-------------------------------------------------
2 files changed, 7 insertions(+), 92 deletions(-)
---
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 9e457b8d..bd0635c5 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -557,9 +557,12 @@ fail:
return false;
}
-GJS_JSAPI_RETURN_CONVENTION
-static JSObject* lookup_namespace(JSContext* cx, JSObject* global,
- JS::HandleId ns_name) {
+JSObject* gjs_lookup_namespace_object_by_name(JSContext* cx,
+ JS::HandleId ns_name) {
+ JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
+ g_assert(gjs_global_get_type(global) == GjsGlobalType::DEFAULT &&
+ "Not possible to load GI namespaces in non-main realm");
+
JS::RootedObject native_registry(cx, gjs_get_native_registry(global));
auto priv = GjsContextPrivate::from_cx(cx);
const GjsAtoms& atoms = priv->atoms();
@@ -581,46 +584,6 @@ static JSObject* lookup_namespace(JSContext* cx, JSObject* global,
return retval;
}
-GJS_JSAPI_RETURN_CONVENTION
-static JSObject* lookup_internal_namespace(JSContext* cx, JSObject* global,
- JS::HandleId ns_name) {
- JS::RootedObject native_registry(cx, gjs_get_native_registry(global));
-
- const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
-
- // The internal global only supports GObject, Gio, GLib, and private
- // namespaces.
- g_assert((ns_name == atoms.gobject() || ns_name == atoms.gio() ||
- ns_name == atoms.glib() ||
- ns_name == atoms.private_ns_marker()) &&
- "Attempted to load unknown GI namespace on internal global.");
-
- JS::RootedObject retval(cx);
-
- if (!gjs_global_registry_get(cx, native_registry, ns_name, &retval))
- return nullptr;
-
- return retval;
-}
-
-JSObject* gjs_lookup_namespace_object_by_name(JSContext* cx,
- JS::HandleId ns_name) {
- JS::RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
-
- switch (gjs_global_get_type(global)) {
- case GjsGlobalType::DEFAULT:
- return lookup_namespace(cx, global, ns_name);
- case GjsGlobalType::INTERNAL:
- return lookup_internal_namespace(cx, global, ns_name);
- case GjsGlobalType::DEBUGGER:
- default:
- // It is not possible to load namespace objects in other globals
- // global.
- g_assert_not_reached();
- return nullptr;
- }
-}
-
const char*
gjs_info_type_name(GIInfoType type)
{
diff --git a/gjs/global.cpp b/gjs/global.cpp
index b7c9497c..8837235c 100644
--- a/gjs/global.cpp
+++ b/gjs/global.cpp
@@ -9,7 +9,6 @@
#include <stddef.h> // for size_t
-#include <girepository.h>
#include <glib.h>
#include <js/CallArgs.h> // for CallArgs, CallArgsFromVp
@@ -28,7 +27,6 @@
#include <js/Utility.h> // for UniqueChars
#include <jsapi.h> // for AutoSaveExceptionState, ...
-#include "gi/ns.h"
#include "gjs/atoms.h"
#include "gjs/context-private.h"
#include "gjs/engine.h"
@@ -317,8 +315,6 @@ class GjsInternalGlobal : GjsBaseGlobal {
static bool define_properties(JSContext* cx, JS::HandleObject global,
const char* realm_name,
const char* bootstrap_script G_GNUC_UNUSED) {
- const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
-
JS::Realm* realm = JS::GetObjectRealmOrNull(global);
g_assert(realm && "Global object must be associated with a realm");
// const_cast is allowed here if we never free the realm data
@@ -338,52 +334,8 @@ class GjsInternalGlobal : GjsBaseGlobal {
gjs_set_global_slot(global, GjsGlobalSlot::MODULE_REGISTRY,
JS::ObjectValue(*module_registry));
- if (!JS_DefineFunctions(cx, global, static_funcs))
- return false;
- // GI Modules
-
- GError* error = nullptr;
- if (!g_irepository_require(nullptr, "GObject", "2.0",
- GIRepositoryLoadFlags(0), &error) ||
- !g_irepository_require(nullptr, "GLib", "2.0",
- GIRepositoryLoadFlags(0), &error) ||
- !g_irepository_require(nullptr, "Gio", "2.0",
- GIRepositoryLoadFlags(0), &error)) {
- gjs_throw_gerror_message(cx, error);
- g_error_free(error);
- return false;
- }
-
- JS::RootedObject gobject(cx, gjs_create_ns(cx, "GObject"));
- JS::RootedObject glib(cx, gjs_create_ns(cx, "GLib"));
- JS::RootedObject gio(cx, gjs_create_ns(cx, "Gio"));
- JS::RootedObject privateNS(cx, JS_NewPlainObject(cx));
-
- if (!gjs_global_registry_set(cx, native_registry,
- atoms.private_ns_marker(), privateNS) ||
- !gjs_global_registry_set(cx, native_registry, atoms.gobject(),
- gobject) ||
- !gjs_global_registry_set(cx, native_registry, atoms.glib(), glib) ||
- !gjs_global_registry_set(cx, native_registry, atoms.gio(), gio) ||
- !JS_DefinePropertyById(cx, global, atoms.glib(), glib,
- JSPROP_PERMANENT) ||
- !JS_DefinePropertyById(cx, global, atoms.gio(), gio,
- JSPROP_PERMANENT) ||
- !JS_DefinePropertyById(cx, global, atoms.gobject(), gobject,
- JSPROP_PERMANENT)) {
- return false;
- }
-
- // Native Modules
-
- JS::RootedObject byteArray(cx, JS_NewPlainObject(cx));
- if (!gjs_load_native_module(cx, "_byteArrayNative", &byteArray) ||
- !JS_DefineProperty(cx, global, "ByteUtils", byteArray,
- JSPROP_PERMANENT))
- return false;
-
- return true;
+ return JS_DefineFunctions(cx, global, static_funcs);
}
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]