Skip to content

Commit 16954b4

Browse files
committed
debt - careful with proxy, use type PropertyKey and not string
1 parent 5f7dd08 commit 16954b4

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/vs/workbench/api/common/extHostConfiguration.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class ExtHostConfigProvider {
198198
};
199199
return isObject(target) ?
200200
new Proxy(target, {
201-
get: (target: any, property: string) => {
201+
get: (target: any, property: PropertyKey) => {
202202
if (typeof property === 'string' && property.toLowerCase() === 'tojson') {
203203
cloneTarget();
204204
return () => clonedTarget;
@@ -213,21 +213,21 @@ export class ExtHostConfigProvider {
213213
}
214214
return result;
215215
},
216-
set: (_target: any, property: string, value: any) => {
216+
set: (_target: any, property: PropertyKey, value: any) => {
217217
cloneTarget();
218218
if (clonedTarget) {
219219
clonedTarget[property] = value;
220220
}
221221
return true;
222222
},
223-
deleteProperty: (_target: any, property: string) => {
223+
deleteProperty: (_target: any, property: PropertyKey) => {
224224
cloneTarget();
225225
if (clonedTarget) {
226226
delete clonedTarget[property];
227227
}
228228
return true;
229229
},
230-
defineProperty: (_target: any, property: string, descriptor: any) => {
230+
defineProperty: (_target: any, property: PropertyKey, descriptor: any) => {
231231
cloneTarget();
232232
if (clonedTarget) {
233233
Object.defineProperty(clonedTarget, property, descriptor);
@@ -284,10 +284,10 @@ export class ExtHostConfigProvider {
284284
const readonlyProxy = (target: any): any => {
285285
return isObject(target) ?
286286
new Proxy(target, {
287-
get: (target: any, property: string) => readonlyProxy(target[property]),
288-
set: (_target: any, property: string, _value: any) => { throw new Error(`TypeError: Cannot assign to read only property '${property}' of object`); },
289-
deleteProperty: (_target: any, property: string) => { throw new Error(`TypeError: Cannot delete read only property '${property}' of object`); },
290-
defineProperty: (_target: any, property: string) => { throw new Error(`TypeError: Cannot define property '${property}' for a readonly object`); },
287+
get: (target: any, property: PropertyKey) => readonlyProxy(target[property]),
288+
set: (_target: any, property: PropertyKey, _value: any) => { throw new Error(`TypeError: Cannot assign to read only property '${String(property)}' of object`); },
289+
deleteProperty: (_target: any, property: PropertyKey) => { throw new Error(`TypeError: Cannot delete read only property '${String(property)}' of object`); },
290+
defineProperty: (_target: any, property: PropertyKey) => { throw new Error(`TypeError: Cannot define property '${String(property)}' for a readonly object`); },
291291
setPrototypeOf: (_target: any) => { throw new Error(`TypeError: Cannot set prototype for a readonly object`); },
292292
isExtensible: () => false,
293293
preventExtensions: () => true

src/vs/workbench/services/extensions/common/rpcProtocol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ export class RPCProtocol extends Disposable implements IRPCProtocol {
180180

181181
private _createProxy<T>(rpcId: number): T {
182182
let handler = {
183-
get: (target: any, name: string) => {
184-
if (!target[name] && name.charCodeAt(0) === CharCode.DollarSign) {
183+
get: (target: any, name: PropertyKey) => {
184+
if (typeof name === 'string' && !target[name] && name.charCodeAt(0) === CharCode.DollarSign) {
185185
target[name] = (...myArgs: any[]) => {
186186
return this._remoteCall(rpcId, name, myArgs);
187187
};

src/vs/workbench/services/extensions/worker/extHost.services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function NotImplementedProxy<T>(name: ServiceIdentifier<T>): { new(): T } {
4343
return <any>class {
4444
constructor() {
4545
return new Proxy({}, {
46-
get(target: any, prop: string | number) {
46+
get(target: any, prop: PropertyKey) {
4747
if (target[prop]) {
4848
return target[prop];
4949
}

src/vs/workbench/test/browser/api/testRPCProtocol.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ export class TestRPCProtocol implements IExtHostContext, IExtHostRpcService {
7979

8080
private _createProxy<T>(proxyId: string): T {
8181
let handler = {
82-
get: (target: any, name: string) => {
83-
if (!target[name] && name.charCodeAt(0) === CharCode.DollarSign) {
82+
get: (target: any, name: PropertyKey) => {
83+
if (typeof name === 'string' && !target[name] && name.charCodeAt(0) === CharCode.DollarSign) {
8484
target[name] = (...myArgs: any[]) => {
8585
return this._remoteCall(proxyId, name, myArgs);
8686
};
8787
}
88+
8889
return target[name];
8990
}
9091
};

0 commit comments

Comments
 (0)