Skip to content

Commit 0a6124e

Browse files
author
Michael Droettboom
authored
Merge pull request #779 from mozilla/172777-qt-fixes
Bug 172777 - Apply workarounds to known Qt JS issues
2 parents cf93ab8 + 3c7f611 commit 0a6124e

File tree

13 files changed

+74
-104
lines changed

13 files changed

+74
-104
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.20.0...main)
44

5+
* [#754](https://github.com/mozilla/glean.js/pull/754): Change target ECMAScript target from 2015 to 2016 when building for Qt.
6+
* [#779](https://github.com/mozilla/glean.js/pull/779): Add a number of workarounds for the Qt Javascript engine.
7+
58
# v0.20.0 (2021-09-17)
69

710
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.19.0...v0.20.0)
@@ -10,7 +13,6 @@
1013
* [#695](https://github.com/mozilla/glean.js/pull/695): Implement PlatformInfo module for the Node.js platform.
1114
* [#695](https://github.com/mozilla/glean.js/pull/730): Implement Uploader module for the Node.js platform.
1215

13-
1416
# v0.19.0 (2021-09-03)
1517

1618
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.18.1...v0.19.0)

glean/src/core/dispatcher.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ class Dispatcher {
7979
// i.e. a Shutdown command is in the queue.
8080
private shuttingDown = false;
8181
// A promise containing the current execution promise.
82-
//
83-
// This is `undefined` in case there is no ongoing execution of tasks.
84-
private currentJob?: Promise<void>;
82+
private currentJob = Promise.resolve();
8583

8684
constructor(readonly maxPreInitQueueSize = 100, readonly logTag = LOG_TAG) {
8785
this.queue = [];
@@ -176,9 +174,10 @@ class Dispatcher {
176174
// that was launched inside another task.
177175
this.currentJob
178176
.then(() => {
179-
this.currentJob = undefined;
177+
// eslint-disable-next-line @typescript-eslint/no-this-alias
178+
const that = this;
180179
if (this.state === DispatcherState.Processing) {
181-
this.state = DispatcherState.Idle;
180+
that.state = DispatcherState.Idle;
182181
}
183182
})
184183
.catch(error => {
@@ -374,7 +373,7 @@ class Dispatcher {
374373
this.shuttingDown = true;
375374
this.launchInternal({ command: Commands.Shutdown });
376375
this.resume();
377-
return this.currentJob || Promise.resolve();
376+
return this.currentJob;
378377
}
379378

380379
/**
@@ -388,7 +387,7 @@ class Dispatcher {
388387
* @returns The promise.
389388
*/
390389
async testBlockOnQueue(): Promise<void> {
391-
return this.currentJob && await this.currentJob;
390+
return await this.currentJob;
392391
}
393392

394393
/**

glean/src/core/glean.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Glean {
8686
*/
8787
private static async onUploadEnabled(): Promise<void> {
8888
Context.uploadEnabled = true;
89-
await Glean.coreMetrics.initialize(Glean.instance._config, Glean.platform, Context.metricsDatabase);
89+
await Glean.coreMetrics.initialize(Glean.instance._config, Glean.platform);
9090
}
9191

9292
/**

glean/src/core/internal_metrics.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import TimeUnit from "./metrics/time_unit.js";
1111
import { generateUUIDv4 } from "./utils.js";
1212
import type { ConfigurationInterface } from "./config.js";
1313
import type Platform from "../platform/index.js";
14-
import type MetricsDatabase from "./metrics/database.js";
1514
import { Lifetime } from "./metrics/lifetime.js";
1615
import log, { LoggingLevel } from "./log.js";
16+
import { Context } from "./context.js";
1717

1818
const LOG_TAG = "core.InternalMetrics";
1919

@@ -100,9 +100,9 @@ export class CoreMetrics {
100100
});
101101
}
102102

103-
async initialize(config: ConfigurationInterface, platform: Platform, metricsDatabase: MetricsDatabase): Promise<void> {
104-
await this.initializeClientId(metricsDatabase);
105-
await this.initializeFirstRunDate(metricsDatabase);
103+
async initialize(config: ConfigurationInterface, platform: Platform): Promise<void> {
104+
await this.initializeClientId();
105+
await this.initializeFirstRunDate();
106106
await StringMetricType._private_setUndispatched(this.os, await platform.info.os());
107107
await StringMetricType._private_setUndispatched(this.osVersion, await platform.info.osVersion());
108108
await StringMetricType._private_setUndispatched(this.architecture, await platform.info.arch());
@@ -114,12 +114,10 @@ export class CoreMetrics {
114114
/**
115115
* Generates and sets the client_id if it is not set,
116116
* or if the current value is currepted.
117-
*
118-
* @param metricsDatabase The metrics database.
119117
*/
120-
private async initializeClientId(metricsDatabase: MetricsDatabase): Promise<void> {
118+
private async initializeClientId(): Promise<void> {
121119
let needNewClientId = false;
122-
const clientIdData = await metricsDatabase.getMetric(CLIENT_INFO_STORAGE, this.clientId);
120+
const clientIdData = await Context.metricsDatabase.getMetric(CLIENT_INFO_STORAGE, this.clientId);
123121
if (clientIdData) {
124122
try {
125123
const currentClientId = createMetric("uuid", clientIdData);
@@ -141,11 +139,9 @@ export class CoreMetrics {
141139

142140
/**
143141
* Generates and sets the first_run_date if it is not set.
144-
*
145-
* @param metricsDatabase The metrics database.
146142
*/
147-
private async initializeFirstRunDate(metricsDatabase: MetricsDatabase): Promise<void> {
148-
const firstRunDate = await metricsDatabase.getMetric(
143+
private async initializeFirstRunDate(): Promise<void> {
144+
const firstRunDate = await Context.metricsDatabase.getMetric(
149145
CLIENT_INFO_STORAGE,
150146
this.firstRunDate
151147
);

glean/src/core/metrics/database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class MetricsDatabase {
162162
}
163163

164164
const store = this._chooseStore(metric.lifetime);
165-
const storageKey = await metric.identifier(this);
165+
const storageKey = await metric.identifier();
166166
for (const ping of metric.sendInPings) {
167167
const finalTransformFn = (v?: JSONValue): JSONValue => transformFn(v).get();
168168
await store.update([ping, metric.type, storageKey], finalTransformFn);
@@ -231,7 +231,7 @@ class MetricsDatabase {
231231
metric: MetricType
232232
): Promise<T | undefined> {
233233
const store = this._chooseStore(metric.lifetime);
234-
const storageKey = await metric.identifier(this);
234+
const storageKey = await metric.identifier();
235235
const value = await store.get([ping, metric.type, storageKey]);
236236
if (!isUndefined(value) && !validateMetricInternalRepresentation<T>(metric.type, value)) {
237237
log(

glean/src/core/metrics/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import type { JSONValue } from "../utils.js";
66
import type { Lifetime } from "./lifetime.js";
7-
import type MetricsDatabase from "./database.js";
87
import type { ErrorType } from "../error/error_type.js";
98
import { isUndefined } from "../utils.js";
109
import { getValidDynamicLabel } from "./types/labeled.js";
@@ -82,17 +81,16 @@ export abstract class MetricType implements CommonMetricData {
8281
/**
8382
* The metric's unique identifier, including the category, name and label.
8483
*
85-
* @param metricsDatabase The metrics database.
8684
* @returns The generated identifier. If `category` is empty, it's ommitted. Otherwise,
8785
* it's the combination of the metric's `category`, `name` and `label`.
8886
*/
89-
async identifier(metricsDatabase: MetricsDatabase): Promise<string> {
87+
async identifier(): Promise<string> {
9088
const baseIdentifier = this.baseIdentifier();
9189

9290
// We need to use `isUndefined` and cannot use `(this.dynamicLabel)` because we want
9391
// empty strings to propagate as dynamic labels, so that erros are potentially recorded.
9492
if (!isUndefined(this.dynamicLabel)) {
95-
return await getValidDynamicLabel(metricsDatabase, this);
93+
return await getValidDynamicLabel(this);
9694
} else {
9795
return baseIdentifier;
9896
}

glean/src/core/metrics/types/labeled.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { CommonMetricData, MetricType } from "../index.js";
66
import type CounterMetricType from "./counter.js";
77
import type BooleanMetricType from "./boolean.js";
88
import type StringMetricType from "./string.js";
9-
import type MetricsDatabase from "../database.js";
109
import type { JSONValue } from "../../utils.js";
1110
import { Metric } from "../metric.js";
1211
import { Context } from "../../context.js";
@@ -93,11 +92,10 @@ export function stripLabel(identifier: string): string {
9392
* valid. If not, record an error and store data in the "__other__"
9493
* label.
9594
*
96-
* @param metricsDatabase the metrics database.
9795
* @param metric the metric to record to.
9896
* @returns a valid label that can be used to store data.
9997
*/
100-
export async function getValidDynamicLabel(metricsDatabase: MetricsDatabase, metric: MetricType): Promise<string> {
98+
export async function getValidDynamicLabel(metric: MetricType): Promise<string> {
10199
// Note that we assume `metric.dynamicLabel` to always be available within this function.
102100
// This is a safe assumptions because we should only call `getValidDynamicLabel` if we have
103101
// a dynamic label.
@@ -108,14 +106,14 @@ export async function getValidDynamicLabel(metricsDatabase: MetricsDatabase, met
108106
const key = combineIdentifierAndLabel(metric.baseIdentifier(), metric.dynamicLabel);
109107

110108
for (const ping of metric.sendInPings) {
111-
if (await metricsDatabase.hasMetric(metric.lifetime, ping, metric.type, key)) {
109+
if (await Context.metricsDatabase.hasMetric(metric.lifetime, ping, metric.type, key)) {
112110
return key;
113111
}
114112
}
115113

116114
let numUsedKeys = 0;
117115
for (const ping of metric.sendInPings) {
118-
numUsedKeys += await metricsDatabase.countByBaseIdentifier(
116+
numUsedKeys += await Context.metricsDatabase.countByBaseIdentifier(
119117
metric.lifetime,
120118
ping,
121119
metric.type,

0 commit comments

Comments
 (0)