hyj1991 / v8-profiler-next

node bindings for the v8 profiler
MIT License
219 stars 21 forks source link

Bug: setGenerateType only accepts type = 1 #63

Closed alexgimenez02 closed 1 year ago

alexgimenez02 commented 1 year ago

When attempting to create a "flat" profile, I am presented with the following error:

image

Checking by myself, I noticed the conditional to check if the value is 0 or 1 is wrong.

Current implementation:

 setGenerateType: function (type) {
    const types = [0, 1];
    if (types.indexOf(type) > 0) {
      binding.cpu.setGenerateType(type);
    } else {
      console.error(`type should in [${types.join(', ')}], got ${type}.`);
    }
  }, 

My suggestion:

 setGenerateType: function (type) {
    const types = [0, 1];
    if (types.indexOf(type) > -1) {
      binding.cpu.setGenerateType(type);
    } else {
      console.error(`type should in [${types.join(', ')}], got ${type}.`);
    }
  }, 
hyj1991 commented 1 year ago

landed at: https://github.com/hyj1991/v8-profiler-next/commit/a8ebd969c6c618af370aebfa7a6ada4d7c85e956

hyj1991 commented 1 year ago

Thank you for your feedback :)