domenic/promises-unwrapping

`Promise(..)` doesn't seem to be usable as a typical constructor

getify opened this issue · 3 comments

I have node v0.11.13, and just downloaded this repo, did npm install, and tried to define a simple test:

var Promise = require("./lib/testable-implementation.js");

var p = new Promise(function(resolve,reject){
   resolve(42);
});

Then I tried to run that with node --harmony myfile.js, and I get an error:

TypeError: Promise constructor called on an object not initialized as a promise.
    at new Promise (/Users/getify/Desktop/tmp2/reference-implementation/lib/testable-implementation.js:269:15)
    at Object.<anonymous> (/Users/getify/Desktop/tmp2/reference-implementation/myfile.js:3:9)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:349:32)
    at Function.Module._load (module.js:305:12)
    at Function.Module.runMain (module.js:490:10)
    at startup (node.js:124:16)
    at node.js:807:3

I then checked all the included tests (which run fine), and none of them called the constructor.

So then I tried:

var Promise = require("./lib/testable-implementation.js");
var atAtCreate = require("especially/well-known-symbols")["@@create"];

var p = Pr.call( Pr[atAtCreate](), function(resolve,reject){
    resolve(42);
});

And that worked. So, my question is, is that the intention of this implementation?

You need to use OrdinaryConstruct, like the tests do, since new in Node 0.11.23 does not implement ES6 semantics.


From: Kyle Simpsonmailto:notifications@github.com
Sent: ý2014-ý06-ý22 00:39
To: domenic/promises-unwrappingmailto:promises-unwrapping@noreply.github.com
Subject: [promises-unwrapping] Promise(..) doesn't seem to be usable as a typical constructor (#112)

I have node v0.11.13, and just downloaded this repo, did npm install, and tried to define a simple test:

var Promise = require("./lib/testable-implementation.js");

var p = new Promise(function(resolve,reject){
resolve(42);
});

Then I tried to run that with node --harmony myfile.js, and I get an error:

TypeError: Promise constructor called on an object not initialized as a promise.
at new Promise (/Users/getify/Desktop/tmp2/reference-implementation/lib/testable-implementation.js:269:15)
at Object. (/Users/getify/Desktop/tmp2/reference-implementation/myfile.js:3:9)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)
at Function.Module.runMain (module.js:490:10)
at startup (node.js:124:16)
at node.js:807:3

I then checked all the included tests (which run fine), and none of them called the constructor.

So then I tried:

var Promise = require("./lib/testable-implementation.js");
var atAtCreate = require("especially/well-known-symbols")["@@create"];

var p = Pr.call( PratAtCreate, function(resolve,reject){
resolve(42);
});

And that worked. So, my question is, is that the intention of this implementation?


Reply to this email directly or view it on GitHubhttps://github.com//issues/112.

Or use something like es6-shim if all you want is an efficient es5
implementation of es6 promises.

Thanks. That's what I was missing.