melchor629 / node-flac-bindings

Nodejs bindings to libFLAC
ISC License
17 stars 1 forks source link

Miss check object on ptr #7

Closed 2dxgujun closed 6 years ago

2dxgujun commented 6 years ago
template<typename T>
static T* fromjs(const Local<Value> &m) {
  Nan::HandleScope scope;
  if(!m->IsObject()) { Nan::ThrowError(Nan::Error("Only objects accepted in metadata APIs")); return nullptr; }
  MaybeLocal<Value> ptr = Nan::Get(Nan::To<Object>(m).ToLocalChecked(), Nan::New("_ptr").ToLocalChecked());
  if(ptr.IsEmpty()) { Nan::ThrowError(Nan::Error("This object was not created by the FLAC API")); return nullptr; }
  if(!m->IsObject()) { Nan::ThrowError(Nan::Error("This object was not created by the API or was modified incorrecty")); return nullptr; }
  Local<Value> ptr2 = ptr.ToLocalChecked();
  if(!Buffer::HasInstance(ptr2)) { Nan::ThrowError(Nan::Error("This object was modified incorrectly")); return nullptr; }
  return UnwrapPointer<T>(ptr2);
}

There is a double check of !m->IsObject(), does is should be ptr.IsObject()

melchor629 commented 6 years ago

Mmmm yes. That's incorrect. It should be like you said. I will fix it later.

Thanks :)