Skip to content

Commit

Permalink
set 'this' correctly for Arrow Functions - #1302 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Feb 20, 2018
1 parent 9492f90 commit 8a494b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -41,6 +41,7 @@
Allow STM32LL port to write 32 bits to flash at a time to bring it in line with other ports
Allow flash writes *from* unaligned addresses on nRF52 and ESP8266 (previously this crashed the ESP8266)
Update process.ENV.EXPORTS to bring it in line with what the compiler uses
Now set 'this' correctly for Arrow Functions

1v95 : nRF5x: Swap to UART fifo to avoid overrun errors at high baud rates
Ensure Exceptions/errors are reported on a blank line
Expand Down
3 changes: 3 additions & 0 deletions src/jsparse.c
Expand Up @@ -1449,6 +1449,9 @@ NO_INLINE JsVar *jspeArrowFunction(JsVar *funcVar, JsVar *a) {

bool expressionOnly = lex->tk!='{';
jspeFunctionDefinitionInternal(funcVar, expressionOnly);
if (execInfo.thisVar) {
jsvObjectSetChild(funcVar, JSPARSE_FUNCTION_THIS_NAME, execInfo.thisVar);
}
return funcVar;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/test_arrow_functions_this.js
@@ -0,0 +1,9 @@
var obj = {
value : 42,
a : function() {
return x=>this.value+x;
}
};

var r = obj.a()(8);
result = r === 50;

0 comments on commit 8a494b3

Please sign in to comment.