-
Notifications
You must be signed in to change notification settings - Fork 31
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
Function.prototype.toString requires that 'this' be a Function #94
Comments
Yeah feel free to make a PR, seems like a cheap check for added safety. I'm assuming something like this? if (!prototype || !prototype.constructor) {
return create(null);
} EDIT: Actually, now that I've gotten fingers to keyboard, I think this can be solved in a more accurate way that also doesn't impact perf for the majority use-case. When cloning an object, this utility is used: export function getCleanClone(prototype: any): any {
if (!prototype) {
return create(null);
}
const Constructor = prototype.constructor;
if (Constructor === Object) {
return prototype === Object.prototype ? {} : create(prototype);
}
if (~toStringFunction.call(Constructor).indexOf('[native code]')) {
try {
return new Constructor();
} catch {}
}
return create(prototype);
} The failure you're getting is in the final if (
Constructor &&
~toStringFunction.call(Constructor).indexOf('[native code]')
) { Now the test passes, and the clone appropriately has the same prototype as the |
Version |
Here from pinojs/pino-pretty#477
Basically I get an error from trying to log null object that uses V8 optimization
Optimization looks like this and it used in
fast-querystring
packageI figured out that internal function
getCleanClone
only check that prototype existI think it should handle case where
var Constructor = prototype.constructor === undefined
that would mean that this is null prototype and we should returncreate(null)
. I could make PR if you agree with it. What do you think?Also it possible to use this optimization, but I'm not sure how much it would be breaking change and should be perf tested to understand if this is worth it. Separate issue ofc.
The text was updated successfully, but these errors were encountered: