Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(helpers): Use hasOwnProperty.call #37013

Closed

Conversation

ExE-Boss
Copy link
Contributor

@ExE-Boss ExE-Boss commented Feb 25, 2020

Currently, the following code:

exports.hasOwnProperty(…) override

// func-util.ts
export const { apply, call } = (({ apply }) => ({
	apply: <T, A extends any[], R>(
		target: (this: T, ...args: A) => R,
		thisArg: T,
		args: A = [] as A
	): R => apply(target, thisArg, args),
	call: <T, A extends any[], R>(
		target: (this: T, ...args: A) => R,
		thisArg: T,
		...args: A
	): R => apply(target, thisArg, args),
}))(Reflect);
// helpers.ts
import { assertArgs, assertObject } from "./types.js";
import { call } from "./func-util.js";

export * from "./func-util.js";
export const {
	hasOwnProperty,
	isPrototypeOf,
} = (({ hasOwnProperty, isPrototypeOf }) => {
	return {
		hasOwnProperty(target: object, property: PropertyKey) {
			assertArgs(arguments.length, 2);
			assertObject(target);
			return call(hasOwnProperty, target, property);
		},
		isPrototypeOf(proto: object, target: any) {
			assertArgs(arguments.length, 2);
			assertObject(proto);
			return call(isPrototypeOf, proto, target);
		},
	};
})(Object.prototype);

results in an error at runtime when transpiled to non‑ESM, because exports.hasOwnProperty(…) is called with only a single non‑object argument.


This also won't work in case exports has its prototype set to null


TSLib PR: microsoft/tslib#92

Fixes #37016
Fixes #3197

@sandersn sandersn added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Mar 2, 2020
@sandersn sandersn added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Mar 12, 2020
@rbuckton
Copy link
Member

@ExE-Boss can you update this PR? The helpers have moved to src/compiler/factory/emitHelpers.ts and the baselines need to be updated.

@rbuckton
Copy link
Member

rbuckton commented Jul 9, 2020

@ExE-Boss: If its ok with you, I'm going to try to resolve the conflicts in this PR so that I can merge it. If I'm unable to modify this PR directly, I'll probably have to create a new PR with the changes and close this one.

@rbuckton
Copy link
Member

rbuckton commented Jul 9, 2020

@ExE-Boss I'm closing this in favor of #39537 (which is just this PR updated with master). Thanks for the contribution!

@rbuckton rbuckton closed this Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Avoid calling hasOwnProperty in helpers Re-export issue with hasOwnProperty.
3 participants