SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

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

Ähnlich wie What is new with JavaScript in Gnome: The 2021 edition

Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacript
Lei Kang
 
Google Developer Fest 2010
Google Developer Fest 2010Google Developer Fest 2010
Google Developer Fest 2010
Chris Ramsdale
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Carol McDonald
 

Ähnlich wie What is new with JavaScript in Gnome: The 2021 edition (20)

Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacript
 
Moving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresMoving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventures
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010
 
Google Developer Fest 2010
Google Developer Fest 2010Google Developer Fest 2010
Google Developer Fest 2010
 
JBoss World 2010
JBoss World 2010JBoss World 2010
JBoss World 2010
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and Golang
 
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 version
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
 
introduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraformintroduction-infra-as-a-code using terraform
introduction-infra-as-a-code using terraform
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
The Ring programming language version 1.8 book - Part 95 of 202
The Ring programming language version 1.8 book - Part 95 of 202The Ring programming language version 1.8 book - Part 95 of 202
The Ring programming language version 1.8 book - Part 95 of 202
 
Live deployment, ci, drupal
Live deployment, ci, drupalLive deployment, ci, drupal
Live deployment, ci, drupal
 
Why Gradle?
Why Gradle?Why Gradle?
Why Gradle?
 

Mehr von Igalia

Building End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPEBuilding End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPE
Igalia
 
Automated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded DevicesAutomated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded Devices
Igalia
 
Running JS via WASM faster with JIT
Running JS via WASM      faster with JITRunning JS via WASM      faster with JIT
Running JS via WASM faster with JIT
Igalia
 
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por IgaliaIntroducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Igalia
 

Mehr von Igalia (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Building End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPEBuilding End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPE
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded DevicesAutomated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded Devices
 
Embedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to MaintenanceEmbedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to Maintenance
 
Optimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdfOptimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdf
 
Running JS via WASM faster with JIT
Running JS via WASM      faster with JITRunning JS via WASM      faster with JIT
Running JS via WASM faster with JIT
 
To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!
 
Implementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamerImplementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamer
 
8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa
 
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por IgaliaIntroducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
 
2023 in Chimera Linux
2023 in Chimera                    Linux2023 in Chimera                    Linux
2023 in Chimera Linux
 
Building a Linux distro with LLVM
Building a Linux distro        with LLVMBuilding a Linux distro        with LLVM
Building a Linux distro with LLVM
 
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUsturnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
 
Graphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devicesGraphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devices
 
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOSDelegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
 
MessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the webMessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the web
 
Replacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shadersReplacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shaders
 
I'm not an AMD expert, but...
I'm not an AMD expert, but...I'm not an AMD expert, but...
I'm not an AMD expert, but...
 
Status of Vulkan on Raspberry
Status of Vulkan on RaspberryStatus of Vulkan on Raspberry
Status of Vulkan on Raspberry
 

Kürzlich hochgeladen

ENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu sweENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu swe
MohammadAliNayeem
 
Teachers record management system project report..pdf
Teachers record management system project report..pdfTeachers record management system project report..pdf
Teachers record management system project report..pdf
Kamal Acharya
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
Kamal Acharya
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
Kamal Acharya
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Lovely Professional University
 

Kürzlich hochgeladen (20)

RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
ENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu sweENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu swe
 
Teachers record management system project report..pdf
Teachers record management system project report..pdfTeachers record management system project report..pdf
Teachers record management system project report..pdf
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2
 
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfRESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
 
Attraction and Repulsion type Moving Iron Instruments.pptx
Attraction and Repulsion type Moving Iron Instruments.pptxAttraction and Repulsion type Moving Iron Instruments.pptx
Attraction and Repulsion type Moving Iron Instruments.pptx
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
Electrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineElectrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission line
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
 
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
 
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
 
Dairy management system project report..pdf
Dairy management system project report..pdfDairy management system project report..pdf
Dairy management system project report..pdf
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdf
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdf
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
 

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