-
Notifications
You must be signed in to change notification settings - Fork 914
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
not a constructor #368
Comments
Needs verification, but I fixed it for my scenario. Changing line 18814 of quickjs.c from return JS_ThrowTypeError(ctx, "not a constructor"); to return JS_ThrowTypeError(ctx, "%s is not a constructor", JS_ToCString(ctx, JS_GetPropertyStr(ctx, func_obj, "name"))); Now running const Foo = () => {}; Results in the correct error |
Calling JS code to build the error message is likely not a good idea. In addition you are leaking the C string. |
Excellent observation, but i did say I was looking for clarification on if I was on the correct path. Change:
To:
|
The function name can be extracted without calling ToCString, IMHO that would be a better path. |
JS_GetPropertyStr returns a JSValue which is not directly represent a string in C. So would need converted with JS_ToCString. If you know something I am missing? |
I think using |
Speaks for itself, if calling new when its not a constructor, the error being reported is just
TypeError: not a constructor
For example
var Foo = () => {};
var foo = new Foo(); // TypeError: Foo is not a constructor
However, QuickJS just reports
TypeError: not a constructor
The text was updated successfully, but these errors were encountered: