SlideShare a Scribd company logo
What's new with
JavaScript in
GNOME
The 2021 edition
Philip Chimento

 pchimento •   ptomato

 @therealptomato

GUADEC Online, July 22, 2021
Photo by Lucas Pezeta from Pexels 1
Introduction: What we will talk about
Same thing we talk about every year!
What's new in GJS?
What's next in GJS?
We need some help! Here's what you can do
2
Introduction
Presentation is full of links if you want to click through later
If you want to follow along: ptomato.name/talks/guadec2021
3
What's new in JavaScript land for
What's new in JavaScript land for
What's new in JavaScript land for
GNOME 40 and 41?
GNOME 40 and 41?
GNOME 40 and 41?
4
4
4
Crash fixes
㊵ ㊶ 10 crashing bugs fixed in the past year
But also, 10 crashing bugs reported in the past year
Total of 9 currently open
2 older than 1 year
㊵ Many refactors adding type safety ( Marco Trevisan)
5
Performance improvements ㊶
Memory usage improvements ( Marco Trevisan)
!625 for objects
!519 for functions
6
ES Modules ㊵
// Old, but still works, not deprecated:
const System = imports.system; // built-in module

imports.gi.versions.Gtk = '3.0';
const {Gtk} = imports.gi; // G-I binding

imports.searchPath.unshift('resource:///com/example/MyApp');
const {MyClass, myFunction} = imports.src.myModule;

// imports src/myModule.js from search path

// New 

import System from 'system'; // built-in module
import Gtk from 'gi://Gtk?version=3.0'; // G-I binding

import {MyClass, myFunction} from './src/myModule.js';

// imports path relative to currently executing file

7
ES Modules ㊵
Run your main file with -m
or gjs_context_eval_module() if using the GObject-based API
ES modules can import legacy modules, but not vice versa
To port your code, start at the top level and work downwards
Evan Welsh
8
ES Modules ㊵
ES modules are always in strict mode
Importing is compile-time!
To import conditionally, use dynamic async import()
// NOT POSSIBLE 

if (usingSomeLibrary)

import SomeLibrary from 'gi://SomeLibrary';

// Possible 

if (usingSomeLibrary)

const SomeLibrary = await import('gi://SomeLibrary');

9
Debugger improvements ㊵
Backtrace command that prints all the locals, like GDB
Program listing
Show line along with frame
Nasah Kuma
10
Debugger improvements ㊵
function myFunction(a, b, c) {

const d = Math.random();
debugger;

}

myFunction(3, 2, 1);
11
Debugger improvements ㊵
db> bt full

#0 myFunction(3, 2, 1) at bug.js:3:4

d = 0.7590159046381023

#1 toplevel at bug.js:5:10

db> list
1 function myFunction(a, b, c) {

2 const d = Math.random();
*3 debugger;

4 }

5 myFunction(3, 2, 1);
db> frame 1

#1 toplevel at bug.js:5:10

5 myFunction(3, 2, 1);
12
JS Object GObject parameters ㊵
Properties: {

myArray: GObject.ParamSpec.jsobject('my-array', 'My array',

'You can now use JS objects as the value of GObject properties',
GObject.ParamFlags.READWRITE),

},

Marco Trevisan
13
Text encoding/decoding ㊶
// Old, but still works, not deprecated:
const ByteArray = imports.byteArray;
const pizza = ByteArray.toString(Uint8Array.of(0xf0, 0x9f, 0x8d, 0x95) /*, 'utf-8' */);

const pizzaBytes = ByteArray.fromString(' ' /*, 'utf-8' */);

// New 

const decoder = new TextDecoder(/* 'utf-8' */);

const pizza = decoder.decode(Uint8Array.of(0xf0, 0x9f, 0x8d, 0x95));
const encoder = new TextEncoder();

const pizzaBytes = encoder.encode(' ');

Evan Welsh
14
Memory profiling ㊶
15
Console API ㊶
// Old, but still works, not deprecated:
log('A message from your program');

// New, nice if you're used to browsers and Node:

console.log('A message from your program');

Evan Welsh
16
Documentation and Examples
Extensions Rebooted
17
What is upcoming in JavaScript land for
What is upcoming in JavaScript land for
What is upcoming in JavaScript land for
GNOME?
GNOME?
GNOME?
18
18
18
Native async operations ㊶ ㊷
Annotations:
<method name="load_contents_async" c:identifier="g_file_load_contents_async"
glib:finish-func="g_file_load_contents_finish"

glib:sync-func="g_file_load_contents">

// Opt-in per method no longer needed:

// Gio._promisify(Gio._LocalFilePrototype, 'load_contents_async', 'load_contents_finish');

const [contents] = await file.load_contents_async(/* cancel = */ null);

Veena Nagar
19
Next JS engine upgrade (Firefox 91) ㊷
#private class fields
class MyClass {

#value;

someMethod() {

doSomethingWith(this.#value);

}

}

Note: Doesn't yet integrate with GObject classes.
20
Next JS engine upgrade (Firefox 91) ㊷
at() : Python-style indexing for arrays, strings, and typed arrays
const arr = [1, 2, 3, 4, 5, 6, 7];

arr.at(0) // 1

arr.at(-1) // 7
arr.at(999) // undefined

'my string'.at(-7) // ' '

arr[arr.length - 1] // no longer necessary!
21
Next JS engine upgrade (Firefox 91) ㊷
Promise.any() : First successful sub-promise
const cancellable = new Gio.Cancellable();

const fastestServer = await Promise.any([

checkServer(EAST, cancellable),

checkServer(WEST, cancellable),

waitSeconds(30),
]);

if (!fastestServer) {

cancellable.cancel();

notify('No server found within 30 seconds');
}

22
Next JS engine upgrade (Firefox 91) ㊷
??= , &&= , ||= operators
Short-circuiting assignment operators
a ??= b - assign a = b if a is null or undefined
a ||= b - assign a = b if a is falsey
a &&= b - assign a = b if a is truthy
23
How can
How can
How can you
you
you help?
help?
help?
24
24
24
Help define best practices for the
GNOME JS ecosystem
Sample app has been updated
For an experiment with even newer stuff, see the GJS Bloatpad
Writing native Linux desktop apps with JavaScript at LAS 2021
Talk to us in #javascript:gnome.org about things confusing you!
25
The Big Hammer, why isn't it removed?
Well-defined problems are nearly all solved. Squishy problems remain.
We need:
㊷ better memory accounting
to quantify acceptable memory usage for Shell, & tune GC accordingly
to figure out some solution that fits both Shell and apps
a communication plan
26
Thanks
GJS contributors from 40 and 41
License
Presentation licensed under Creative Commons BY-NC-ND 4.0
27
Questions?
Questions?
Questions?
‍
‍
‍
Image:
Image:
Image: IRCat
IRCat
IRCat from
from
from Pixabay
Pixabay
Pixabay 28
28
28

More Related Content

PDF
Types - slice, map, new, make, struct - Gopherlabs
PDF
ES6 ECMA2015
PDF
When webpack -p is not enough
PDF
Groovy and Grails talk
PDF
Async await functions in ruby
PDF
Hiveminder - Everything but the Secret Sauce
PPTX
How go makes us faster (May 2015)
PDF
Goroutine stack and local variable allocation in Go
Types - slice, map, new, make, struct - Gopherlabs
ES6 ECMA2015
When webpack -p is not enough
Groovy and Grails talk
Async await functions in ruby
Hiveminder - Everything but the Secret Sauce
How go makes us faster (May 2015)
Goroutine stack and local variable allocation in Go

What's hot (20)

PDF
Quantum circuit example in Qiskit
PDF
Angular v2 et plus : le futur du développement d'applications en entreprise
PDF
Large scale machine learning projects with r suite
PDF
[UDS] Cloud Computing "pour les nuls" (Exemple avec LinShare)
PPTX
Type script新鮮貨報你知
PDF
Advanced Node.JS Meetup
PPTX
Node js packages [#howto with npm]
PDF
TDC2018SP | Trilha Containers - CI/CD com Docker e Drone
PDF
Qsam simulator in IBM Quantum Lab cloud
PPTX
How to lock a Python in a cage? Managing Python environment inside an R project
PDF
PDF
KubeCon EU 2016: Using Traffic Control to Test Apps in Kubernetes
PDF
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
PDF
The Mystery of Event Loop in JavaScript
KEY
CPAN Realtime feed
PDF
Inc decsourcefile
PDF
Using Monitoring & Configuration Management to restart services.
PDF
Decision making - for loop , nested loop ,if-else statements , switch in goph...
PDF
From minutes with Guzzle to seconds with Symfony HttpClient.
PDF
Taking containers from development to production
Quantum circuit example in Qiskit
Angular v2 et plus : le futur du développement d'applications en entreprise
Large scale machine learning projects with r suite
[UDS] Cloud Computing "pour les nuls" (Exemple avec LinShare)
Type script新鮮貨報你知
Advanced Node.JS Meetup
Node js packages [#howto with npm]
TDC2018SP | Trilha Containers - CI/CD com Docker e Drone
Qsam simulator in IBM Quantum Lab cloud
How to lock a Python in a cage? Managing Python environment inside an R project
KubeCon EU 2016: Using Traffic Control to Test Apps in Kubernetes
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
The Mystery of Event Loop in JavaScript
CPAN Realtime feed
Inc decsourcefile
Using Monitoring & Configuration Management to restart services.
Decision making - for loop , nested loop ,if-else statements , switch in goph...
From minutes with Guzzle to seconds with Symfony HttpClient.
Taking containers from development to production
Ad

Similar to What is new with JavaScript in Gnome: The 2021 edition (20)

PDF
The Newest JavaScript Technologies in GNOME
PDF
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
PDF
Javascript, the GNOME way (JSConf EU 2011)
PPTX
ES6 - JavaCro 2016
PPTX
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
PPTX
JS digest. Mid-Summer 2017
PDF
JavaScript Editions ES7, ES8 and ES9 vs V8
PPTX
Turbo charging v8 engine
PDF
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
PDF
node.js in production: Reflections on three years of riding the unicorn
PDF
Whats new in ES2019
PDF
JavaScript for impatient programmers.pdf
PPTX
JS awesomeness or how will ES6 help me build better apps ?
PDF
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
PPTX
Js engine performance
PDF
[PDF]_Learning_ECMAScript_6.pdf
PDF
[4developers2016] The ultimate mobile DX using JS as a primary language (Fato...
PDF
Moving Web forward: Part I — ECMAScript 201x
PDF
JavaScript in 2015
PDF
Writing native Linux desktop apps with JavaScript
The Newest JavaScript Technologies in GNOME
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
Javascript, the GNOME way (JSConf EU 2011)
ES6 - JavaCro 2016
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
JS digest. Mid-Summer 2017
JavaScript Editions ES7, ES8 and ES9 vs V8
Turbo charging v8 engine
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
node.js in production: Reflections on three years of riding the unicorn
Whats new in ES2019
JavaScript for impatient programmers.pdf
JS awesomeness or how will ES6 help me build better apps ?
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
Js engine performance
[PDF]_Learning_ECMAScript_6.pdf
[4developers2016] The ultimate mobile DX using JS as a primary language (Fato...
Moving Web forward: Part I — ECMAScript 201x
JavaScript in 2015
Writing native Linux desktop apps with JavaScript
Ad

More from Igalia (20)

PDF
Life of a Kernel Bug Fix
PDF
Unlocking the Full Potential of WPE to Build a Successful Embedded Product
PDF
Advancing WebDriver BiDi support in WebKit
PDF
Jumping Over the Garden Wall - WPE WebKit on Android
PDF
Collective Funding, Governance and Prioritiation of Browser Engine Projects
PDF
Don't let your motivation go, save time with kworkflow
PDF
Solving the world’s (localization) problems
PDF
The Whippet Embeddable Garbage Collection Library
PDF
Nobody asks "How is JavaScript?"
PDF
Getting more juice out from your Raspberry Pi GPU
PDF
WebRTC support in WebKitGTK and WPEWebKit with GStreamer: Status update
PDF
Demystifying Temporal: A Deep Dive into JavaScript New Temporal API
PDF
CSS :has() Unlimited Power
PDF
Device-Generated Commands in Vulkan
PDF
Current state of Lavapipe: Mesa's software renderer for Vulkan
PDF
Vulkan Video is Open: Application showcase
PDF
Scheme on WebAssembly: It is happening!
PDF
EBC - A new backend compiler for etnaviv
PDF
RISC-V LLVM State of the Union
PDF
Device-Generated Commands in Vulkan
Life of a Kernel Bug Fix
Unlocking the Full Potential of WPE to Build a Successful Embedded Product
Advancing WebDriver BiDi support in WebKit
Jumping Over the Garden Wall - WPE WebKit on Android
Collective Funding, Governance and Prioritiation of Browser Engine Projects
Don't let your motivation go, save time with kworkflow
Solving the world’s (localization) problems
The Whippet Embeddable Garbage Collection Library
Nobody asks "How is JavaScript?"
Getting more juice out from your Raspberry Pi GPU
WebRTC support in WebKitGTK and WPEWebKit with GStreamer: Status update
Demystifying Temporal: A Deep Dive into JavaScript New Temporal API
CSS :has() Unlimited Power
Device-Generated Commands in Vulkan
Current state of Lavapipe: Mesa's software renderer for Vulkan
Vulkan Video is Open: Application showcase
Scheme on WebAssembly: It is happening!
EBC - A new backend compiler for etnaviv
RISC-V LLVM State of the Union
Device-Generated Commands in Vulkan

Recently uploaded (20)

PPTX
Artificial Intelligence
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
additive manufacturing of ss316l using mig welding
PPT
Mechanical Engineering MATERIALS Selection
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Sustainable Sites - Green Building Construction
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
OOP with Java - Java Introduction (Basics)
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
composite construction of structures.pdf
PDF
Well-logging-methods_new................
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
Artificial Intelligence
bas. eng. economics group 4 presentation 1.pptx
additive manufacturing of ss316l using mig welding
Mechanical Engineering MATERIALS Selection
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Sustainable Sites - Green Building Construction
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
OOP with Java - Java Introduction (Basics)
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
composite construction of structures.pdf
Well-logging-methods_new................
UNIT 4 Total Quality Management .pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Model Code of Practice - Construction Work - 21102022 .pdf

What is new with JavaScript in Gnome: The 2021 edition

  • 1. What's new with JavaScript in GNOME The 2021 edition Philip Chimento  pchimento •   ptomato  @therealptomato GUADEC Online, July 22, 2021 Photo by Lucas Pezeta from Pexels 1
  • 2. Introduction: What we will talk about Same thing we talk about every year! What's new in GJS? What's next in GJS? We need some help! Here's what you can do 2
  • 3. Introduction Presentation is full of links if you want to click through later If you want to follow along: ptomato.name/talks/guadec2021 3
  • 4. What's new in JavaScript land for What's new in JavaScript land for What's new in JavaScript land for GNOME 40 and 41? GNOME 40 and 41? GNOME 40 and 41? 4 4 4
  • 5. Crash fixes ㊵ ㊶ 10 crashing bugs fixed in the past year But also, 10 crashing bugs reported in the past year Total of 9 currently open 2 older than 1 year ㊵ Many refactors adding type safety ( Marco Trevisan) 5
  • 6. Performance improvements ㊶ Memory usage improvements ( Marco Trevisan) !625 for objects !519 for functions 6
  • 7. ES Modules ㊵ // Old, but still works, not deprecated: const System = imports.system; // built-in module imports.gi.versions.Gtk = '3.0'; const {Gtk} = imports.gi; // G-I binding imports.searchPath.unshift('resource:///com/example/MyApp'); const {MyClass, myFunction} = imports.src.myModule; // imports src/myModule.js from search path // New import System from 'system'; // built-in module import Gtk from 'gi://Gtk?version=3.0'; // G-I binding import {MyClass, myFunction} from './src/myModule.js'; // imports path relative to currently executing file 7
  • 8. ES Modules ㊵ Run your main file with -m or gjs_context_eval_module() if using the GObject-based API ES modules can import legacy modules, but not vice versa To port your code, start at the top level and work downwards Evan Welsh 8
  • 9. ES Modules ㊵ ES modules are always in strict mode Importing is compile-time! To import conditionally, use dynamic async import() // NOT POSSIBLE if (usingSomeLibrary) import SomeLibrary from 'gi://SomeLibrary'; // Possible if (usingSomeLibrary) const SomeLibrary = await import('gi://SomeLibrary'); 9
  • 10. Debugger improvements ㊵ Backtrace command that prints all the locals, like GDB Program listing Show line along with frame Nasah Kuma 10
  • 11. Debugger improvements ㊵ function myFunction(a, b, c) { const d = Math.random(); debugger; } myFunction(3, 2, 1); 11
  • 12. Debugger improvements ㊵ db> bt full #0 myFunction(3, 2, 1) at bug.js:3:4 d = 0.7590159046381023 #1 toplevel at bug.js:5:10 db> list 1 function myFunction(a, b, c) { 2 const d = Math.random(); *3 debugger; 4 } 5 myFunction(3, 2, 1); db> frame 1 #1 toplevel at bug.js:5:10 5 myFunction(3, 2, 1); 12
  • 13. JS Object GObject parameters ㊵ Properties: { myArray: GObject.ParamSpec.jsobject('my-array', 'My array', 'You can now use JS objects as the value of GObject properties', GObject.ParamFlags.READWRITE), }, Marco Trevisan 13
  • 14. Text encoding/decoding ㊶ // Old, but still works, not deprecated: const ByteArray = imports.byteArray; const pizza = ByteArray.toString(Uint8Array.of(0xf0, 0x9f, 0x8d, 0x95) /*, 'utf-8' */); const pizzaBytes = ByteArray.fromString(' ' /*, 'utf-8' */); // New const decoder = new TextDecoder(/* 'utf-8' */); const pizza = decoder.decode(Uint8Array.of(0xf0, 0x9f, 0x8d, 0x95)); const encoder = new TextEncoder(); const pizzaBytes = encoder.encode(' '); Evan Welsh 14
  • 16. Console API ㊶ // Old, but still works, not deprecated: log('A message from your program'); // New, nice if you're used to browsers and Node: console.log('A message from your program'); Evan Welsh 16
  • 18. What is upcoming in JavaScript land for What is upcoming in JavaScript land for What is upcoming in JavaScript land for GNOME? GNOME? GNOME? 18 18 18
  • 19. Native async operations ㊶ ㊷ Annotations: <method name="load_contents_async" c:identifier="g_file_load_contents_async" glib:finish-func="g_file_load_contents_finish" glib:sync-func="g_file_load_contents"> // Opt-in per method no longer needed: // Gio._promisify(Gio._LocalFilePrototype, 'load_contents_async', 'load_contents_finish'); const [contents] = await file.load_contents_async(/* cancel = */ null); Veena Nagar 19
  • 20. Next JS engine upgrade (Firefox 91) ㊷ #private class fields class MyClass { #value; someMethod() { doSomethingWith(this.#value); } } Note: Doesn't yet integrate with GObject classes. 20
  • 21. Next JS engine upgrade (Firefox 91) ㊷ at() : Python-style indexing for arrays, strings, and typed arrays const arr = [1, 2, 3, 4, 5, 6, 7]; arr.at(0) // 1 arr.at(-1) // 7 arr.at(999) // undefined 'my string'.at(-7) // ' ' arr[arr.length - 1] // no longer necessary! 21
  • 22. Next JS engine upgrade (Firefox 91) ㊷ Promise.any() : First successful sub-promise const cancellable = new Gio.Cancellable(); const fastestServer = await Promise.any([ checkServer(EAST, cancellable), checkServer(WEST, cancellable), waitSeconds(30), ]); if (!fastestServer) { cancellable.cancel(); notify('No server found within 30 seconds'); } 22
  • 23. Next JS engine upgrade (Firefox 91) ㊷ ??= , &&= , ||= operators Short-circuiting assignment operators a ??= b - assign a = b if a is null or undefined a ||= b - assign a = b if a is falsey a &&= b - assign a = b if a is truthy 23
  • 24. How can How can How can you you you help? help? help? 24 24 24
  • 25. Help define best practices for the GNOME JS ecosystem Sample app has been updated For an experiment with even newer stuff, see the GJS Bloatpad Writing native Linux desktop apps with JavaScript at LAS 2021 Talk to us in #javascript:gnome.org about things confusing you! 25
  • 26. The Big Hammer, why isn't it removed? Well-defined problems are nearly all solved. Squishy problems remain. We need: ㊷ better memory accounting to quantify acceptable memory usage for Shell, & tune GC accordingly to figure out some solution that fits both Shell and apps a communication plan 26
  • 27. Thanks GJS contributors from 40 and 41 License Presentation licensed under Creative Commons BY-NC-ND 4.0 27