Skip to content

Literal Object prototype is not working properly inside the plugin's context #62

Description

@aacotroneo

({}).constructor === Object is not working as expected, it should be true, but it's false if the code is run inside the plugin's code. As many libraries rely on that (bad practice) check, they don't fully work (such as aws sdk #56)

This is a local hack, but easy enough to reproduce. It can be tested with any plugin, as we can simply replace 2 lines (in dist if you don't want to rebuild).

this line

const iifeCode = `(function(exports){${newLine}${code}${newLine}}(module.exports));`;

replace by the following 2 lines.

  console.log('This is outside plugin:', new Object().constructor === Object, ({}).constructor === Object)
  const iifeCode = `console.log('This is inside', new Object().constructor === Object, ({}).constructor === Object)`;

The output is

This is outside plugin: true true
This is inside true false

I spent some time trying to customize the context variables with no luck. Maybe someone with more expertise, I have no clue how the constructor of {} is defined in that child context we create.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions