New issue
Advanced search Search tips

Issue 709334 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner:
Closed: Apr 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

V8 Cannot deduce direct function .bind() without LVALUE.

Project Member Reported by hua...@chromium.org, Apr 7 2017

Issue description

Chrome Version: 59.0.3064.0 (Official Build) canary (64-bit) (cohort: 64-Bit)
OS: Win 8.1

What steps will reproduce the problem?
(1) Run the following JavaScript (in Dev Console, or load attached):

  function(t){console.log(t);}.bind(null,3)();

What is the expected result? Console outputs "3".

What happens instead? The following error:
Uncaught SyntaxError: Unexpected token (

Please use labels and text to provide additional information.

If we try the following:
(A) Assign an LVALUE:
  result = function(t){console.log(t);}.bind(null,3)();

(B) Put () around function:
  (function(t){console.log(t);}).bind(null,3)();

(C) Put () around bind function
  (function(t){console.log(t);}.bind)(null,3)();

Then this correctly prints 3 and evaluates undefined.

Since (A) is commonly used, it's rather surprising that without an LVALUE the parser fails.
 
test.html
191 bytes View Download
This also fails in FireFox, so maybe it's some ECMAScript oddity that's working as intended??
Components: -Blink>JavaScript>Compiler Blink>JavaScript>Language
Owner: adamk@chromium.org
Status: Assigned (was: Untriaged)
Adam, can you please provide clarity?

Comment 3 by adamk@chromium.org, Apr 12 2017

Status: WontFix (was: Assigned)
Indeed, this is working as intended. The issue is that in cases A-C, the function is in an expression context. Whereas in the first case, it's in the context of a statement, and fails to parse as it's an invalid function declaration (it lacks a name).

Sign in to add a comment