[gjs/ewlsh/enable-weak-refs] global: Enable WeakRef




commit 6de905fa3d3fb1ef10c7ddad91fec832878dfaf2
Author: Evan Welsh <contact evanwelsh com>
Date:   Sun Jan 30 15:54:16 2022 -0800

    global: Enable WeakRef
    
    Add a test suite to validate all expected global objects are in
    fact defined.

 gjs/global.cpp                   |  6 ++++++
 installed-tests/js/meson.build   |  1 +
 installed-tests/js/testGlobal.js | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)
---
diff --git a/gjs/global.cpp b/gjs/global.cpp
index 912d5a84e..3ed6ac5f3 100644
--- a/gjs/global.cpp
+++ b/gjs/global.cpp
@@ -44,6 +44,12 @@ union Utf8Unit;
 class GjsBaseGlobal {
     static JSObject* base(JSContext* cx, const JSClass* clasp,
                           JS::RealmCreationOptions options) {
+        // Enable WeakRef without the cleanupSome specification
+        // Re-evaluate if cleanupSome is standardized
+        // See: https://github.com/tc39/proposal-cleanup-some
+        options.setWeakRefsEnabled(
+            JS::WeakRefSpecifier::EnabledWithoutCleanupSome);
+
         JS::RealmBehaviors behaviors;
         JS::RealmOptions compartment_options(options, behaviors);
 
diff --git a/installed-tests/js/meson.build b/installed-tests/js/meson.build
index 6a5c40b50..f531fd356 100644
--- a/installed-tests/js/meson.build
+++ b/installed-tests/js/meson.build
@@ -236,6 +236,7 @@ modules_tests = [
     'ESModules',
     'Encoding',
     'GLibLogWriter',
+    'Global',
     'Timers',
 ]
 if build_cairo
diff --git a/installed-tests/js/testGlobal.js b/installed-tests/js/testGlobal.js
new file mode 100644
index 000000000..c4b69cdfb
--- /dev/null
+++ b/installed-tests/js/testGlobal.js
@@ -0,0 +1,39 @@
+describe('globalThis', () => {
+    function itIsDefined(value, message) {
+        it(`${message ? `${message} ` : ''}is defined`, function () {
+            expect(value).toBeDefined();
+        });
+    }
+
+    it('is equal to window', function () {
+        expect(globalThis.window).toBe(globalThis);
+        expect(window.globalThis).toBe(globalThis);
+    });
+
+    describe('WeakRef', () => {
+        itIsDefined(globalThis.WeakRef);
+    });
+
+    describe('console', () => {
+        itIsDefined(globalThis.console);
+    });
+
+    describe('TextEncoder', () => {
+        itIsDefined(globalThis.TextEncoder);
+    });
+
+    describe('TextDecoder', () => {
+        itIsDefined(globalThis.TextDecoder);
+    });
+
+    describe('ARGV', () => {
+        itIsDefined(globalThis.ARGV);
+    });
+
+    describe('print function', () => {
+        itIsDefined(globalThis.log, 'log');
+        itIsDefined(globalThis.print, 'print');
+        itIsDefined(globalThis.printerr, 'printerr');
+        itIsDefined(globalThis.logError, 'logError');
+    });
+});


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]