Issue: JSObjectGetPrototype Returns the Same JSValueRef for Different Classes

In JavaScriptCore, when creating and manipulating classes and prototypes, the JSObjectGetPrototype function is used to retrieve the prototype of an object.

Problem:
I’ve encountered a situation where JSObjectGetPrototype always returns the same JSValueRef for different classes, even though I am creating distinct prototypes for each class.

  • I create multiple classes, each with its own unique prototype.
  • When I use JSObjectGetPrototype to retrieve the prototype of different instances, I receive the same JSValueRef for all of them, suggesting that the prototype is not unique as expected.

What I Tried:

  1. Creating Unique Prototypes:

    • I used JSObjectMake to create new objects as prototypes for different classes.
    • I then called JSObjectSetPrototype to set these prototypes for the respective constructors.
  2. Retrieving and Logging Prototypes:

    • I used JSObjectGetPrototype to retrieve the prototype for each class instance.
    • I logged the addresses of the prototypes to verify their uniqueness.
  3. Logging and Comparison:

    • I compared the addresses of the prototypes retrieved for different classes to check if they were unique.

What I Expected:

  1. Unique Prototypes:

    • I expected that each class would have its own unique prototype.
    • The addresses retrieved by JSObjectGetPrototype for different classes should be distinct.
  2. Access to Methods:

    • I anticipated that methods added to the prototypes would be accessible when interacting with instances of these classes.

Outcome:

  • Despite setting different prototypes for each class, JSObjectGetPrototype returned the same JSValueRef for all classes.
  • This suggests that the prototypes are not being set or managed correctly, resulting in all classes sharing the same prototype.

Questions:

  1. Is there a known issue or limitation with JSObjectGetPrototype returning the same value for all classes?
  2. How can I ensure that prototypes are correctly assigned and are unique for each class?
  3. Are there any additional steps or considerations to manage prototypes effectively in JavaScriptCore?

Fullcalendar show modal from url

I’m using Fullcalendar and everything is working fine, I have a weekly calendar with events and when I click on an event than a modal shows with more information about this event.

Let say I show this calendar from the url https://test.com/fullcalendar.php

I want to add some extra functions to this so that the modal of the event with ID 123 is showing when I go the to url https://test.com/fullcalendar.php?id=123, thus without clicking on the event in the calendar.

Is this possible?

One user cannot create subscription inside topic in Azure Service Bus (JavaScript)

One user of my aplication that should create subscription in a specific topic is unable to do so (all of the others can). User is getting error with the following content:

<Error>
<Code>400</Code>
<Detail>The specified resource description is invalid.
 TrackingId:1e75e58c-e002-4092-b9e5-2d00c702d785_G12, 
 SystemTracker:*name of my service bus*:Topic:*name of my topic*, 
 Timestamp:2024-08-16T08:05:54
</Detail>
</Error>

The code that is working successfully for everybody else but for this user is the following:

this._sbAdminClient.createSubscription(
                        `myApp-${user}`,
                        azureSubscriptionId,
                        {
                            autoDeleteOnIdle: 'PT1H',
                        }
                    )

Just to be clear, if I check Azure portal, the topic exists and if I manually create subscription, then receiver works fine.

Is there an easy way to transform an object into an array of it’s keys strings?

I want to make an function (or find one that does it for me) that gets an object keys and puts them into an array, like paths for the values, here an example:

const obj = {
    key1: 'a',
    key2: 'b',
    key3: {
        subkey1: 'value',
        subkey2: {
            subsubkey: 'value'
        }
    }
}

console.log(functionThatIWant(obj))

And I get this return:

[ 'key1', 'key2', 'key3.subkey1', 'key3.subkey2.subsubkey' ]

I tried find a funcion like this somewhere and I couldn’t, and I’m trying to make it by my own (It’s not working)

Converting array of harcoded paths into grouped child path data structure [closed]

Input:

const data = [
  'app/index.ts',
  'app/folder1/File1.tsx',
  'app/folder1/File2.tsx',
  'app/data/Data1.ts',
  'app/data/Data2.ts',
  'app/style.ts'
]

Expected output grouping paths:

const output = {
  "app": {
    files: ['index.ts', 'style.ts'],
    folder1: {
      files: ["File1.tsx", "File2.tsx"],
    },
    data: {
      files: ["Data.ts", "Data2.ts"],
    }
  }
}

Function I wrote getting wrong output:

const data = [
  'app/index.ts',
  'app/folder1/File1.tsx',
  'app/folder1/File2.tsx',
  'app/data/Data1.ts',
  'app/data/Data2.ts',
  'app/style.ts'
];

function convertData(data) {
  const output = {};

  data.forEach(path => {
    const pathSegments = path.split('/');
    const [root, ...rest] = pathSegments;

    let currentLevel = output;

    rest.forEach((segment, index) => {
      if (!currentLevel[segment]) {
        currentLevel[segment] = index === rest.length - 1 ? [] : {};
      }
      currentLevel = currentLevel[segment];
    });

    if (Array.isArray(currentLevel)) {
      currentLevel.push(pathSegments[pathSegments.length - 1]);
    } else {
      currentLevel.files = currentLevel.files || [];
      currentLevel.files.push(pathSegments[pathSegments.length - 1]);
    }
  });

  return output;
}

const out = convertData(data);
console.log(out);

HTML: Dropdown of a select field should have the same width

I need a method to give the options (the dropdown) of a native select element the same width as the select field.

So if I give a select field the width 8rem using css (select { width: 8rem}) then I want all elements in my dropdown to be 8rem wide as well. If the text of an option is longer, it should wrap.

Is this somehow possible with a native select? I am not allowed to use/build a custom select field for accessibility reasons. I know select fields are hard to style but maybe there is a good workaround im not aware of.

I can use javascript, css and html.

NextJS error boundaries with server actions

Error boundaries in nextjs appears to be mostly a client-side boundary for returning fallback components (or redirecting) in the event of some failure. But does a similar feature exist for server actions?

I ask because I would like to architect my server actions in such a way that I can write them as throwing exceptions in the event of some error, and centrally catch such errors without necessarily handling all the error conditions inside of each server action endpoint. Somewhat functionally equivalent to how you might architect your conventional backend code with middleware or something similar.

Functionally this is what I am trying to achieve, but I would rather be able to support it without routing all my server actions through a single endpoint:

'use server'

const RPCArray = {
    GET_DATA: (args) => {
        if (!args)
            throw new Error('No good')
        return {}
    },

    PUT_DATA: (args) => {
        if (!args)
            throw new Error('No good')
        return {}
    }
}

export async function doServerRPC(which: string, ...args: any): Promise<any> {
    try {
        return RPCArray[which](args)
    } catch (e: any) {
        return {
            message: e.message || 'An unknown error ocurred'
        }
    }
}

Where client code can do e.g.

const resp = doServerRPC('GET_DATA')

It would be most ideal if the feature were somehow built into the server action infrastructure and I need’nt serialize all my server actions through single endpoint. I was looking at error boundaries to see if error.tsx would apply but I don’t think it does.

Is there another way of doing this without forcing each server action to have a try/catch like I’ve shown in doServerRPC above?

In the event that this is not possible with nextjs, what sort of language features might help facilitate it? Can you, for instance, register exception handlers on a per file/module basis?

Constant is undefined when equal to this.state in React, causing findindex to blow up cannot read properties of undefined

const {activitiesResult} = this.state;  //activitiesResult 

shows as undefined in debug.

    const {authHeader} = this.props;
    const activityIndex = activitiesResult.findIndex((obj) => obj.publicID === data);

This line of code of course blows up I need to use several property in this object later.

Can someone explain why the const is undefined? That the is error in debugging, as that is the error I am getting. How to get around this? I am new to react.

I have tried to put it in an array. I have tried setState, but I am new to react. When I debug I can see the properties in this.state. They are not getting assigned to the constant. It shows as undefined.

Vuejs Asynchronous Components’ Refs are not reactive as props to child components (only happens in production)

I’m using VueJS async components, I’m storing them in refs but it seems like these refs are never created as reactive refs in production.

My app asynchronously loads up certain components where they are needed. I have created a map of the components along with what I would like their ref to be as such:

const componentsMap = {
    header: {
        component: defineAsyncComponent(() => import("./components/header-panel.vue")),
        ref: "header_panel",
    },
    hero: {
        component: defineAsyncComponent(() => import("@/views/Editor/components/hero/hero-panel.vue")),
        ref: "hero_panel",
    },
};

Usage of these async components with the built-in dynamic <component /> is as such:

<component :is="currentComponent" :ref="currentComponent.ref" />

Having previously defined the refs which will store each of the component instances once they are loaded:

const header_panel = ref<any>(null);
const hero_panel = ref<any>(null);

I expect to then be able to access these refs by passing them to a child component:

<ChildComponent :header_panel="header_panel" :hero_panel="hero_panel" />

I then expect to be able to use these two panels in ChildComponent.

It works as expected in development, once the asynchronous components have been loaded, the child component gets the updated prop and it stops being null, then it can be used.

In production, the props of the ChildComponent don’t get updated once an async component has been fetched, I used a watcher to check and it appears it never gets instantiated as a reactive variable.

Is My Use of JavaScript import Statements Correct? [closed]

I’ve read the MDN documentation, but it feels like a lot of information, and as a non-native English speaker, I’m not sure if I’ve understood everything correctly. What I want to do is have a main.js file that imports other JavaScript files, such as lightbox.js, clipboard.js, etc. Is this approach correct?:

main.js:

import "./custom";
import "./lightbox"

The files are in the same folder as the main.js file. I’m using ESBuild, and everything seems to be working, but I’m not sure if I did it correctly. I often see import statements with the from keyword, but in my case, I’ve imported the whole files directly, which is what I actually want. Is this the right approach?

How to customize HTML report file name in Playwright

I’m trying to customize the Playwright’s HTML report file name.

I’ve tried both fileName and outputFile settings but no luck.
I have to mention that when I set outputFolder it changes the folder accordingly.

import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: [
    [
      "html",
      {
        fileName: "test-results.html", // Not working
        outputFile: "myFile.html", // Not working
        outputFolder: "myFolder", // Working
      },
    ],
});

In other reporters such as json or junit these settings works just fine:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: [
    ['json', {  outputFile: 'test-results.json' }] // Working
  ],
});

I couldn’t find anything useful in Playwright Reporters Docs regarding this problem.

Change TableContainer default theming chakra ui

I’m using chakra ui’s TableContainer with the following style:

<TableContainer p="8" m="8" bg="white" border="6px solid" borderRadius="xl" borderColor="white" boxShadow='base'>

I want to add a default theme to it, I have tried the following:

I have this file tableContainer.js:

const TableContainer = {
    baseStyle: {
      p: "8",
      m: "8",
      bg: "white",
      border: "6px solid",
      borderRadius: "2xl",
      borderColor: "white",
      boxShadow: "base",
    },
  }
  
export default TableContainer

In my index.js I have this to set the default usage:

import { extendTheme } from "@chakra-ui/react"
import TableContainer from ".tableContainer"

const overrides = {
    components: {
        TableContainer
    }
}

export default extendTheme(overrides)

My app.js has the following line it it as well:

<ChakraProvider theme={theme}>

Then just calling <TableContainer><TableContainer/>

But my styling is not applying.

Any advice would be greatly appreciated?

How can I execute a function if a user cancels a download in browser during the operation in JavaScript?

I’m using the following JavaScript function to initiate a file download:

function save(object, mime, name) {
  var a = document.createElement('a');
  var url = URL.createObjectURL(object);
  a.href = url;
  a.download = name;
  a.click();
}

This function creates a download link and simulates a click to start the download process. However, I want to run a specific function if the user cancels the download or closes the tab during this operation.

Cancel Button

Is there a way to detect if the download is canceled or interrupted so that I can execute a function or handle the situation appropriately? If not, is there a workaround to achieve this?

I understand that JavaScript in the browser has limited access to the download status after the user initiates it, but any suggestions or workarounds would be greatly appreciated!

Jquery each SVG element

Here is my problem: I use the WordPress image map pro plugin to generate plans with clickable areas in SVG. When the page loads, the HTML code is generated. I want to loop in jquery on the SVG elements generated by the plugin in order to be able to retrieve their data-title that I must use later. But it does not find me any occurrence. On the other hand, if I tell it to loop as soon as I click on an area, it retrieves all the elements. I do not understand. I notice that the plugin’s JS file is loaded at the end. By creating a JS file that loads after the plugin’s, it does not work.

website url : https://preprod.meriadeck.com/liste-boutiques-meriadeck/

code not working :

     jQuery(document).ready(function(){
        jQuery( ".imp-objects" ).each(function() {
            let valueObjectMapSingleProduct = jQuery(this).attr('data-title');
            console.log("toto");
        });
    });

code working :

 jQuery('.liste-boutique-nav li').click(function(){
        jQuery( ".imp-objects" ).each(function() {
            let valueObjectMapSingleProduct = jQuery(this).attr('data-title');
            console.log("toto");
        });

    });

Thanks for your help !

Nico

I tried to load the code in the footer after calling the plugin’s js file.
When trying to use the each loop on SVG elements independent of the plugin, everything works but as soon as it comes to SVG elements generated by the plugin, it doesn’t work. I have the impression that an action (click for example) is needed for it to work.

How to download videos from YouTube using a browser bookmark

I have internet filtering on my computer and the filtering company blocks all video downloads from YouTube and it only leaves the option to watch. The question is whether someone can bring or create a javascript code or another suitable language that I will put in a bookmark in the browser and when I click on the bookmark the video will be reduced to the highest quality or it will be Some options. It is very important that the code does not work through another server, because of course the other servers are blocked. It must be that the code itself downloads the file. Thank you very much.

I tried several times to download the video and could not use software