https://kotlinlang.org logo
Title
j

jessewilson

02/14/2023, 4:01 PM
I’m getting this crash running
jsTest
and
jsBrowserTest
on our CI environments. I’m still trying to isolate exactly what needs to go wrong to trigger this crash:
Uncaught ReferenceError: jsDeleteProperty is not defined
  at /tmp/_karma_webpack_738366/commons.js:405:5
  ReferenceError: jsDeleteProperty is not defined
      at InternalHashCodeMap.createJsMap [as createJsMap_8hfwp5_k$] (/tmp/_karma_webpack_738366/commons.js:405:5)
      at new InternalHashCodeMap (/tmp/_karma_webpack_738366/commons.js:11762:30)
      at HashMap_init_$Init$_0 (/tmp/_karma_webpack_738366/commons.js:11390:25)
      at HashMap_init_$Init$_1 (/tmp/_karma_webpack_738366/commons.js:11397:5)
      at LinkedHashMap_init_$Init$_1 (/tmp/_karma_webpack_738366/commons.js:12095:5)
      at LinkedHashMap_init_$Init$_2 (/tmp/_karma_webpack_738366/commons.js:12104:5)
      at LinkedHashMap_init_$Create$_2 (/tmp/_karma_webpack_738366/commons.js:12108:12)
      at mapOf (/tmp/_karma_webpack_738366/commons.js:2718:44)
      at init_properties_TestApi_kt_iy7e2c (/tmp/_karma_webpack_738366/commons.js:18131:25)
      at suite (/tmp/_karma_webpack_738366/commons.js:18072:5)
When I interrogate the
common.js
file, I can confirm that the
jsDeleteProperty
is called:
... snip 400 lines
  ...
  setMetadataFor(HashSet, 'HashSet', classMeta, AbstractMutableSet, [AbstractMutableSet, MutableSet], undefined, undefined, []);
  setMetadataFor(InternalHashCodeMap$iterator$1, undefined, classMeta, undefined, [MutableIterator], undefined, undefined, []);
  function createJsMap() {
    var result = Object.create(null);
    result['foo'] = 1;
    jsDeleteProperty(result, 'foo');
    return result;
  }
  setMetadataFor(InternalMap, 'InternalMap', interfaceMeta, undefined, [MutableIterable], undefined, undefined, []);
  setMetadataFor(InternalHashCodeMap, 'InternalHashCodeMap', classMeta, undefined, [InternalMap], undefined, undefined, []);
  ...
  ... another ~100K lines of code
And I can also confirm that the
jsDeleteProperty
function doesn’t exist. I’m first encountering this after upgrading to Kotlin 1.8. I haven’t been able to isolate exactly what triggers this.
My (unverified) guess is that
@InlineOnly
annotation on
jsDeleteProperty()
isn’t honoured when emitting
createMap()
, but it still prevents the function from being emitted as JS source.
@kotlin.internal.InlineOnly
internal inline fun jsDeleteProperty(obj: Any, property: Any) {
    js("delete obj[property]")
}
Well, I’ve been looking at this for most of the day, and I’ve learned that the issue will be fixed in 1.8.20. The beta now reliably inlines the call to this function:
function createJsMap() {
    var result = Object.create(null);
    result['foo'] = 1;
    var tmp$ret$0;
    // Inline function 'kotlin.js.jsDeleteProperty' call
    delete result['foo'];
    tmp$ret$0 = Unit_getInstance();
    return result;
  }