#1144 js: Func.toImmutable not implemented

katox Sat 10 Jul 2010

I found out that this code produces an error in JS (works as expected in JVM env "A nop B f"):

class Main
{
  Void main()
  {
    t := B() { echo("f") }
  }
}

class A
{
  new make(|This| f)
  {
    echo("A")
    f.call(this)
  }
}

class B : A
{
  static const |A| nop := |A| { echo("nop") }
  new make(|This| f) : super(nop)
  {
    echo("B")
    f.call(this)
  }
}

console output:

sys.js: 40 Uncaught sys::NotImmutableErr: |->sys::Void|
sys.js:9464 A
testik.fwt:62 Uncaught TypeError: Cannot call method 'call' of null

andy Tue 13 Jul 2010

Promoted to ticket #1144 and assigned to andy

Good catch - Func.toImmutable needs to be implemented.

andy Tue 13 Jul 2010

Renamed from JS: static closure can't be used in a constructor to js: Func.toImmutable not implemented

andy Mon 3 Jan 2011

Added Func.toImmutable - but actually a deeper issue with Func.isImmutable I still need to sort out.

SlimerDude Tue 18 Aug 2015

I bumped into this today, so thought I'd share a simple failing test case:

@Js
class TestJsImmutable : Test {
    Void testCase() {
        func := |->Obj?| { 42 }.toImmutable
    }
}
C:\> fant -js foo::TestJsImmutable

-- Run: foo::TestJsImmutable.testCase...
sys::NotImmutableErr: Func

Time: 32ms

Failed:
  foo::TestJsImmutable.testCase

***
*** 1  FAILURES [1 tests, 0 methods, 0 verifies]
***

Is there a current workaround?

Login or Signup to reply.