ECMAScript icon indicating copy to clipboard operation
ECMAScript copied to clipboard

Unable to rebind ECMAScript instance from godot object in threaded worker.js

Open dangerousbeans opened this issue 2 years ago • 3 comments

My main thread is sending out a ECMAscript class as a message to a worker thread using godot.abandon_value & godot.adopt_value, but I only get the godot object and cannot call any of the js methods on the class:

// parcel.tsx
export default class Parcel extends godot.Spatial {
  test_function(){
    console.log("stuff I wana run here"))
  }
}

// worker.js
onmessage = function(e) {
  let parcel = godot.adopt_value(e.parcel)
  console.log(parcel)                                 // [Spatial:2362]
  console.log(parcel.test_function())         // undefined
  console.log(parcel.call("test_function")) // error
}

// grid.tsx
export default class Grid  extends godot.Spatial {
  featureLoadThread

  _ready(){
    let p = new Parcel()

    this.featureLoadThread = new Worker('res://src/worker.js')
    this.featureLoadThread.onmessage = this._onmessage.bind(this);
    this.featureLoadThread.postMessage({ type:"featureLoad", parcel: godot.abandon_value(p) })
  }
}

dangerousbeans avatar Aug 15 '21 01:08 dangerousbeans

Here's an example of the situation applied to the demos project; https://github.com/dangerousbeans/ECMAScriptDemos/commit/6959fbf385fd074037e3c23d0a21ddb06aac1502

dangerousbeans avatar Aug 15 '21 02:08 dangerousbeans

You can only pass primitive values between workers. It is the standard and limit of the JavaScript language, this why the adopt_value exists.

Joran Kikke @.***>于2021年8月15日 周日10:00写道:

Here's an example of the situation applied to the demos project; @.*** https://github.com/dangerousbeans/ECMAScriptDemos/commit/6959fbf385fd074037e3c23d0a21ddb06aac1502

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GodotExplorer/ECMAScript/issues/108#issuecomment-898983282, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVEKTFPXZAYKK34XKJAYQTT44NSVANCNFSM5CFURLUA .

Geequlim avatar Aug 15 '21 10:08 Geequlim

@Geequlim I can get the godot object fine, but the one returned from godot.adopt_value no longer has any ECMAscript bindings or js context

dangerousbeans avatar Aug 15 '21 20:08 dangerousbeans