-
Notifications
You must be signed in to change notification settings - Fork 923
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
Problem with creating new class type from C code and displaying list of props/functions from it. #315
Comments
GitHub recently upgraded the ubuntu-latest images and I suspect that is the cause of the linux-asan and linux-msan failures. Pin to the old LTS for now. Fixes: quickjs-ng/quickjs#314
The problem looks to come from js_get_length64(ctx, &len, val) in function |
Looks like |
Thank you for your attention. Do you think setting prop_count by hand would
make properties to show up?
czw., 10 paź 2024, 17:14 użytkownik Léo-Paul Géneau <
***@***.***> napisał:
… Looks like (*(*(JSObject *)val.u.ptr)->shape)->prop_count is 0 for
classes defined in C code instead of the expected value 2 in your example
which makes JS_GetOwnPropertyNamesInternal
<https://github.com/bellard/quickjs/blob/6e2e68fd0896957f92eb6c242a2e048c1ef3cae0/quickjs.c#L7519>
return a empty array.
—
Reply to this email directly, view it on GitHub
<#315 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFMMURTRZL4PA7KDUTAGYL3Z22KUZAVCNFSM6AAAAABI2RZYQ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBVGQYDINZZGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I think it is dangerous to set |
Well I do not get where |
Are the properties defined as enunerable? |
@saghul nice catch, indeed the following code:
produces the output:
Therefore it might be by design that properties are not enumerable, a curious choice from my point of view as it is enumerable by default in Javascript. |
how can I define props as enumerable? adding JS_PROP_ENUMERABLE alongside other object properties would be enough? |
This is because of how those properties are defined in that particular sample. Line 1050 in 6e2e68f
When defining it like that it will only be configurable, not enumerable. |
so changing it to JS_PROP_CONFIGURABLE | JS_PROP_ENUMERABLE would solve my problem? |
Yes. In NG we have this:
Which you can copy and paste in your project, which defines a getter / setter and allows you to decide which specific flags you want. |
Why not use |
Because the example is trying to showcase those APIs, in your app you do you :-) |
I get the point of the example, I was just wondering why using |
thank you all, for me this issue can be closed. I think it's sad that there does not exist some wiki for users with "problems" like this :) |
For someone searching for classes with enumerable properties, I think the point example class could with written as:
|
It is probably not trivial to guess that classes created like in the point example do not have enumerable properties (at least it was not for bellard#315). Therefore PointEnumerable class describes how to implement such class.
When i'm creating my own class in C code (like in examples/point.c) and using it in QuickJS why can't i see props and functions from it when i'm running java script code? I mean I can access and use them, but when I'm trying to JSON.stringify that object, or assign it to another object data from class data is not visible (or it's lost in case of assign). For e.g. when I run:
import {Point} from "./examples/point.so";
let point = new Point(5,5);
console.log("point.x = "+point.x);
point.x = 10;
console.log("point.x =" + point.x);
console.log("point stringified = " + JSON.stringify(point, null,2));
let point2 = Object.assign({}, point);
console.log("point2.x = " + point2.x);
result is:
point.x = 5
point.x = 10
point stringified = {}
point2.x = undefined
The text was updated successfully, but these errors were encountered: