2

When looping with an object, const, let keywords malfunction on Bixby capsule local-endpoint javascript.

I ran Bixby studio on my laptop(Ubuntu 18.04). Trying Bixby simulator, on debug console api result is constructed in an unexpected way.

var http = require('http')
var console = require('console')
var config = require('config')
module.exports.function = function getBTCRates () {
  console.log("GET /ticker without any parameter!)")
  // Read the remote.url value from capsule.properties
  var response = http.getUrl(config.get('blockchain.url') + '/ticker', { format: 'json' });

  var items = [];
  for (var currency in response) {
      var item = response[currency];
      item.quarterBefore = item['15m']
      delete item['15m'];
      item.currency = currency;
      items.push(item)
  }
  return items;
}

If I change var keywords to const or let as follows, it malfunctions.

var http = require('http')
var console = require('console')
var config = require('config')
module.exports.function = function getBTCRates () {
  console.log("GET /ticker without any parameter!)")
  // Read the remote.url value from capsule.properties
  var response = http.getUrl(config.get('blockchain.url') + '/ticker', { format: 'json' });

  const items = [];
  for (let currency in response) {
      const item = response[currency];
      item.quarterBefore = item['15m']
      delete item['15m'];
      item.currency = currency;
      items.push(item)
  }
  return items;
}

When I use const, let keywords, result is as follows:

wrong result

When I use var keywords, result is as follows:

right result

Yubi Lee
  • 76
  • 5
  • 1
    That's an interesting bug. I would've expected it to either throw a syntax error, or behave as `const` / `let` would normally (without problems), but you're getting something different entirely. Looks like however they're using `const`, etc is not standard - if you want to write in ES6 (which is good!), use Babel first. – CertainPerformance Jul 07 '19 at 06:04
  • Hi, welcome to stack overflow. Maybe you can track down the issue when changing only one item. – Jeroen Heier Jul 07 '19 at 06:15

2 Answers2

1

A few suggestions:

  1. Check if it's Ubuntu specific issue since Bixby IDE for Ubuntu is only in Alpha stage. You can test your code on a MAC or PC.
  2. The debug console in IDE offers better details about exceptions. It is possible that JS run into an exception but capsule still try to carry on with whatever default/previous value it can get.
  3. Change only const or let to isolate the issue.
  4. You can submit a diagnostic using IDE's contact support function under help menu.
0

Consult https://mozilla.github.io/rhino/compat/engines.html to see which ES6 features are supported in various versions of Bixby. Currently it seems that let (not const) should mostly work, but requires an undocumented flag and I have no idea how to use it.

janek37
  • 572
  • 5
  • 16