Git Product home page Git Product logo

Comments (7)

moztcampbell avatar moztcampbell commented on August 25, 2024 2

Searching the ECMAScript spec for uses of OrdinaryObjectCreate(null) I find a few:

  • @@unscopables properties such as [1,2,3][Symbol.unscopables]
  • import.meta in modules
  • The regexp named capture groups described in their issue

So it is very uncommon.

from bob.

schalkneethling avatar schalkneethling commented on August 25, 2024 1

@MEF4232 Thank you for reporting this. @wbamberg Thank you for digging in, that is indeed the problem. As this is a problem with interactive examples/Bob I am moving the issue to the mdn/bob repo

from bob.

karlcow avatar karlcow commented on August 25, 2024 1

Just to remember for later for myself (but if it's interesting to others)

from bob.

wbamberg avatar wbamberg commented on August 25, 2024

This is interesting. The same example works in the browser console, but fails in the interactive example's console, in both Firefox and Chrome.

Firefox: "Error: t.constructor is undefined"
Chrome: "Error: Cannot read property 'name' of undefined"

I think it's very likely that this is due to a bug in the interactive examples code that implements console.log: formatOutput is trying to work out what kind of thing it's trying to log, and if it thinks it's an object, calling formatObject. In particular it is doing:

var objectName = input.constructor.name;

...so it's assuming that if it's being called, then the argument has a constructor property. But in the browser console:

const paragraph = 'The quick brown fox jumps over the lazy dog. It barked.';

const capturingRegex = /(?<animal>fox|cat) jumps over/;
const found = paragraph.match(capturingRegex);

console.log(typeof found.groups); // "object"
console.log(typeof found.groups.constructor) // "undefined"
console.log(typeof found.groups.constructor.name) // "TypeError: found.groups.constructor is undefined"

@schalkneethling , what do you reckon?

from bob.

schalkneethling avatar schalkneethling commented on August 25, 2024

@schalkneethling , what do you reckon?

Will take a look. Thanks for the heads up, @wbamberg

from bob.

schalkneethling avatar schalkneethling commented on August 25, 2024

@wbamberg Ok, so adding this solves the problem:

if (!objectName.constructor || !objectName.prototype) {
    var formattedChild = '';
    var start = true;
    for (var key in input) {
        if (start) {
            start = false;
        } else {
            formattedChild = formattedChild + ', ';
        }
        formattedChild =
            formattedChild + key + ': ' + this.formatOutput(input[key]);
    }
    return 'Object { ' + formattedChild + ' }';
}

What I am really curious about is what type of Object this is that has neither a constructor nor a prototype. According to the docs:

All objects (with the exception of objects created with Object.create(null)) will have a constructor property

Are there other instances of this other than on String.match?

from bob.

schalkneethling avatar schalkneethling commented on August 25, 2024

Thank you for the extremely valuable info @karlcow and @moztcampbell ❤️

from bob.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.