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

[TypeError: _runMicrotasks is not a function] #2181

Closed
cswl opened this issue Jul 15, 2015 · 18 comments
Closed

[TypeError: _runMicrotasks is not a function] #2181

cswl opened this issue Jul 15, 2015 · 18 comments
Labels
v8 engine Issues and PRs related to the V8 dependency.

Comments

@cswl
Copy link

cswl commented Jul 15, 2015

The below code throws the above mentioned error. I tried in iojs 2.3.4 and 3.0nightly. I havent tested on Chrome, but its working as expected on FFox.
I think its some sort of a bug, I dont know much internal details, but I dont see why the below code will throw the above expection.

    var p= new Promise(function(res,rej) {
    res(true);
    });

    p.then(Promise.reject)
    .then(null,function(e){console.log(e);} );
@Fishrock123 Fishrock123 added the v8 engine Issues and PRs related to the V8 dependency. label Jul 15, 2015
@thefourtheye
Copy link
Contributor

Try Promise.reject.bind(Promise)

@thefourtheye
Copy link
Contributor

I knew this error for a while now. I would like to fix it, if we really should, with some guidance. It would be a good opportunity to get to know a little about the C++ land.

@cswl
Copy link
Author

cswl commented Jul 15, 2015

@thefourtheye This indeed seems like an v8 issuse.
Tested on Chrome. Its throwing undefined is not a function.
Both errors are in reject (native) method. I think Chrome is not showing the internal method due to sandboxing. Either way its a bug in v8.

@thefourtheye
Copy link
Contributor

@cswl I would not be very sure about that, because _runMicrotasks is a member in node.js file.

@cswl
Copy link
Author

cswl commented Jul 15, 2015

@thefourtheye Ah, yes..sorry. I had set alias for iojs with --stack-trace-limit=1.
Now its tracing to node.js like you pointed .
I still don't get why Chrome would throw the error though.

@thefourtheye
Copy link
Contributor

@cswl The reject function loses the context when you simply do Promise.reject. That is why Chrome throws this error. But when you do Promise.reject.bind(Promise), you are setting the context of the reject function to Promise.

@cswl
Copy link
Author

cswl commented Jul 15, 2015

@thefourtheye Hmm, I read on MDN that Promise.reject is a static method so I thought the bindings were not necessary and it can be called as standalone function.
That explains why its working on Firefox. Do you happen to know what the spec says?

Cause this works in iojs using bluebird.

p.then(Promise.reject)
    .catch(console.log);  

Comment out bluebird and you get _runMicrotasks is not a function.

@thefourtheye
Copy link
Contributor

Wait. I might be totally wrong here. Let's hear from the experts. Cc @benjamingr @petkaantonov @vkurchatkin

@thefourtheye
Copy link
Contributor

@cswl As per the ECMAScript 6 specification for Promise.reject,

  1. Let C be the this value.
  2. If Type(C) is not Object, throw a TypeError exception.

...

NOTE The reject function expects its this value to be a constructor function that supports the parameter conventions of the Promise constructor.

So, I would say the behavior is correct (throwing a TypeError), as per the specifications, but the error message need not have to include _runMicrotasks.

X posting similar bug nodejs/node-v0.x-archive#25623, but with Promise.all.

@thefourtheye
Copy link
Contributor

Okay, the actual place where this error originates is here,

return new this(function(resolve, reject) { reject(r) });

Here, this is not a valid Promise constructor function. Continuing with the analysis....

Edit 1: Looks like v8 uses %_CallFunction and I have no idea what that is.

@benjamingr
Copy link
Member

Sorry for unavailability, I've talked about this with Domenic in the past, Promise.reject is not a free function, IIRC the reason is so that promise subclasses can "extend it" and a SubPromise.reject rejects with a SubPromise and not a regular Promise.

@benjamingr
Copy link
Member

Anyway, this is not a bug - it's specified behavior.

@thefourtheye
Copy link
Contributor

@benjamingr Correct, it is as per the spec. But the error message should not say _runMicrotasks, right? That is what I am trying to figure out.

@benjamingr
Copy link
Member

Yes, the error message in Chrome is pretty bad too last I checked :)

On Wed, Jul 15, 2015 at 8:36 AM, thefourtheye [email protected]
wrote:

@benjamingr https://github.com/benjamingr Correct, it is as per the
spec. But the error message should not say _runMicrotasks, right? That is
what I am trying to figure out.


Reply to this email directly or view it on GitHub
#2181 (comment).

@vkurchatkin
Copy link
Contributor

I suspect it's a bug in v8.It tries to be smart and show better message than undefined is not a function, but fails inferring the name.

@cswl
Copy link
Author

cswl commented Jul 15, 2015

@thefourtheye @vkurchatkin

I pinpointed the error in https://github.com/nodejs/io.js/blob/master/src/node.js

Have a look at function _tickDomainCallback line 362. The _runMicroTasks() at line 400 seems to be throwing the error.

@cswl
Copy link
Author

cswl commented Jul 16, 2015

Here is the related v8 issue, http://code.google.com/p/v8/issues/detail?id=4243

@vkurchatkin
Copy link
Contributor

Closing this. The behaviour is in line with the spec. Error message is clearly wrong, but it's just a minor issue with v8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

5 participants