Skip to content

Why does Function.apply(Function, args) does have no access to require()? #2212

@cookiengineer

Description

@cookiengineer

I don't understand the mistake here, so it could be just my dumbness.

If you execute the following code, it raises a ReferenceError (require is not defined).

Why is this the case and how to fix it?

The functionality of deserializing Functions on the fly is somehow required, as it's part of an update and debugging system. I am pretty sure this code / mechanics worked in a previous version of iojs.

I'm using v2.4.0. I could not find the code where it is injected, does anyone have hints where to look at?

bindargs = [ 'foo', 'bar' ];
bindargs.push('var fs = require("fs");');

var cb1 = Function.apply(Function, bindargs);
var cb2 = new Function(bindargs[0], bindargs[1], bindargs[2]);


console.log('Before CB2');
cb2();
console.log('After CB2');


console.log('Before CB1');
cb1();
console.log('After CB1');

Metadata

Metadata

Assignees

No one assigned

    Labels

    moduleIssues and PRs related to the module subsystem.questionIssues that look for answers.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions