Skip to content
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

Proxying primitive instances return anonymous toString() return functions #558

Open
chanceaclark opened this issue Aug 24, 2023 · 0 comments

Comments

@chanceaclark
Copy link

Bug Report

Current behavior

Within the edge runtime calling Object.toString() (Function.toString.call(Object) is equivalent, see additional context) returns an anonymous function function () { [native code] }.

You can reproduce this behavior here:

import { runServer, EdgeRuntime } from 'edge-runtime'

const initialCode = `
    console.log('Object:\\n');


    console.log({}.__proto__.constructor.toString());
    console.log(Object.toString());
    console.log(Function.toString.call(Object));

    console.log('\\nArray:\\n');

    console.log([].__proto__.constructor.toString());
    console.log(Array.toString());
    console.log(Function.toString.call(Array));
`

const runtime = new EdgeRuntime({ initialCode });
const server = await runServer({ runtime });

server.close();

Returns:

Object:

function Object() { [native code] }
function () { [native code] }
function () { [native code] }

Array:

function Array() { [native code] }
function () { [native code] }
function () { [native code] }

Expected behavior/code

In both browser and node runtimes, using Function.toString.call(Object) returns function Object() { [native code] }. I have a feeling like it should work in a edge runtime as well 🤔

Possible solution

I nailed it down to this proxy and similarly for jest.setup.ts however, I couldn't figure out a solution for it 😞

Additional context/screenshots

For background context, I found this using the airtable lib, which was using lodash's isPlainObject function, specifically this line: https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L12046 (directly objectCtorString). I've been debating whether that is unreliable to use on lodash's library or something broken by the runtime. I have a feeling like this is something the runtime should fix since it works as expected on node/browser runtimes but let me know otherwise.

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

No branches or pull requests

1 participant