Skip to content

fix(lib/es2015): Fix definition of ProxyHandler - #35594

Merged
Ron Buckton (rbuckton) merged 1 commit into
microsoft:masterfrom
ExE-Boss:lib/es2015/fix-proxy-handler-definition
Jan 4, 2021
Merged

fix(lib/es2015): Fix definition of ProxyHandler#35594
Ron Buckton (rbuckton) merged 1 commit into
microsoft:masterfrom
ExE-Boss:lib/es2015/fix-proxy-handler-definition

Conversation

@ExE-Boss

@ExE-BossExE Boss (ExE-Boss) commented Dec 9, 2019

Copy link
Copy Markdown
Contributor

This fixes several issues I found while comparing the definition of ProxyHandler to what’s actually defined in the specification.

Depends on:


Fixes#42894

Comment threadsrc/lib/es2015.proxy.d.ts Outdated
interface ProxyHandler<T extends object> {
getPrototypeOf? (target: T): object | null;
setPrototypeOf? (target: T, v: any): boolean;
setPrototypeOf? (target: T, v: object | null): boolean;

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Proxy exotic object’s [[SetPrototypeOf]] ( V ) internal method ensures that V is object | null before passing it to user code.

Comment threadsrc/lib/es2015.proxy.d.ts Outdated
get? (target: T, p: string | symbol, receiver: any): any;
set? (target: T, p: string | symbol, value: any, receiver: any): boolean;
deleteProperty? (target: T, p: string | symbol): boolean;
defineProperty? (target: T, p: string | symbol, attributes: PropertyDescriptor): boolean;

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Proxy exotic object doesn’t convert valid numeric indexes into numbers before passing them to user code, they remain as strings, which is how they’re actually implemented.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numbers never really exist as object keys, it's probably the biggest "lie" in typescript 🤷‍♀

Comment threadsrc/lib/es2015.proxy.d.ts Outdated
set? (target: T, p: string | symbol, value: any, receiver: any): boolean;
deleteProperty? (target: T, p: string | symbol): boolean;
defineProperty? (target: T, p: string | symbol, attributes: PropertyDescriptor): boolean;
ownKeys? (target: T): ArrayLike<string | symbol>;

@ExE-BossExE Boss (ExE-Boss)Dec 9, 2019

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you return anything other that a string or symbol here, this will throw a TypeError at runtime (no, numbers don’t stringified here for whatever reason; see tc39/ecma262#1804 for discussion).

On the plus side, the spec doesn’t actually require that the returned value is an Array instance, just that it has a length property and doesn’t have holes.


Spec: 🔗

Comment threadsrc/lib/es2015.proxy.d.ts Outdated
defineProperty? (target: T, p: string | symbol, attributes: PropertyDescriptor): boolean;
ownKeys? (target: T): ArrayLike<string | symbol>;
apply? (target: T & ((...args: any[]) => any), thisArg: any, argArray: any[]): any;
construct? (target: T & (new (...args: any[]) => object), argArray: any[], newTarget?: any): object;

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will only ever get called if the wrapped object is callable or constructable, respectively.

Comment threadsrc/lib/es2015.proxy.d.ts Outdated
set? (target: T, p: PropertyKey, value: any, receiver: any): boolean;
deleteProperty? (target: T, p: PropertyKey): boolean;
defineProperty? (target: T, p: PropertyKey, attributes: PropertyDescriptor): boolean;
enumerate? (target: T): PropertyKey[];

@ExE-BossExE Boss (ExE-Boss)Dec 9, 2019

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enumerate(…) method was removed in ES2016 from both Reflect and ProxyHandlers, due to implementers deciding against it.

The type is wrong anyway, since it’s specified to return Iterator<any>.

@typescript-bot

Copy link
Copy Markdown
Contributor

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@ExE-Boss
ExE Boss (ExE-Boss)force-pushed the lib/es2015/fix-proxy-handler-definition branch from a15bf40 to 64743c4CompareJanuary 4, 2021 10:52
@ExE-Boss
ExE Boss (ExE-Boss) marked this pull request as ready for review January 4, 2021 10:52
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

ProxyHandler.apply method

5 participants

@ExE-Boss@typescript-bot@Jessidhia@rbuckton@sandersn