HaxeFoundation / HaxeFoundation/haxe

[js] Passing String.charAt takes weird closure

Open
#5,568 1 comment 1 reaction 2 assignees Claimed by @Simn View on GitHub
platform-javascript
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

``` haxe
class Main {
static function main() {
var str = "fdsf";
run(str.charAt);
}

static function run(cb:Int->String) trace(cb(2));
}
```

Generated:

``` js
// Generated by Haxe 3.3.0
(function () { "use strict";
var Main = function() { };
Main.main = function() {
Main.run($bind("fdsf","fdsf".charAt));
};
Main.run = function(cb) {
console.log(cb(2));
};
var $_, $fid = 0;
function $bind(o,m) { if( m == null ) return null; if( m.__id__ == null ) m.__id__ = $fid++; var f; if( o.hx__closures__ == null ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == null ) { f = function(){ return f.method.apply(f.scope, arguments); }; f.scope = o; f.method = m; o.hx__closures__[m.__id__] = f; } return f; }
Main.main();
})();
```

Errors with `TypeError: Cannot assign to read only property 'hx__closures__' of fdsf`. Not a regression and might be broken on other targets too.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.