-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
assert.throws() does not accept an arrow function as the second argument #3275
Comments
May be related to: #3188 |
Important thing to understand here is, arrow functions will not have their Please keep in mind that, |
It is a somewhat unsatisfying dichotomy though, especially since |
True. I am not sure why they chose to compare function f() {}
f.prototype = undefined;
console.log({} instanceof f); Even this throws the same error. |
My reading of the ES6 spec is that, for better or worse, V8's behavior is conforming. SpiderMonkey works the same way, FWIW. I'll file a pull request with a workaround. |
It may be a silly idea, but I am afraid that You wrote:
I think the Here is a demonstration showing how it works: function Person() {}
var person = new Person();
console.log(person.__proto__ === Person.prototype); // true
console.log(person.prototype === undefined); // true
console.log(person.__proto__.__proto__ === Object.prototype); // true
Here is a demonstration showing how they work: console.log(typeof () => {} === "function"); // true
console.log((() => {}) instanceof Function); // true
console.log(typeof (() => {}).__proto__ === "function"); // true
console.log((() => {}).__proto__ === Function.prototype); // true
console.log(typeof Object.getPrototypeOf(() => {}) === "function"); // true
console.log(Object.getPrototypeOf(() => {}) === Function.prototype); // true
console.log(typeof (() => {}).prototype === "undefined"); // true
console.log((() => {}).prototype === undefined); // true
console.log("--------");
console.log(typeof function() {} === "function"); // true
console.log((function() {}) instanceof Function); // true
console.log(typeof (function() {}).__proto__ === "function"); // true
console.log((function() {}).__proto__ === Function.prototype); // true
console.log(typeof Object.getPrototypeOf(function() {}) === "function"); // true
console.log(Object.getPrototypeOf(function() {}) === Function.prototype); // true
console.log(typeof (function() {}).prototype === "object"); // true
console.log((function() {}).prototype === Function.prototype); // false
console.log("--------"); I am using Node.js v4.1.2. I confirmed that using |
Some more ideas: function Person() {}
var person = new Person();
console.log(person instanceof Person); // true
Person.prototype = undefined;
// Still works!
console.log(Object.getPrototypeOf(person).constructor === Person); // true
console.log(person instanceof Person); // exception VS function f() {}
console.log({} instanceof f); // false
f.prototype = undefined;
// Still works!
console.log(Object.getPrototypeOf({}).constructor === f); // false
console.log({} instanceof f); // exception |
`x instanceof f` where f is an arrow function throws a (spec-conforming) "Function has non-object prototype 'undefined' in instanceof check" exception. Add a workaround so that it's possible to pass arrow functions as the second argument to assert.throws(). The try/catch block is a little jarring but swapping around the clauses in the if statements changes the semantics too much. Fixes: nodejs#3275 PR-URL: nodejs#3276 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
`x instanceof f` where f is an arrow function throws a (spec-conforming) "Function has non-object prototype 'undefined' in instanceof check" exception. Add a workaround so that it's possible to pass arrow functions as the second argument to assert.throws(). The try/catch block is a little jarring but swapping around the clauses in the if statements changes the semantics too much. Fixes: #3275 PR-URL: #3276 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Is this issue broken again in Node 8.4.0 (or intentionally changed)? I'm experiencing the exact same issue here when trying to pass an arrow function as the second argument to |
@lumaxis I can not reproduce this. Do you have a test case for me? @asukakenji I updated your original examples to include the missing return statement in arrow functions with braces. |
Code:
Result:
The results are the same no matter which of the following syntax is used:
[BridgeAR: fixed examples by adding missing return statements]
The text was updated successfully, but these errors were encountered: