Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property getter executed statically when using configureMembers #60

Closed
kapetan opened this issue Jul 22, 2020 · 1 comment
Closed

Property getter executed statically when using configureMembers #60

kapetan opened this issue Jul 22, 2020 · 1 comment

Comments

@kapetan
Copy link

kapetan commented Jul 22, 2020

Hi,

Property getters seem to be executed as soon as you call configureMembers. This can result in errors as instance state is not initialized yet.

Running the below script with node results in a TypeError, since the private property is initialized in the constructor.

const dbus = require('dbus-next')

const { Interface } = dbus.interface

class TestInterface extends Interface {
   constructor() {
     this._myPrivateProperty = 'HELLO'
   }

   get myProperty() {
     console.log('--> get myProperty')
     return this._myPrivateProperty.toLowerCase()
   }
}

TestInterface.configureMembers({
  properties: {
    myProperty: { signature: 's' }
  }
})

Terminal output:

--> get myProperty
/private/tmp/test-dbus/index.js:12
     return this._myPrivateProperty.toLowerCase()
                                    ^

TypeError: Cannot read property 'toLowerCase' of undefined
    at Interface.get myProperty [as myProperty] (/private/tmp/test-dbus/index.js:12:37)
    at applyDecorator (/private/tmp/test-dbus/node_modules/dbus-next/lib/service/interface.js:314:32)
    at Function.configureMembers (/private/tmp/test-dbus/node_modules/dbus-next/lib/service/interface.js:323:7)
    at Object.<anonymous> (/private/tmp/test-dbus/index.js:16:15)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

The issue seems to originate here:

value: this.prototype[key]

@acrisci
Copy link
Member

acrisci commented Jul 22, 2020

Yeah that does seem like a bug that should be fixed.

@acrisci acrisci closed this as completed in 9c024dd Aug 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants