Skip to content

Commit 438be26

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[cleanup] Fix SDK.RemoteObject.callFunctionJSON types
The function can return null and use of it should respect that. Fixed: 402390420 Change-Id: Id7ace3e3090a8cfd938d92589494c267612f7a10 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6438951 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Auto-Submit: Nikolay Vitkov <nvitkov@chromium.org> Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
1 parent 18c644a commit 438be26

File tree

8 files changed

+20
-11
lines changed

8 files changed

+20
-11
lines changed

front_end/core/sdk/RemoteObject.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export abstract class RemoteObject {
242242

243243
callFunctionJSON<T, U>(
244244
_functionDeclaration: (this: U, ...args: any[]) => T,
245-
_args: Protocol.Runtime.CallArgument[]|undefined): Promise<T> {
245+
_args: Protocol.Runtime.CallArgument[]|undefined): Promise<T|null> {
246246
throw new Error('Not implemented');
247247
}
248248

@@ -568,7 +568,7 @@ export class RemoteObjectImpl extends RemoteObject {
568568

569569
override async callFunctionJSON<T, U>(
570570
functionDeclaration: (this: U, ...args: any[]) => T,
571-
args: Protocol.Runtime.CallArgument[]|undefined): Promise<T> {
571+
args: Protocol.Runtime.CallArgument[]|undefined): Promise<T|null> {
572572
const response = await this.#runtimeAgent.invoke_callFunctionOn({
573573
objectId: this.#objectIdInternal,
574574
functionDeclaration: functionDeclaration.toString(),
@@ -577,7 +577,7 @@ export class RemoteObjectImpl extends RemoteObject {
577577
returnByValue: true,
578578
});
579579
if (response.getError() || response.exceptionDetails) {
580-
return null as T;
580+
return null;
581581
}
582582

583583
return response.result.value;
@@ -973,7 +973,7 @@ export class RemoteArrayBuffer {
973973
return this.#objectInternal.arrayBufferByteLength();
974974
}
975975

976-
async bytes(start = 0, end = this.byteLength()): Promise<number[]> {
976+
async bytes(start = 0, end = this.byteLength()): Promise<number[]|null> {
977977
if (start < 0 || start >= this.byteLength()) {
978978
throw new RangeError('start is out of range');
979979
}

front_end/models/source_map_scopes/NamesResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ export class RemoteObject extends SDK.RemoteObject.RemoteObject {
741741
}
742742

743743
override callFunctionJSON<T, U>(
744-
functionDeclaration: (this: U, ...args: any[]) => T, args?: Protocol.Runtime.CallArgument[]): Promise<T> {
744+
functionDeclaration: (this: U, ...args: any[]) => T, args?: Protocol.Runtime.CallArgument[]): Promise<T|null> {
745745
return this.object.callFunctionJSON(functionDeclaration, args);
746746
}
747747

front_end/panels/event_listeners/EventListenersUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ export async function frameworkEventListeners(object: SDK.RemoteObject.RemoteObj
7575
return {type: this.type, useCapture: this.useCapture, passive: this.passive, once: this.once};
7676
}
7777

78-
function storeTruncatedListener(truncatedListener: TruncatedEventListenerObjectInInspectedPage): void {
78+
function storeTruncatedListener(truncatedListener: TruncatedEventListenerObjectInInspectedPage|null): void {
79+
if (!truncatedListener) {
80+
return;
81+
}
82+
7983
if (truncatedListener.type !== undefined) {
8084
type = truncatedListener.type;
8185
}

front_end/panels/event_listeners/EventListenersView.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ export class EventListenersView extends UI.Widget.VBox {
145145
return isInternal;
146146
}
147147

148-
function setIsInternal(isInternal: boolean[]): void {
148+
function setIsInternal(isInternal: boolean[]|null): void {
149+
if (!isInternal) {
150+
return;
151+
}
152+
149153
for (let i = 0; i < eventListeners.length; ++i) {
150154
if (isInternal[i]) {
151155
eventListeners[i].markAsFramework();

front_end/panels/linear_memory_inspector/LinearMemoryInspectorController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export class RemoteArrayBufferWrapper implements LazyUint8Array {
5353
return new Uint8Array(0);
5454
}
5555
const array = await this.#remoteArrayBuffer.bytes(start, newEnd);
56-
return new Uint8Array(array);
56+
57+
return new Uint8Array(array ?? []);
5758
}
5859
}
5960

front_end/ui/components/text_editor/javascript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ async function prototypesFromObject(object: SDK.RemoteObject.RemoteObject): Prom
710710
}
711711
}
712712
return result;
713-
}, []);
713+
}, []) ?? [];
714714
}
715715

716716
// Given a function object that is probably a bound function, try to

front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ export class ArrayGroupingTreeElement extends UI.TreeOutline.TreeElement {
14241424
return {ranges};
14251425
}
14261426

1427-
async function callback(result: {ranges: number[][]}|undefined): Promise<void> {
1427+
async function callback(result: {ranges: number[][]}|undefined|null): Promise<void> {
14281428
if (!result) {
14291429
return;
14301430
}

front_end/ui/legacy/components/utils/ImagePreview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class ImagePreview {
194194

195195
const featuresObject = await object.callFunctionJSON(features, undefined);
196196
object.release();
197-
return featuresObject;
197+
return featuresObject ?? undefined;
198198

199199
function features(this: HTMLImageElement): PrecomputedFeatures {
200200
return {

0 commit comments

Comments
 (0)