Skip to content

Conversation

@GermanCodeEngineer
Copy link

@GermanCodeEngineer GermanCodeEngineer commented Nov 9, 2025

Resolves

dogeiscutObjectHandler is used to represent items of an object.(jwArrayHandler is the same for arrays) It is used both for conversion toString and to HTML element. This is problematic as the object item e.g. can't know if it needs escape a string or if it can use html elements or not.

Proposed Changes

I tried another solution but it was rightfully rejected: PR 411.

Add arguments to these handlers that specify expected return type and environment context(e.g. for a string, array representation or object representation).

Important

As PM extensions are split between PenguinMod-Vm and PenguinMod-ExtensionsGallery, I had two create two seperate pull requests:
this one and PR

@Ianyourgod
Copy link
Member

i'm against this. in your screenshot, it shows invalid json. i don't think we should have raw html elements in json

@GermanCodeEngineer
Copy link
Author

GermanCodeEngineer commented Nov 9, 2025

the screenshot is from before the change (color + object extension). this stringification can happen under many circumstances.
when not converted to a string:
image
when converted to a string:
image
the problem is the handler can't know wether its put in a string/html. we could just change dogeiscutObject to just use toString or add 2 seperate handlers

@GermanCodeEngineer
Copy link
Author

i'm against this. in your screenshot, it shows invalid json. i don't think we should have raw html elements in json

it alredy allows html(which is useful): https://github.com/PenguinMod/PenguinMod-ExtensionsGallery/blob/main/static/extensions/DogeisCut/dogeiscutObject.js#L181

@DogeisCut
Copy link

It showing html when stringified is actually a bug, not sure when it came it as this used to work properly but- It's supposed to call toJson on the color value when stringified

@jwklong
Copy link
Member

jwklong commented Nov 11, 2025

shouldn't the tostring method just be identical to array
cause pretty sure this would work

toString(pretty = false) {
    return JSON.stringify(this.toJSON(), null, pretty ? "\t" : null)
}

@DogeisCut
Copy link

I cant remember why i overcomplicated it

@DogeisCut
Copy link

and indeed your function works fine, no idea why i had a custom solution

@DogeisCut
Copy link

ykw it might've been a leftover from when i was still trying to make this support recursive objects

@DogeisCut
Copy link

image nvm

@GermanCodeEngineer
Copy link
Author

do we just change how dogeiscutObjectHandler is used? cause then we can just close the PR

@GermanCodeEngineer
Copy link
Author

its important that not all javascript objects inside dogeiscut objects are displayed like a dogeiscut object

@GermanCodeEngineer
Copy link
Author

?

@GermanCodeEngineer
Copy link
Author

image nvm

toString() {
    const stringify = (obj) => {
        if (obj instanceof jwArray.Type) {
            return `[${obj.array.map(item => stringify(item)).join(",")}]`;
        }
        if (isArray(obj)) {
            return `[${obj.map(stringify).join(",")}]`;
        }
        if (obj instanceof dogeiscutObject.Type) {
            return obj.toString();
        }
        if (obj !== null && typeof obj === "object") {
            if (typeof obj.dogeiscutObjectHandler == "function") {
                return obj.dogeiscutObjectHandler()
            }
            if (typeof obj.jwArrayHandler == "function") {
                return obj.jwArrayHandler()
            }
            const entries = Object.entries(obj)
                .map(([key, value]) => `"${key.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}":${stringify(value)}`)
                .join(",");
            return `{${entries}}`;
        }
        if (obj === null || obj === undefined) return "null";
        if (typeof obj === "string") return JSON.stringify(obj);
        if (typeof obj === "number" || typeof obj === "boolean") return obj.toString();
        return "?";
    };

    return stringify(this.object);
}

but the current solution can't be good either as it treats any JS object like a dogeiscutObject

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants